1 / 20

CompSci 105 SS 2005 Principles of Computer Science

CompSci 105 SS 2005 Principles of Computer Science. Lecture 22: Efficiency of BST Operations. Lecturer: Santokh Singh. Inorder Traversal. void printTree( TreeNode root) if ( root != null ) printTree( root.getLeft () ); println(root.getRootItem()); printTree( root.getRight() ); }.

lynton
Download Presentation

CompSci 105 SS 2005 Principles of Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CompSci 105 SS 2005 Principles of Computer Science Lecture 22: Efficiency of BST Operations Lecturer: Santokh Singh

  2. Inorder Traversal void printTree( TreeNode root) if ( root != null ) printTree( root.getLeft () ); println(root.getRootItem()); printTree( root.getRight() ); } M B Q J O U Textbook, p. 434

  3. Deleting the root root root root root M M M M Q B Q B U J U J O O No children No right child No left child Two children Textbook, p. 462

  4. Exercise • Draw the BST that results from inserting the values D, C, G, B, E, F in order. Now draw the result of deleting the root.

  5. Treesort Please refer to the prescribed Textbook, pages 478-479, now.

  6. ADT Table Textbook, p. 498-499

  7. ADT Table Operations void create () int length() void insert( item) void delete( key ) item find(key) Textbook, p. 498-499

  8. ADT Table Unsorted Array Sorted Array Program that uses a table Sorted Linked List ADT Table Unsorted Linked List Binary Search Tree Textbook, p. 504-517

  9. M B Q J O U BST Efficiency Textbook, p. 474-478

  10. M B Q U J O U Q O BST Efficiency M J B Textbook, p. 474-478

  11. M B Q U J O U Q O Average Case? M J B Textbook, p. 474-478

  12. Full and Complete Trees M Q G O U B J A full tree Textbook, p. 427

  13. Full and Complete Trees M M Q Q G G O U B J B A full tree A complete tree Textbook, p. 427

  14. Minimising Tree Height M B Q A J O Textbook, p. 480-481

  15. ADT Priority Queue • To do: • Study for 105 Exam • Play • Eat • 4. Sleep Textbook, p. 517

  16. Priority Queue Operations void create () boolean isEmpty() void insert( item) item delete() • To do: • Study for 105 Exam • Play • Eat • 4. Sleep Textbook, p. 518

  17. ADT Table Unsorted Array Sorted Array Program that uses a priority queue Sorted Linked List ADT Priority Queue Unsorted Linked List Binary Search Tree

  18. Heap Like a binary search tree, but • Always keep it a complete tree • Don’t completely sort data Textbook, p. 520

  19. Heap Like a binary search tree, but • Always keep it a complete tree • Don’t completely sort data … just make sure that each node’s key is bigger than its children’s keys. Textbook, p. 520

  20. BST’s vs Heaps M U Q J G Q G U B J B M BST heap

More Related