time complexities

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

1/45

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:07 AM on 5/4/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

46 Terms

1
New cards

Insert at head

Best Case: O(1), Worst Case: O(1), Why: Only update head

2
New cards

Remove head

Best Case: O(1), Worst Case: O(1), Why: Only update head

3
New cards

Insert at tail (with tail ref)

Best Case: O(1), Worst Case: O(1), Why: Direct pointer

4
New cards

Insert at tail (no tail ref)

Best Case: O(n), Worst Case: O(n), Why: Must traverse

5
New cards

Remove tail

Best Case: O(n), Worst Case: O(n), Why: Need previous node

6
New cards

Search

Best Case: O(1), Worst Case: O(n), Why: First node vs last/not found

7
New cards

Count nodes

Best Case: O(n), Worst Case: O(n), Why: Must traverse

8
New cards

Access root

Best Case: O(1), Worst Case: O(1), Notes: Always direct

9
New cards

Traverse tree

Best Case: O(n), Worst Case: O(n), Notes: All nodes visited

10
New cards

Search in Binary Search Trees (BST)

Best Case: O(log n), Worst Case: O(n), When: Balanced vs skewed

11
New cards

Insert in Binary Search Trees (BST)

Best Case: O(log n), Worst Case: O(n), When: Sorted input causes skew

12
New cards

Remove in Binary Search Trees (BST)

Best Case: O(log n), Worst Case: O(n), When: Same reasoning

13
New cards

Search in AVL Trees

Best Case: O(log n), Worst Case: O(log n), Why: Tree stays balanced

14
New cards

Insert in AVL Trees

Best Case: O(log n), Worst Case: O(log n), Why: Rotations are O(1)

15
New cards

Remove in AVL Trees

Best Case: O(log n), Worst Case: O(log n), Why: Rebalancing up tree

16
New cards

Push in Stacks

Best Case: O(1), Worst Case: O(1), Notes: Array or linked list

17
New cards

Pop in Stacks

Best Case: O(1), Worst Case: O(1), Notes: Remove top

18
New cards

Peek in Stacks

Best Case: O(1), Worst Case: O(1), Notes: No removal

19
New cards

Search in Stacks

Best Case: O(n), Worst Case: O(n), Notes: Must scan

20
New cards

Enqueue in Queues

Best Case: O(1), Worst Case: O(1), Notes: With circular array / linked list

21
New cards

Dequeue in Queues

Best Case: O(1), Worst Case: O(1), Notes: Remove front

22
New cards

First in Queues

Best Case: O(1), Worst Case: O(1), Notes: No removal

23
New cards

Search in Queues

Best Case: O(n), Worst Case: O(n), Notes: Must scan

24
New cards

Hash Tables - Search

O(1) best / O(n) worst case due to many collisions

25
New cards

Hash Tables - Insert

O(1) best / O(n) worst case due to table full or collisions

26
New cards

Hash Tables - Remove

O(1) best / O(n) worst case due to same reasoning

27
New cards

Priority Queues - Unsorted List Insert

O(1) best / O(1) worst case

28
New cards

Priority Queues - Unsorted List min

O(n) best / O(n) worst case

29
New cards

Priority Queues - Unsorted List remove_min

O(n) best / O(n) worst case

30
New cards

Priority Queues - Sorted List Insert

O(n) best / O(n) worst case

31
New cards

Priority Queues - Sorted List min

O(1) best / O(1) worst case

32
New cards

Priority Queues - Sorted List remove_min

O(1) best / O(1) worst case

33
New cards

Priority Queues - Heap Insert

O(1)* best / O(log n) worst case

34
New cards

Priority Queues - Heap min

O(1) best / O(1) worst case

35
New cards

Priority Queues - Heap remove_min

O(log n) best / O(log n) worst case

36
New cards

Selection Sort

O(n²) best / O(n²) worst case, always scans entire list

37
New cards

Insertion Sort

O(n) best / O(n²) worst case, fast on nearly-sorted data

38
New cards

Heap Sort

O(n log n) best / O(n log n) worst case, guaranteed

39
New cards

BST-based sort

O(n log n) best / O(n²) worst case, unbalanced tree risk

40
New cards

Exam-Day Memory Rule - Insert

Upheap

41
New cards

Exam-Day Memory Rule - Remove

Downheap

42
New cards

Exam-Day Memory Rule - Queue

FIFO

43
New cards

Exam-Day Memory Rule - Stack

LIFO

44
New cards

Exam-Day Memory Rule - Heap height

O(log n)

45
New cards

Exam-Day Memory Rule - Hash tables

O(1) expected, O(n) worst

46
New cards

Exam-Day Memory Rule - Insertion sort best case

O(n)