Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Structures: BST Analysis and Removal, Exercises of Data Structures and Algorithms

An analysis of the running time for various operations on a Binary Search Tree (BST), including find, insert, delete, and traverse. It also discusses the concept of height balance and the impact of data insertion order on the height of the tree. The document also mentions the redo policy for CS 225 students and the functional data structures in Clojure for the honors section.

Typology: Exercises

2021/2022

Uploaded on 09/12/2022

arien
arien 🇺🇸

4.8

(24)

310 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 225
Data Structures
October 4 BST Remove
G Carl Evans
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Data Structures: BST Analysis and Removal and more Exercises Data Structures and Algorithms in PDF only on Docsity!

CS 225

Data Structures

October 4 – BST Remove

G Carl Evans

MP Redo

  • There will be two redos of MPs this semester. The redo will be done

one the code in your repo on the last day of class December 8

th

. The

redo will change you grade to the following.

Max(old_grade, .90 * new_grade)

template<typename K, typename V>

*________________________ _remove(TreeNode & root, const K & key) {

}

1 2 3 4 5 6 7 8 9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

root

remove(40);

remove(10);

remove(13);

BST Analysis

Every operation that we have studied on a BST depends on

the height of the tree: O(h).

…what is this in terms of n , the amount of data?

We need a relationship between h and n :

f(h) ≤ n ≤ g(h)

BST Analysis

Q: What is the maximum number of nodes in a tree of

height h?

A

S X

2

22

2 5

BST Analysis

Therefore, for all BST:

Lower bound:

U pper bound:

BST Analysis

The height of a BST depends on the order in which the data

is inserted into it.

ex: 1 3 2 4 5 7 6 vs. 4 2 3 6 7 1 5

Q: How many different ways are there to insert keys into a

BST?

Q: What is the average height of all the arrangements?

BST Analysis – Running Time

Operation

BST

Average case

BST

Worst case

Sorted array Sorted List

find

insert

delete

traverse

Height-Balanced Tree

What tree makes you happier?

Height balance: b = height(T

L

) - height(T

R

A tree is height balanced if:

5 9

7

7

5

9