For BSTs, the most inefficient way to add is in to put it in order.
In a 2-3 tree, what is the worst case insertion order?
Talk about nodes in a B-tree being half full?
Worst case height of a weighted quick union:
How to approach give a task to do, and figure out what data structure to use?
First what tools do we have?
Read in a text file and print all of the unique words that appear. The words should be printed in alphabetical order
Use a TreeSet<String>
Read in a text file and print all of the unique words that appear. The words should be printed in alphabetical order
Use a TreeMap<String, Integer>
Erweiterten netzwerk:
Map<String, Integer> → username
�HashMap vs. TreeMap? We need O(log N) time.
Erweiterten netzwerk:
Map<String, Integer> → username
�HashMap vs. TreeMap? We need O(log N) time.
Let’s talk about LLRB height.
Come up with a sequence of union and connected operations such that the overall runtime of the sequence is O(N + #Union + #connected).
doStuff() {� WQU x = new WQU(x); // runtime is theta(N)
x.union( … ); do this lots of times // each needs to be constant
x.connected( … ); do this lots of times // each needs to be constant
}
Why is the answer “don’t do any union or connected calls at all” bad?
With clever insight, we realized the problem is really
We want to find a sequence of operations such that the height of the tree is … ALSO CONSTANT.
Prove that when you do range finding it takes theta(log N + R) where R is the number.
8
3
9
1
8
3
9
1
8
3
9
1
1
8
3
9
13
7
2
1
5
16
8
9
1
13
7
2
Find the smallest item, put it in the root
5
16
8
Adding elements to a binary search tree.
1
10
12
11
WRiting godo hashcodes: You should understand why the intiial ahscode from lecture wer enot good (multiplying by powers of 32)
If I do a 2-4, can I end up with one item in every node, yes, but I’m not sure of the seuqence.
For hash tables, do you insert at the end or beginning of list?
Data structures questions: OK to assume hashCode is well written? YES, but well writen is no guarantee of performance because of th pigeonhole performance.
\
13
7
2
1
5
16
8
9
1
13
7
2
Find the smallest item, put it in the root
5
16
8