Algorithm Runtime

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:45 PM on 10/3/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

30 Terms

1
New cards

Insertion sort

Best: Θ(n) (already sorted; inner loop breaks after one comparison). Average: Θ(n^2). Worst: Θ(n^2) (reverse-sorted: n(n-1)/2 comparisons and swaps). Extra space: O(1) (in-place).

2
New cards

Merge sort

Best: Θ(n log n). Average: Θ(n log n). Worst: Θ(n log n) (T(n) = 2T(n/2) + cn). Extra space: O(n) (Merge copies halves into L[] and R[]); not in-place.

3
New cards

Merge step (Merge procedure of merge sort)

Best: Θ(n). Average: Θ(n). Worst: Θ(n) (exactly one comparison per element moved). Extra space: O(n) (the L[] and R[] copies).

4
New cards

Heap sort

Best: O(n log n) (Θ(n log n) for distinct keys; linear only if all keys are equal). Average: Θ(n log n). Worst: O(n log n) (BuildHeap O(n) + n Delete-Max calls at O(log n)). Extra space: O(1) (in-place).

5
New cards

Counting sort

Best: Θ(n + k). Average: Θ(n + k). Worst: Θ(n + k) (same for every input; integers in 0..k). Extra space: O(n + k) (count array C[0..k] plus output array of size n). Stable.

6
New cards

Radix sort

Best: Θ(d(n + r)). Average: Θ(d(n + r)). Worst: Θ(d(n + r)) (d counting-sort passes; O(n) if d and r are constants). Extra space: O(n + r) (counting array of size O(r) plus output array of size n). Stable.

7
New cards

Bucket sort

Best: Θ(n) (items spread evenly across buckets). Average: Θ(n) expected (uniformly distributed input, n equal-size buckets). Worst: O(n^2) (all items in one bucket, sorted by insertion sort). Extra space: O(n) (buckets holding the n items).

8
New cards

Find minimum or maximum (linear scan)

Best: Θ(n). Average: Θ(n). Worst: Θ(n) (exactly n - 1 comparisons, which is optimal). Extra space: O(1).

9
New cards

Partition step (Randomized-Select / Quicksort style)

Best: Θ(n). Average: Θ(n). Worst: Θ(n) (examines each element once against the pivot). Extra space: O(1) if done in place.

10
New cards

Randomized-Select (kth smallest)

Best: Θ(n) (the pivot has rank k; one partition still costs Θ(n)). Average (expected): Θ(n). Worst: Θ(n^2) (always picking the max as pivot: T(n) = T(n-1) + cn). Extra space: O(1) extra besides the recursion stack (about O(log n) expected depth).

11
New cards

Select (median-of-medians, kth smallest in worst-case linear time)

Best: Θ(n). Average: Θ(n). Worst: Θ(n) (T(n) = T(n/5) + T(3n/4) + Θ(n)). Extra space: O(n) (array of group medians) plus the recursion stack.

12
New cards

Find max in a max-heap

Best: O(1). Average: O(1). Worst: O(1) (the max is at A[1]). Extra space: O(1).

13
New cards

Bubble-up(A, i)

Best: O(1) (element is not larger than its parent; no swap). Average: O(1) expected for random keys. Worst: O(log n) (swaps all the way to the root). Extra space: O(1).

14
New cards

Insert into a heap

Best: O(1). Average: O(1) expected for random keys. Worst: O(log n) (insert as a leaf, then Bubble-up). Extra space: O(1).

15
New cards

Bubble-down(A, i)

Best: O(1) (no swap needed). Average: O(log n) (for a node near the root of a random heap). Worst: O(log n), more precisely O(h) for a node of height h. Extra space: O(1).

16
New cards

Delete-Max (heap)

Best: O(1) (no swap needed during Bubble-down, e.g., all keys equal). Average: Θ(log n). Worst: O(log n) (swap A[1] with last element, then Bubble-down from the root). Extra space: O(1).

17
New cards

BuildHeap, iterative method (repeated Bubble-up)

Best: O(n) (input already in heap order; no swaps). Average: O(n) for random input. Worst: O(n log n) (each of n insertions bubbles up O(log n)). Extra space: O(1) (in-place).

18
New cards

BottomBuildHeap (bottom-up method with Bubble-down)

Best: Θ(n). Average: Θ(n). Worst: Θ(n) (sum of h·n/2^h = 2n). Extra space: O(1) (in-place).

19
New cards

Linear search (unsorted array or list)

Best: O(1) (item is first). Average: O(n). Worst: O(n) (item is last or absent). Extra space: O(1).

20
New cards

Binary search (sorted array)

Best: O(1) (item is at the middle). Average: O(log n). Worst: O(log n). Extra space: O(1) iterative.

21
New cards

Unsorted array: search / insert / delete

Search: best O(1), average O(n), worst O(n). Insert: O(n) (may need to copy to a larger array). Delete: O(n). Space: O(n) for the stored data.

22
New cards

Sorted array: search / insert / delete

Search (binary search): best O(1), average O(log n), worst O(log n). Insert: O(n) (shift elements). Delete: O(n) (shift elements). Space: O(n) for the stored data.

23
New cards

Unsorted linked list: search / insert / delete

Search: best O(1), average O(n), worst O(n). Insert (at the front): O(1). Delete: O(n) (must search first). Space: O(n) for the stored data.

24
New cards

Sorted linked list: search / insert / delete

Search: best O(1), average O(n), worst O(n). Insert: O(n). Delete: O(n). Space: O(n) for the stored data.

25
New cards

Direct-address table (search / insert / delete)

Best: O(1). Average: O(1). Worst: O(1) for all three operations. Space: Θ(m), where m is the size of the key range (can be very wasteful).

26
New cards

Hash table with no collisions (search / insert / delete)

Best: O(1). Average: O(1). Worst: O(1) (go to position h(k)). Space: Θ(m), with m much smaller than the universe.

27
New cards

Hash table with chaining: insert

Best: O(1). Average: O(1). Worst: O(1) (attach to the front or back of the chain at h(k)). Space: O(m + n) (table plus chain nodes).

28
New cards

Hash table with chaining: search / delete

Best: O(1) (key is first in its chain). Average: O(1 + α) under uniform hashing, where α = n/m (O(1) if α is constant). Worst: O(n) (all keys in one chain). Space: O(m + n).

29
New cards

Hash table with open addressing: search / insert / delete

Best: O(1) (first probe succeeds). Average: expected at most 1/(1 - α) probes under uniform hashing (α < 1). Worst: O(n) probes (as the table fills, up to m). Space: O(m), with n ≤ m.

30
New cards

Average-finding algorithm (sum n numbers, divide by n)

Best: Θ(n). Average: Θ(n). Worst: Θ(n) (one pass through the n numbers). Extra space: O(1).