Big-O notation and BST

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

1/52

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:50 PM on 2/5/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

53 Terms

1
New cards

ArrayList addAtIndex()

O(1) amortized for index at size and O(n) for the rest; Requires shifting elements to the right of the index

2
New cards

ArrayList addToFront()

O(n); Requires shifting all elements to the right.

3
New cards

ArrayList addToBack()

O(1) amortized; adding to back is O(1) but resizing the array can occasionally be O(n)

4
New cards

ArrayList removeAtIndex()

O(1) for index size - 1 and O(n) for other cases; requires shifting elements to the left of the index.

5
New cards

ArrayList removeFromFront()

O(n); requires shifting all elements to the left after removal.

6
New cards

ArrayList removeFromBack()

O(1); removing from the back is a constant time operation if the array is not resized.

7
New cards

Singly LinkedList addAtIndex()

O(n) unless its at the front; requires traversing the list to reach the specified index before adding the new element.

8
New cards

Singly LinkedList addAtFront()

O(1); adding an element at the front of a linked list is a constant time operation since it only involves updating the head pointer.

9
New cards

Singly LinkedList addAtBack()

O(1) with a tail, O(n) without a tail. With a tail, simply update the tail pointer. Without a tail, you have to traverse the entire list to find the last element before adding the new node.

10
New cards

Singly LinkedList removeAtFront()

O(1); simply update the head pointer.

11
New cards

Singly LinkedList removeAtIndex()

O(n); removing an element at a specific index requires traversing the list to that index.

12
New cards

Singly LinkedList removeAtBack()

O(n) always for a SLL; removing from the back requires traversing the list

13
New cards

Doubly LinkedList addAtIndex()

O(n) unless at the front or at the back with a tail; Still have to traverse the list to get to that given index

14
New cards

Doubly LinkedList addFront()

O(1); update head pointer

15
New cards

Doubly LinkedList addBack()

O(1) with a tail pointer; O(n) without. Need a tail pointer to update the back in constant time.

16
New cards

Doubly LinkedList removeAtIndex()

O(n) unless at the front or at the back with a tail pointer; Have to traverse the list to get to the given index

17
New cards

Doubly LinkedList removeFront()

O(1); update head and remove the node by pointing head at the second node

18
New cards

Doubly LinkedList removeBack()

O(1) with a tail pointer, O(n) without; Need a tail pointer to update the back by using the tail’s previous node, without you have to traverse the entire list

19
New cards

CSLL addAtIndex()

O(n) unless at front; Have to traverse the circular list to

20
New cards

CSLL addFront()

O(1); To add at front, you have to essentially point the newNode at the second node and then point the head node to that newNode and then swap their data

21
New cards

CSLL addAtBack()

O(n), O(1) with a tail pointer; Have to traverse the list to get to the back

22
New cards

CSLL removeAtIndex()

O(n) unless at the head

23
New cards

CSLL removeFront()

O(1); essentially get rid of the second node by pointing 1st node to 3rd node and then copying the data from the 2nd to the 1st.

24
New cards

CSLL removeBack()

O(n) without a tail pointer.

25
New cards

Stack Array push()

O(1) amortized; add to the back of the array and resizing if needed (addToBack() essentially)

26
New cards

Stack Array pop()

O(1); removing the top element from the stack is done in constant time. (removeFromBack() essentially)

27
New cards

Queue Array enqueue()

O(1) amortized; add to the back and resizing if needed

28
New cards

Queue Array dequeue()

O(1) amortized; using a circular buffer allows constant time removal from the front of the queue.

29
New cards

Stack LL push()

O(1), update the head pointer by doing the temp swap thing. head is the top of the stack

30
New cards

Stack LL pop()

O(1), update the head pointer by moving it back a node, removing the top of the stack

31
New cards

Queue LL enqueue()

O(1), update tail pointer. ADD to the back. use tail pointer as your back of your queue

32
New cards

Queue LL dequeue()

O(1); update the head pointer. REMOVE from the front. Use head pointer as the front and update to the next

33
New cards

Deque Array addFront()

O(1)*; circular deque starts with front at the back and decrementing the pointer. potential resizew

34
New cards

Deque Array addBack()

O(1)*; adding to the back actually starts at the front of the array and increments the back pointer. potential resize

35
New cards

Deque Array removeFront()

O(1); removing an element from the front increments front with wrap around modulo arithmetic

36
New cards

Deque Array removeBack()

O(1) removing an element from the back involves decrementing the back pointer (with wrap around using modulo)

37
New cards

Deque DLL addFront()

O(1) insert newnode at head and update head pointer

38
New cards

Deque DLL addBack()

O(1); insert newNode at the tail and update tail pointer

39
New cards

Deque DLL removeFront()

O(1); remove the node at the head and update head pointer

40
New cards

Deque DLL removeBack()

O(1); remove the node at the tail and update the tail pointer

41
New cards

Pre-Order Traversal

O(n); Visits the nodes in order; Root → Left→ Right; Uses Recursion

42
New cards

In-order traversal

O(n); Visits nodes in order: Left → Root → Right; Uses Recursion

43
New cards

Post-Order Traversal

O(n); Visits nodes in the order: Left → Right → Root. Uses recursion

44
New cards

Level-Order Traversal

O(n) Visits nodes level by level, from top to bottom; Uses a queue

45
New cards

Predecessor

In an in-order traversal, predecessor of a node is the previous node in sorted order

46
New cards

Successor

The successor of a node is the next node in sorted order

47
New cards

Full Binary Tree

Every node has either 0 or 2 children (no nodes with a single child)

48
New cards

Complete Binary Tree

All levels are fully filled except possibly the last, which is filled from left to right

49
New cards

Degenerate Tree

Each parent node has only one child, making it resemble a linked list

50
New cards

Balanced Tree

The height difference between left and right subtrees is at most 1 for all nodes

51
New cards

Binary Tree search()

O(log n) average case; O(n) worst case b/c of unbalanced BST;
Starts at root and checks if target is smaller, go left or right based on that

52
New cards

Binary Tree add()

O(log n) for balanced tree, O(n) unbalanced/degenerate
Start at root, compare value with current node. smaller = go left, greater = go right

53
New cards

Binary Tree remove()

O(log n) average case; O(n) worst case
Traverse tree, find in order successor (greater node to the right), replace the node with successor, delete successor from original position