Structured Algorithms Flashcards

(12 cards)

1
Q

Define

‘Big O’ notation

A

A notation that measures the efficiency of algorithms by notating the relationship between the number of operations (O) and number of elements in a set (n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List

Types of search algorithms

A
  • Linear Search
  • Binary Search
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Recall

The time complexity of a linear search.

A

O(n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Recall

Steps of a Linear Search

A

Iterate over a set at a linear rate until the target is found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Recall

The time complexity of a binary search.

A

O[log(n)].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Recall

Steps of a binary search

A
  • Compare the middle element of the set to the target.
  • If it’s greater than the target, repeat iteration on the lower half of the array, and vice versa if it’s less than the target.
  • Repeat until found.

(The set MUST BE SORTED.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List

Types of Sorting Algorithms

A
  • Bubble Sort
  • Insertion Sort
  • Selection Sort

(BIS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Recall

The time complexity for every sorting algorithm covered.

A

O(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which sorting algorithm has a time complexity of O[n * log(n)]?

(Extension)

A

quicksort.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

List

The steps of a bubble sort.

A
  • Iterate through an array (arr)), comparing each value (arr[i]) by its succeeding value (arr[i+1]) and swapping them if arr[i] > arr[i+1].
  • Repeat this until no swaps are done, indicating completion.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List

The steps of a selection sort.

A

Instantiate a ‘sorted’ and ‘unsorted’ set, storing the ‘unsorted’ data in the ‘unsorted’ set, and leaving the ‘sorted’ array empty.

  • Iterate over the ‘unsorted’ set, popping the smallest number, and adding it to the ‘sorted’ set.

(‘pop’ — fetch value and then remove from set)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

List

The steps of an insertion sort.

A

Instantiate a ‘sorted’ and ‘unsorted’ set, storing the ‘unsorted’ data in the ‘unsorted’ set, and leaving the ‘sorted’ array empty.

  • Iterate over ‘unsorted’ set linearly, popping its value, and adding it to the ‘sorted’ array.
  • In the ‘sorted’ set, the value’s index is shifted down until it finds a number less than it.
  • Repeat until ‘unsorted’ is empty.

(like a selection sort-bubble sort hybrid)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly