Structured Algorithms Flashcards

(12 cards)

1
Q

Explain

‘Big O’ complexity chart

A

A graph that shows the efficiency of algorithms by plotting the number of operations required to sort a given number of elements in the worst-case scenario (i.e. the target number is the last number to be found)

it shows how performance scales with input size

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

Explain

‘Big O’ notation

(time complexity)

A

A measure of how fast an algorithm runs based on the size of its input.

O(n) means algorithm speed grows at the same rate as its input size.

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

Recall

The two search algorithms.

LB

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

Explain

What occurs in the linear search algorithm?

A

An array is iterated through in index order until the target is found.

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

Explain

What occurs in the binary search algorithm?

halves sort

A
  • If middle number > target number, reiterate for the lower half of the array (excluding the middle number)
  • If middle number < target number, reiterate for the higher half of the array (excluding the middle number)

repeats and halves search area until target is found

note that binary search requires the array to be sorted.

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

Recall

The three sort algorithms.

BIS

A
  • Bubble Sort
  • Insertion Sort
  • Selection Sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain

What occurs in the bubble sort algorithm?

A
  • i and i + 1 of an array are iterated over.
  • if array[i] > array [i+1], swap them around.

Repeats in passes over the whole array until everything is swapped correctly.

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

Explain

What occurs in the insertion sort algorithm?

A

no clue bro

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

Explain

What occurs in the selection sort algorithm?

A
  • Iterates and finds the maximum value of the list, and moves it to the end of the list, working backwards.

Repeats in passes over the whole array until everything is swapped correctly.

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

Recall

All sorting algorithms (that we’re required to know) have a time complexity of?

A

O(n²)

(this is not good, and gets geometrically slower as #elements increases)

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

Recall

What is the time complexity of the binary search algorithm?

A

O[log(n)]

(this is very good, but it requires the data to be sorted first.)

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

Recall

What is the time complexity of the linear search algorithm?

A

O(n) ☹️

this is okay but not ideal and gets slower with larger databases

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