24-Applications of Trees - EECS 210 Discrete Structures...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Applications of Trees David O. Johnson EECS 210 (Fall 2016) 1 EECS 210 Discrete Structures David O. Johnson Fall 2016
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Reminders Homework 6 due: Thursday, December 1 at the beginning of your lecture Connect 6 due: 11:59 PM, Thursday, December 8 Applications of Trees David O. Johnson EECS 210 (Fall 2016) 2
Image of page 2
Any Questions? Applications of Trees 3 David O. Johnson EECS 210 (Fall 2016)
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Applications of Trees (Section 11.2) Binary Search Trees Decision Trees Prefix Codes Game Trees Applications of Trees David O. Johnson EECS 210 (Fall 2016) 4
Image of page 4
Binary Search Trees Searching for items in a list is one of the most important tasks that arises in computer science. Our primary goal is to implement a searching algorithm that finds items efficiently when the items are totally ordered. This can be accomplished through the use of a binary search tree, which is a binary tree in which each child of a vertex is designated as a right or left child, no vertex has more than one right child or left child , and each vertex is labeled with a key, which is one of the items. Furthermore, vertices are assigned keys so that the key of a vertex is both larger than the keys of all vertices in its left subtree and smaller than the keys of all vertices in its right subtree. Applications of Trees David O. Johnson EECS 210 (Fall 2016) 5 5 6 4 left child right child
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Binary Search Trees This recursive procedure is used to form the binary search tree for a list of items. Start with a tree containing just one vertex, namely, the root. The first item in the list is assigned as the key of the root. To add a new item, first compare it with the keys of vertices already in the tree, starting at the root and moving to the left if the item is less than the key of the respective vertex if this vertex has a left child, or moving to the right if the item is greater than the key of the respective vertex if this vertex has a right child. When the item is less than the respective vertex and this vertex has no left child, then a new vertex with this item as its key is inserted as a new left child. Similarly, when the item is greater than the respective vertex and this vertex has no right child, then a new vertex with this item as its key is inserted as a new right child. We illustrate this procedure with an example. Applications of Trees David O. Johnson EECS 210 (Fall 2016) 6
Image of page 6
Binary Search Tree Creation Solution: The word mathematics is the key of the root. Because physics comes after mathematics (in alphabetical order), add a right child of the root with key physics. Because geography comes before mathematics, add a left child of the root with key geography. Next, add a right child of the vertex with key physics, and assign it the key zoology , because zoology comes after mathematics and after physics.
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern