Big-O Flashcards

1
Q

What is the time complexity of accessing an element in an array?

A

O(1)

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

What is the time complexity of searching in an unsorted array?

A

O(n)

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

What is the time complexity of inserting at the end of an array (amortized)?

A

O(1)

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

What is the time complexity of inserting at the beginning of an array?

A

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 deleting an element from the middle of an array?

A

O(n)

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

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

A

O(n)

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

What is the time complexity of inserting at the head of a linked list?

A

O(1)

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

What is the time complexity of inserting at the tail of a singly linked list (without tail pointer)?

A

O(n)

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

What is the time complexity of deleting from the head of a linked list?

A

O(1)

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

What is the time complexity of searching in a linked list?

A

O(n)

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

What is the average time complexity of searching in a hash table?

A

O(1)

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

What is the worst-case time complexity of searching in a hash table?

A

O(n)

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

What is the average time complexity of inserting into a hash table?

A

O(1)

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

What is the worst-case time complexity of inserting into a hash table?

A

O(n)

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

What is the time complexity of searching in a binary search tree (average case)?

A

O(log n)

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

What is the time complexity of searching in a binary search tree (worst case)?

A

O(n)

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

What is the time complexity of searching in a balanced binary search tree?

A

O(log n)

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

What is the time complexity of inserting into a balanced binary search tree?

A

O(log n)

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

What is the time complexity of deleting from a balanced binary search tree?

A

O(log n)

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

What is the time complexity of heap insert (binary heap)?

A

O(log n)

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

What is the time complexity of heap delete (binary heap)?

A

O(log n)

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

What is the time complexity of heapify an entire array (building a heap)?

A

O(n)

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

What is the time complexity of searching in a heap?

24
Q

What is the time complexity of quicksort (average case)?

A

O(n log n)

25
What is the time complexity of quicksort (worst case)?
O(n²)
26
What is the space complexity of quicksort (in-place)?
O(log n)
27
What is the time complexity of mergesort?
O(n log n)
28
What is the space complexity of mergesort?
O(n)
29
What is the time complexity of bubble sort (worst and average case)?
O(n²)
30
What is the time complexity of insertion sort (best case)?
O(n)
31
What is the time complexity of insertion sort (average and worst case)?
O(n²)
32
What is the time complexity of selection sort?
O(n²)
33
What is the time complexity of binary search?
O(log n)
34
What is the space complexity of binary search (recursive)?
O(log n)
35
What is the space complexity of binary search (iterative)?
O(1)
36
What is the time complexity of Breadth-First Search (BFS)?
O(V + E)
37
What is the space complexity of BFS using a queue?
O(n)
38
What is the time complexity of Depth-First Search (DFS)?
O(V + E)
39
What is the space complexity of DFS using recursion?
O(h), where h is the height of the tree/graph
40
What is the time complexity of Dijkstra’s algorithm (with min-heap)?
O((V + E) log V)
41
What is the space complexity of Dijkstra’s algorithm?
O(V)
42
What is the time complexity of Floyd-Warshall algorithm?
O(V³)
43
What is the time complexity of Kruskal's algorithm (with union-find)?
O(E log E)
44
What is the time complexity of Prim's algorithm (with min-heap)?
O((V + E) log V)
45
What is the time complexity of Topological Sort (DFS based)?
O(V + E)
46
What is the space complexity of storing a graph with an adjacency list?
O(V + E)
47
What is the space complexity of storing a graph with an adjacency matrix?
O(V²)
48
What is the space complexity of dynamic programming with memoization (top-down)?
O(n)
49
What is the space complexity of dynamic programming with tabulation (bottom-up)?
O(n)
50
What is the space complexity of an iterative algorithm with no data structures?
O(1)
51
What is the space complexity of a recursive algorithm with depth n?
O(n)
52
What is the rule of thumb for nested loops over input size n?
O(n²) or worse
53
What is the rule of thumb for algorithms that divide the problem in half each time?
O(log n)
54
What is the rule of thumb for traversing all elements once?
O(n)
55
What is the rule of thumb for brute-force combinations or subsets?
O(2ⁿ)
56
What is the rule of thumb for comparing each pair in a set of n elements?
O(n²)