24-Applications of Trees

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

• Notes
• 46
• 100% (1) 1 out of 1 people found this document helpful

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

Applications of Trees David O. Johnson EECS 210 (Fall 2016) 1 EECS 210 Discrete Structures David O. Johnson Fall 2016

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

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
Any Questions? Applications of Trees 3 David O. Johnson EECS 210 (Fall 2016)

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

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
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

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

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
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.

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

This is the end of the preview. Sign up to access the rest of the document.
• Fall '12
• kato
• David O. Johnson EECS, O. Johnson EECS, David O. Johnson

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern