cs 225
play

CS 225 Data Structures Ma March 9 AV AVL Applications G G Carl - PowerPoint PPT Presentation

CS 225 Data Structures Ma March 9 AV AVL Applications G G Carl Evans AV AVL Runtime Proof On Friday, we proved an upper-bound on the height of an AVL tree is 2 lg(n) or O( lg(n) ) : N(h) := Minimum # of nodes in an AVL tree of height


  1. CS 225 Data Structures Ma March 9 – AV AVL Applications G G Carl Evans

  2. AV AVL Runtime Proof On Friday, we proved an upper-bound on the height of an AVL tree is 2 × lg(n) or O( lg(n) ) : N(h) := Minimum # of nodes in an AVL tree of height h N(h) = 1 + N(h-1) + N(h-2) > 1 + 2 h-1/2 + 2 h-2/2 > 2 × 2 h-2/2 = 2 h-2/2+1 = 2 h/2 Theorem #1: Every AVL tree of height h has at least 2 h/2 nodes.

  3. AV AVL Runtime Proof On Friday, we proved an upper-bound on the height of an AVL tree is 2 × lg(n) or O( lg(n) ) : # of nodes (n) ≥ N(h) > 2 h/2 n > 2 h/2 lg(n) > h/2 2 × lg(n) > h h < 2 × lg(n) , for h ≥ 1 Proved: The maximum number of nodes in an AVL tree of height h is less than 2 × lg(n).

  4. Su Summary of of Ba Balance ced BS BST AVL Trees - Max height: 1.44 * lg(n) - Rotations:

  5. Su Summary of of Ba Balance ced BS BST AVL Trees - Max height: 1.44 * lg(n) - Rotations: Zero rotations on find One rotation on insert O( h ) == O( lg(n) ) rotations on remove Red-Black Trees - Max height: 2 * lg(n) - Constant number of rotations on insert (max 2), remove (max 3).

  6. Wh Why Ba Balanced BS BST?

  7. Su Summary of of Ba Balance ced BS BST Pros: - Running Time: - Improvement Over: - Great for specific applications:

  8. Su Summary of of Ba Balance ced BS BST Cons: - Running Time: - In-memory Requirement:

  9. Re Red-Bl Black T Trees i in C+ C++ C++ provides us a balanced BST as part of the standard library: std::map<K, V> map;

  10. Re Red-Bl Black T Trees i in C+ C++ V & std::map<K, V>::operator[]( const K & )

  11. Re Red-Bl Black T Trees i in C+ C++ V & std::map<K, V>::operator[]( const K & ) std::map<K, V>::erase( const K & )

  12. Re Red-Bl Black T Trees i in C+ C++ iterator std::map<K, V>::lower_bound( const K & ); iterator std::map<K, V>::upper_bound( const K & );

  13. CS 225 CS 225 -- -- Cou Course U Update Your grades can now be viewed on moodle (https://learn.illinois.edu/) We will discuss the grades for the course as a whole (ex: average, etc) in lecture on Wednesday.

  14. It Iter erators Why do we care? 1 DFS dfs(...); 2 for ( ImageTraversal::Iterator it = dfs.begin(); it != dfs.end(); ++it ) { 3 std::cout << (*it) << std::endl; 4 }

  15. Iter It erators Why do we care? 1 DFS dfs(...); 2 for ( ImageTraversal::Iterator it = dfs.begin(); it != dfs.end(); ++it ) { 3 std::cout << (*it) << std::endl; 4 } 1 DFS dfs(...); 2 for ( const Point & p : dfs ) { 3 std::cout << p << std::endl; 4 }

  16. It Iter erators Why do we care? 1 DFS dfs(...); 2 for ( ImageTraversal::Iterator it = dfs.begin(); it != dfs.end(); ++it ) { 3 std::cout << (*it) << std::endl; 4 } 1 DFS dfs(...); 2 for ( const Point & p : dfs ) { 3 std::cout << p << std::endl; 4 } 1 ImageTraversal & traversal = /* ... */; 2 for ( const Point & p : traversal ) { 3 std::cout << p << std::endl; 4 }

  17. Ev Every Data Structure So Far Unsorted Sorted Unsorted Sorted Binary Tree BST AVL Array Array List List Find Insert Remove Traverse

  18. Ra Range-ba base sed d Searche hes Q: Consider points in 1D: p = {p 1 , p 2 , …, p n }. …what points fall in [11, 42]? Tree construction:

  19. Ra Range-ba base sed d Searche hes Balanced BSTs are useful structures for range-based and nearest-neighbor searches. Q: Consider points in 1D: p = {p 1 , p 2 , …, p n }. …what points fall in [11, 42]? Ex: 6 11 41 44 3 33 55

  20. Ra Range-ba base sed d Searche hes Q: Consider points in 1D: p = {p 1 , p 2 , …, p n }. …what points fall in [11, 42]? Ex: 6 11 41 44 3 33 55

  21. Ra Range-ba base sed d Searche hes Q: Consider points in 1D: p = {p 1 , p 2 , …, p n }. …what points fall in [11, 42]? Tree construction:

  22. Ra Range-ba base sed d Searche hes

  23. Ra Range-ba base sed d Searche hes 33 6 44 3 11 41 55 3 6 11 33 41 44

  24. Ra Range-ba base sed d Searche hes Q: Consider points in 1D: p = {p 1 , p 2 , …, p n }. …what points fall in [11, 42]? 33 6 44 3 11 41 55 3 6 11 33 41 44

  25. Ra Range-ba base sed d Searche hes 33 6 44 3 11 41 55 3 6 11 33 41 44

  26. Ru Running T Time 33 6 44 3 11 41 55 3 6 11 33 41 44

  27. Ra Range-ba base sed d Searche hes Q: Consider points in 1D: p = {p 1 , p 2 , …, p n }. …what points fall in [11, 42]? Ex: 6 11 41 44 3 33 55

  28. Ra Range-ba base sed d Searche hes Consider points in 2D: p = {p 1 , p 2 , …, p n }. Q: What points are in the rectangle: p 2 [ (x 1 , y 1 ), (x 2 , y 2 ) ]? p 5 p 6 p 1 Q: What is the nearest point to (x 1 , y 1 ) ? p 3 p 4 p 7

  29. Ra Range-ba base sed d Searche hes Consider points in 2D: p = {p 1 , p 2 , …, p n }. Tree construction: p 2 p 5 p 6 p 1 p 3 p 4 p 7

  30. Ra Range-ba base sed d Searche hes p 2 p 5 p 6 p 1 p 7 p 3 p 1 p 2 p 3 p 4 p 5 p 6 p 4 p 7

  31. kD kD-Tr Trees p 2 p 5 p 6 p 1 p 7 p 3 p 1 p 2 p 3 p 4 p 5 p 6 p 4 p 7

  32. kD kD-Tr Trees p 2 p 5 p 6 p 1 p 7 p 3 p 1 p 2 p 3 p 4 p 5 p 6 p 4 p 7

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend