Download presentation
Presentation is loading. Please wait.
Published byΝύξ Ανδρεάδης Modified over 6 years ago
1
Assignment #8 on Chapter 11: Search Trees (Sorry No Code)
By H.B.
2
Initial idea: Make a normal tree. For every vertex,make a balanced tree to store the sum of each color. The order depends on the amount. Search the answer.
3
1. Make a normal tree. 2. Record the queries. 3. Record the amount of every color of the subtree of the lowest vertices. (Using recursion & Balanced search tree) 4. Record the answer. 5. Loops: Update the balanced tree while processing the higher vertex and record the answer.
4
Numbers in list a & Numbers not in list a ;
How many numbers that are bigger than the current one are moved to the front ; 2 1 3
5
Make a splay tree to record the number and its position. (*2)
When a number is moved, mark it and “SPLAY” it. Now the right sub tree is made up with numbers “larger” than it. If the current position is negative, the answer is the sum. Or the answer is the number + s.
6
Balanced tree. (One by one)
Find the farthest one that he can stand before. Compare the distance and his “c”. Insert the new man with his new position.
7
1. Make 26 splay trees for each letter
1. Make 26 splay trees for each letter. Use 1 & 0 to mark the nodes if the number at the current position is or is NOT the letter. 2. Each node has a flag. 3. Take the letter “a” as an example. When it comes to the range that we want to change, we can know the amount of it in the splay tree a. ( Splay two sides) 4. The FLAG of the parent of the first/ last few vertices is 1.
8
zig-zag zig-zig zig x z z y z y y T4 T1 x T4 T1 T2 T3 T4 x T3 T2 T3 T1
w T2 z w y T3 T1 T2 T3 T4 T3 T4 T1 T2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.