2.3 Algorithms Flashcards

(19 cards)

1
Q

Big O notation purpose

A

Describes upper bound of time/space complexity relative to input size.

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

O(1) complexity

A

Constant time (e.g., array index lookup).

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

O(log n) complexity

A

Logarithmic (e.g., binary search).

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

O(n) complexity

A

Linear (e.g., linear search).

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

O(n log n) complexity

A

Log-linear (e.g., merge sort, quick sort average).

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

O(n²) complexity

A

Quadratic (e.g., bubble sort, nested loops).

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

O(2ⁿ) complexity

A

Exponential (e.g., recursive Fibonacci).

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

Space complexity

A

Measures amount of memory an algorithm uses relative to input size.

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

Depth-first search (DFS)

A

Explores as far as possible down a branch before backtracking. Uses stack (or recursion).

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

Breadth-first search (BFS)

A

Explores all neighbours at current depth before moving deeper. Uses queue.

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

Dijkstra’s algorithm use

A

Finds shortest path from source to all nodes in weighted graph (non-negative weights).

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

A* algorithm difference to Dijkstra

A

Uses heuristics to estimate distance to target; more efficient.

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

A* requirement

A

Requires a heuristic function (e.g., Manhattan distance, Euclidean distance).

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

Bubble sort complexity

A

O(n²) worst case; simple but inefficient.

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

Insertion sort complexity

A

O(n²) worst case; efficient for small or nearly sorted datasets.

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

Merge sort complexity

A

O(n log n); stable; divide and conquer; requires additional memory.

17
Q

Quick sort complexity

A

O(n log n) average; O(n²) worst; in-place variant exists.

18
Q

Binary search requirement

A

Data must be sorted; O(log n).

19
Q

Linear search complexity

A

O(n); works on unsorted data.