tutorial 10 binary trees
play

Tutorial 10 - Binary Trees A binary tree is a linked data structure - PowerPoint PPT Presentation

Tutorial 10 - Binary Trees A binary tree is a linked data structure where each element has a link to at most two child nodes There is a root node that is not the child of any other node There are leaf nodes which have no children 1 CS


  1. Tutorial 10 - Binary Trees • A binary tree is a linked data structure where each element has a link to at most two child nodes • There is a root node that is not the child of any other node • There are leaf nodes which have no children 1 CS 136 Spring 2020 Tutorial 10

  2. Root Node Leaf Nodes 2 CS 136 Spring 2020 Tutorial 10

  3. Binary Search Trees • A binary search tree is a binary tree where each element is associated with a value • The left child and all of its descendants have values that are lower than it’s parent’s value • The right child and all of its descendants have values that are higher than it’s parent’s value 3 CS 136 Spring 2020 Tutorial 10

  4. 4 CS 136 Spring 2020 Tutorial 10

  5. Binary Search Trees • Binary search trees represent collections of data that can be ordered • We can check whether or not a value is stored in the binary search tree using binary search 5 CS 136 Spring 2020 Tutorial 10

  6. 6 CS 136 Spring 2020 Tutorial 10

  7. 7 CS 136 Spring 2020 Tutorial 10

  8. 8 CS 136 Spring 2020 Tutorial 10

  9. 9 CS 136 Spring 2020 Tutorial 10

  10. Exercise: Implement a Binary Search Tree 1. Implement a binary search tree in C. 2. Provide a method called push for adding new nodes to a tree. 3. Provide a method called find that checks whether some value is contained in the binary tree. Use binary search. 4. Provide a method called print that prints a binary search tree. 10 CS 136 Spring 2020 Tutorial 10

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