FINAL EXAM BIG O CRAM

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/86

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

87 Terms

1
New cards

ArrayList add at first, add at last, add at any index

O(n) for add at first (must shift all elements right)
O(1)* for add at last (amortized append)
O(n) for add at any index (shift subsequent elements right)

2
New cards

ArrayList remove at first, remove at last, remove at any index

O(n) for remove at first (shift all elements left)
O(1) for remove at last (decrement size)
O(n) for remove at any index (shift subsequent elements left)

3
New cards

ArrayList search at index, search for specific value

O(1) for search at index (direct access)
O(n) for search for specific value (scan until found)

4
New cards

ArrayList resize

O(n) for resize (allocate new array and copy all elements)

5
New cards

SLL (no tail) add at first, add at last, add at any index

O(1) for add at first (update head)
O(n) for add at last (traverse to end)
O(n) for add at any index (traverse to position)

6
New cards

SLL (no tail) remove at first, remove at last, remove at any index

O(1) for remove at first (update head)
O(n) for remove at last (traverse to node before last)
O(n) for remove at any index (traverse to predecessor)

7
New cards

SLL (no tail) search at index, search for specific value

O(n) for search at index (must traverse node by node)
O(n) for search for specific value (must traverse node by node)

8
New cards

SLL (with tail) add at first, add at last, add at any index

O(1) for add at first (update head)
O(1) for add at last (update tail)
O(n) for add at any index (traverse)

9
New cards

SLL (with tail) remove at first, remove at last, remove at any index

O(1) for remove at first (update head)
O(n) for remove at last (traverse to predecessor)
O(n) for remove at any index (traverse to predecessor)

10
New cards

SLL (with tail) search at index, search for specific value

O(n) for search at index (must traverse node by node)
O(n) for search for specific value (must traverse node by node)

11
New cards

CSLL add at first, add at last, add at any index

O(1) for add at first (insert after tail)
O(1) for add at last (insert after tail and update tail)
O(n) for add at any index (traverse)

12
New cards

CSLL remove at first, remove at last, remove at any index

O(1) for remove at first (update tail.next)
O(n) for remove at last (traverse to predecessor)
O(n) for remove at any index (traverse to predecessor)

13
New cards

CSLL search at index, search for specific value

O(n) for search at index (must traverse node by node)
O(n) for search for specific value (must traverse node by node)

14
New cards

DLL (with tail) add at first, add at last, add at any index

O(1) for add at first (link before head)
O(1) for add at last (link after tail)
O(n) for add at any index (traverse)

15
New cards

DLL (with tail) remove at first, remove at last, remove at any index

O(1) for remove at first (unlink head)
O(1) for remove at last (unlink tail)
O(n) for remove at any index (traverse)

16
New cards

DLL (with tail) search at index, search for specific value

O(n) for search at index (must traverse)
O(n) for search for specific value (must traverse)

17
New cards

Stack (array-backed) add at last

O(1)* for push (amortized append)

18
New cards

Stack (array-backed) remove at last

O(1) for pop

19
New cards

Stack (array-backed) resize

O(n) when resizing on push

20
New cards

Queue (array-backed) add at last

O(1)* for enqueue (amortized in circular buffer)

21
New cards

Queue (array-backed) remove at first

O(1) for dequeue

22
New cards

Queue (array-backed) resize

O(n) when resizing

23
New cards

Deque (array-backed) add at first, add at last

O(1)* for add at first (amortized in circular buffer)
O(1)* for add at last (amortized in circular buffer)

24
New cards

Deque (array-backed) remove at first, remove at last

O(1) for remove at first
O(1) for remove at last

25
New cards

Deque (array-backed) resize

O(n) when resizing

26
New cards

BST add

O(log n) for add (traverse from root to insertion point)
O(n) for add in worst case (tree degenerates into a chain)

27
New cards

BST search

O(log n) for search (compare and traverse down the tree)
O(n) for search in worst case (unbalanced tree)

28
New cards

BST remove

O(log n) for remove (locate node, replace, and restructure)
O(n) for remove in worst case (degenerate tree)

29
New cards

Heap add

O(log n) for add (insert at end and bubble up)

30
New cards

Heap remove

O(log n) for remove (remove root, replace with last element, and bubble down)

31
New cards

HashMap with external chaining add

O(1) for add in average case (compute bucket and insert at head)
O(n) for add in worst case (all keys collide into one bucket)

32
New cards

HashMap with external chaining search

O(1) for search in average case (compute bucket and traverse short list)
O(n) for search in worst case (long collision list)

33
New cards

HashMap with external chaining remove

O(1) for remove in average case (compute bucket and unlink node)
O(n) for remove in worst case (long collision list)

34
New cards

HashMap with probing add

O(1) for add in average case (probe sequence to find empty slot)
O(n²) for add in worst case (table nearly full or long probe * n bad inserts)

35
New cards

HashMap with probing search

O(1) for search in average case (probe until match or empty)
O(n) for search in worst case (long probe sequence)

36
New cards

HashMap with probing remove

O(1) for remove in average case (probe to find and mark slot)
O(n) for remove in worst case (long probe sequence)

37
New cards

AVL add

O(log n) for add (BST insert + at most one or two rotations)

38
New cards

AVL search

O(log n) for search (balanced-tree traversal)

39
New cards

AVL remove

O(log n) for remove (BST delete + rotations to rebalance)

40
New cards

SkipList add

O(log n) for add in average case (random-level pointers)
O(n) for add in worst case (all nodes at level 1)

41
New cards

SkipList search

O(log n) for search in average case (multi-level traversal)
O(n) for search in worst case (degenerated levels)

42
New cards

SkipList remove

O(log n) for remove in average case (traverse levels and unlink)
O(n) for remove in worst case (degenerated levels)

43
New cards

2-4 Tree add

O(log n) for add (find leaf, insert, split nodes as needed)

44
New cards

2-4 Tree search

O(log n) for search (descend through 2–4 node keys)

45
New cards

2-4 Tree remove

O(log n) for remove (delete and rebalance via merge or redistribution)

46
New cards

Bubble sort best-case

O(n) when the list is already sorted (one pass, no swaps)

47
New cards

Bubble sort worst-case

O(n²) when the list is in reverse order (every pass swaps at every comparison)

48
New cards

Bubble sort stable/in-place/adaptive

Stable? Yes (preserves order of equal elements)
In-place? Yes (only needs constant extra space)
Adaptive? Yes (stops early if no swaps occur)

49
New cards

Insertion sort best-case

O(n) when the list is already sorted (each new element inserted with one comparison)

50
New cards

Insertion sort worst-case

O(n²) when the list is in reverse order (each insert shifts all prior elements)

51
New cards

Insertion sort stable/in-place/adaptive

Stable? Yes (preserves order of equal elements)
In-place? Yes (only needs constant extra space)
Adaptive? Yes (runs faster when input is partially sorted)

52
New cards

Selection sort best-case

O(n²) even when the list is sorted (always scans remaining elements to find min)

53
New cards

Selection sort worst-case

O(n²) when the list is in reverse or random order (same behavior as best)

54
New cards

Selection sort stable/in-place/adaptive

Stable? No (swapping may change order of equal elements)
In-place? Yes (only needs constant extra space)
Adaptive? No (performs same work regardless of initial order)

55
New cards

Cocktail shaker sort best-case

O(n) when the list is already sorted (one forward and backward pass, no swaps)

56
New cards

Cocktail shaker sort worst-case

O(n²) when the list is in reverse order (each pass moves one element)

57
New cards

Cocktail shaker sort stable/in-place/adaptive

Stable? Yes (like bubble sort, preserves equal-element order)
In-place? Yes (only needs constant extra space)
Adaptive? Yes (stops early if no swaps occur)

58
New cards

Merge sort best-case

O(n log n) for all inputs (always divides and merges)

59
New cards

Merge sort worst-case

O(n log n) for all inputs (same as best)

60
New cards

Merge sort stable/in-place/adaptive

Stable? Yes (merging preserves order of equal elements)
In-place? No (requires O(n) extra space for merging)
Adaptive? No (always performs full merge passes)

61
New cards

Quick sort best-case

O(n log n) with good pivot choices (balanced partitions)

62
New cards

Quick sort worst-case

O(n²) with poor pivot choices (highly unbalanced partitions)

63
New cards

Quick sort stable/in-place/adaptive

Stable? No (swapping may reorder equal elements)
In-place? Yes (partitioning uses constant extra space)
Adaptive? No (performance independent of initial order)

64
New cards

LSD radix sort best-case

O(n k) where n is number of elements and k is number of digit positions

65
New cards

LSD radix sort worst-case

O(n k) (same as best, processes all digits)

66
New cards

LSD radix sort stable/in-place/adaptive

Stable? Yes (uses stable sort per digit)
In-place? Yes (reuses small auxiliary structures)
Adaptive? No (always processes k digit passes)

67
New cards

Heap sort best-case

O(n log n) for all inputs (heapify and successive removals)

68
New cards

Heap sort worst-case

O(n log n) for all inputs (same as best)

69
New cards

Heap sort stable/in-place/adaptive

Stable? No (heap operations can reorder equal elements)
In-place? Yes (uses the array for the heap without extra space)
Adaptive? No (does the same work regardless of order)

70
New cards

Brute Force best cases

Best-case single occurrence: O(m) (pattern matches at first alignment)
Best-case all occurrences: O(n-m)* (first-character mismatches at every shift)

71
New cards

Brute Force worst cases

Worst-case single occurrence: O(nm) (each shift compares all m characters)
Worst-case all occurrences: O(nm) (worst-case overlaps at every alignment)

72
New cards

Boyer-Moore (no Galil Rule) best cases

Best-case single occurrence: O(m) (shifts by m on each mismatch)
Best-case all occurrences: O(n/m + m) (few comparisons per alignment)

73
New cards

Boyer-Moore (no Galil Rule) worst cases

Worst-case single occurrence: O(nm + m) (adversarial text/pattern)
Worst-case all occurrences: O(nm + m) (repeated worst-case alignments)

74
New cards

Boyer-Moore with Galil Rule best cases

Best-case single occurrence: O(m) (large shifts via bad-character heuristic)
Best-case all occurrences: O(n/m + m) (efficient skipping across all matches)

75
New cards

Boyer-Moore with Galil Rule worst cases

Worst-case single occurrence: O(nm + m) (bad-character-only worst case)
Worst-case all occurrences: O(nm + m) (no good-suffix, many overlaps)

76
New cards

KMP best cases

Best-case single occurrence: O(m) (prefix table avoids backtracking)
Best-case all occurrences: O(n + m) (single linear scan finds all)

77
New cards

KMP worst cases

Worst-case single occurrence: O(n + m) (guaranteed linear time)
Worst-case all occurrences: O(n + m) (still linear overall)

78
New cards

Rabin-Karp best cases

Best-case single occurrence: O(m) (constant-time hashes, no collisions)
Best-case all occurrences: O(n + m) (one pass with direct hash checks)

79
New cards

Rabin-Karp worst cases

Worst-case single occurrence: O(nm + m) (many hash collisions force rechecks)
Worst-case all occurrences: O(nm + m) (repeated collision-induced rechecks)

80
New cards

Adjacency Matrix (space complexity)

O(V^2) for best-worst

81
New cards

Adjacency List (space complexity)

O(V²) worst case; O(V + E) average

82
New cards

Edge List (space complexity)

O(E) for best-worst

83
New cards

Depth First Search (time complexity)

O(V + E), where V is the queue of vertices. Inefficient queues might increase V.

84
New cards

Breadth First Search (time complexity)

O(V + E), where V is the queue of vertices. Inefficient queues might increase V.

85
New cards

Dijkstra’s Algo (time complexity)

O(E log E)

86
New cards

Prim’s Algo (time complexity)

O(E log E)

87
New cards

Kruskal’s Algo (time complexity)

O(E log E)