



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The implementation of a map data structure using a binary search tree. The concepts of binary trees, binary search trees, tree terminology, and the advantages of using a binary search tree over a vector for efficient search and insert operations. The document also includes examples of tree traversals and the implementation of adding a new node to a binary search tree.
Typology: Lecture notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




!!!!! Unsorted Sorted Map() O(1) O(1) ~Map() O(1) O(1) add() O(N) O(N) getValue() O(N) O(logN) Overhead per entry none none
Bashful Doc Dopey Grumpy Happy Sleepy Sneezy Bashful Doc Dopey Grumpy Happy Sleepy Sneezy Bashful Doc Dopey Grumpy Happy Sleepy Sneezy
Bashful Doc Dopey Grumpy Happy Sleepy Sneezy
Trees in general Rules for all trees
Binary search tree in specific Binary tree
struct node { int val; node *left, *right; }; Operating on trees Many tree algorithms are recursive
Map implementation template
A balanced tree Values: 2 8 14 15 18 20 21 Different trees possible, depends on order inserted 7 nodes, expected height lg7! 3 Perfectly balanced 8 15 20 (^2 14 ) Entered: 15 8 2 20 21 14 18 (one possibility) Mostly balanced trees Same values: 2 8 14 15 18 20 21 Mostly balanced, height 4 or 5
Degenerate trees Same values: 2 8 14 15 18 20 21 Totally unbalanced, height = 7 Entered: 2 8 14 15 18 20 21 (only possibility)
Entered: 21 20 18 15 14 8 2 (only possibility)
Even more degenerate trees What is relationship between worst-case inputs for tree insertion and Quicksort? Entered: (^21 2 20 8 14 15 18) Entered: 2 8 21 20 18 14 15