binary search trees

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

1/32

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.

33 Terms

1
New cards

bst def

left < root < right

2
New cards

insert in bst

recursively go left/right until null, then insert

3
New cards

are duplicates allowed in a bst

generally NO.

4
New cards

worst case height of bst (big o)

o(n) - tree is skewed

5
New cards

best case height of bst

o(log n) - tree is level, balanced

6
New cards

in order traversal

left - root - right

7
New cards

pre order

root - left - right

8
New cards

post order

left - right - root

9
New cards

level order

breadth first using a queue

10
New cards

delete leaf node - how

just remove it

11
New cards

delete node with one child

replace with the child. corrupt them all.

12
New cards

delete node with two children

replace with in order successor/predecessor

successor is more common

does NOT make any difference

13
New cards

in order successor

smallest node in RIGHT subtree

14
New cards

in order predecessor

largest node in LEFT subtree

15
New cards

what if forget to return the modified subtree on delete/insert

tree doesnt update, logic silently farts in the wind

16
New cards

how is traversal different from structure

traversal visits nodes

17
New cards

visit definition

perform an action on a node—print, remove, etc.

18
New cards

does inserting count as visiting

NO!! what u gana visit if there is no node yet vro 💔💔

19
New cards

recursive insert returns?

new subtree root

20
New cards

deletion time complexity

o(h), h = tree height

21
New cards
22
New cards

does insertion rebalance a bst

no, can become skewed if data is unbalanced

23
New cards

in order traversal always returns?

sorted values (ascending)

24
New cards

In deletion, what does a 2-child case reduce to?

A 1-child or leaf node case (after replacing value)

25
New cards

What happens if you forget to check for null before recursive call?

NullPointerException

26
New cards

Can you use predecessor instead of successor when deleting?

Yes — either keeps the BST valid

27
New cards
28
New cards

Are left and right subtrees of a BST also BSTs?

Yes, by definition

29
New cards

What is the base case for a recursive BST insert?

curNode == null

30
New cards

full tree def

every node has either 0 or 2 children

31
New cards

perfect tree def

all internal nodes have 2 children and all leaf nodes are on the same level (fully filled out)

32
New cards

complete

every level is perfect except for last

last level must be far left as possible

33
New cards

are perfect trees ALWAYS full? are they ALWAYS complete?

by definition yes