Big-O notation and BST

studied byStudied by 5 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 52

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

53 Terms

1

ArrayList addAtIndex()

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

New cards
2

ArrayList addToFront()

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

New cards
3

ArrayList addToBack()

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

New cards
4

ArrayList removeAtIndex()

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

New cards
5

ArrayList removeFromFront()

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

New cards
6

ArrayList removeFromBack()

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

New cards
7

Singly LinkedList addAtIndex()

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

New cards
8

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.

New cards
9

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.

New cards
10

Singly LinkedList removeAtFront()

O(1); simply update the head pointer.

New cards
11

Singly LinkedList removeAtIndex()

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

New cards
12

Singly LinkedList removeAtBack()

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

New cards
13

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

New cards
14

Doubly LinkedList addFront()

O(1); update head pointer

New cards
15

Doubly LinkedList addBack()

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

New cards
16

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

New cards
17

Doubly LinkedList removeFront()

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

New cards
18

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

New cards
19

CSLL addAtIndex()

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

New cards
20

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

New cards
21

CSLL addAtBack()

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

New cards
22

CSLL removeAtIndex()

O(n) unless at the head

New cards
23

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.

New cards
24

CSLL removeBack()

O(n) without a tail pointer.

New cards
25

Stack Array push()

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

New cards
26

Stack Array pop()

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

New cards
27

Queue Array enqueue()

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

New cards
28

Queue Array dequeue()

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

New cards
29

Stack LL push()

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

New cards
30

Stack LL pop()

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

New cards
31

Queue LL enqueue()

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

New cards
32

Queue LL dequeue()

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

New cards
33

Deque Array addFront()

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

New cards
34

Deque Array addBack()

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

New cards
35

Deque Array removeFront()

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

New cards
36

Deque Array removeBack()

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

New cards
37

Deque DLL addFront()

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

New cards
38

Deque DLL addBack()

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

New cards
39

Deque DLL removeFront()

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

New cards
40

Deque DLL removeBack()

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

New cards
41

Pre-Order Traversal

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

New cards
42

In-order traversal

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

New cards
43

Post-Order Traversal

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

New cards
44

Level-Order Traversal

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

New cards
45

Predecessor

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

New cards
46

Successor

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

New cards
47

Full Binary Tree

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

New cards
48

Complete Binary Tree

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

New cards
49

Degenerate Tree

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

New cards
50

Balanced Tree

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

New cards
51

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

New cards
52

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

New cards
53

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

New cards

Explore top notes

note Note
studied byStudied by 32 people
605 days ago
5.0(1)
note Note
studied byStudied by 94 people
1011 days ago
5.0(1)
note Note
studied byStudied by 17 people
825 days ago
5.0(1)
note Note
studied byStudied by 1 person
784 days ago
5.0(1)
note Note
studied byStudied by 37 people
659 days ago
5.0(1)
note Note
studied byStudied by 14 people
911 days ago
5.0(1)
note Note
studied byStudied by 9 people
888 days ago
5.0(1)
note Note
studied byStudied by 5422 people
705 days ago
4.6(34)

Explore top flashcards

flashcards Flashcard (49)
studied byStudied by 6 people
834 days ago
5.0(1)
flashcards Flashcard (32)
studied byStudied by 5 people
489 days ago
5.0(1)
flashcards Flashcard (72)
studied byStudied by 35 people
90 days ago
5.0(1)
flashcards Flashcard (34)
studied byStudied by 9 people
366 days ago
5.0(1)
flashcards Flashcard (24)
studied byStudied by 62 people
561 days ago
4.5(2)
flashcards Flashcard (51)
studied byStudied by 1 person
48 days ago
5.0(3)
flashcards Flashcard (100)
studied byStudied by 4 people
449 days ago
5.0(1)
flashcards Flashcard (423)
studied byStudied by 2 people
1 hour ago
5.0(1)
robot