Algorithms Flashcards

1
Q

What is the time complexity of binary search?

A

O(log n) for a sorted array, as it halves the search space in each step.

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

What is the difference between DFS and BFS?

A

Depth-First Search (DFS) explores as far as possible along a branch (uses stack/recursion). Breadth-First Search (BFS) explores level by level (uses queue). DFS: O(V+E), BFS: O(V+E).

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

What is quicksort, and what is its average time complexity?

A

Quicksort partitions an array around a pivot, recursively sorting subarrays. Average: O(n log n), worst: O(n²) with poor pivot choice.

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

What is dynamic programming?

A

A method to solve problems by breaking them into overlapping subproblems, storing results (memoization or tabulation) to avoid recomputation.

Example: Fibonacci in O(n).

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

What is the time complexity of accessing an element in an array vs. a linked list?

A

Array: O(1) via index. Linked list: O(n) due to traversal.

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