CS
chapter8

# chapter8 - TREES Chapter 8 Chapter Objectives To learn how...

• Lecture Slides
• 189

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

TREES Chapter 8

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

Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how to use recursion to process trees To understand the different ways of traversing a tree To understand the differences between binary trees, binary search trees, and heaps To learn how to implement binary trees, binary search trees, and heaps using
Chapter Objectives (cont.) To learn how to use a binary search tree to store information so that it can be retrieved in an efficient manner To learn how to use a Huffman tree to encode characters using fewer bits than ASCII or Unicode, resulting in smaller files and reduced storage requirements

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

Trees - Introduction All previous data organizations we've studied are linear—each element can have only one predecessor and one successor Accessing all elements in a linear sequence is O( n ) Trees are nonlinear and hierarchical Tree nodes can have multiple successors (but only one predecessor)
Trees - Introduction (cont.) Trees can represent hierarchical organizations of information: class hierarchy disk directory and subdirectories family tree

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

Trees - Introduction (cont.) Trees are recursive data structures because they can be defined recursively Many methods to process trees are written recursively This chapter focuses on the binary tree In a binary tree each element has two successors Binary trees can be represented by arrays and by linked data structures Searching a binary search tree, generally is more efficient than searching an ordered list—O(log n ) versus O(n)
Section 8.1 Tree Terminology and Applications

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

Tree Terminology dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors
Tree Terminology (cont.) dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the top of a tree is called its root

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

Tree Terminology (cont.) dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors The links from a node to its successors are called branches
Tree Terminology (cont.) dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors The successors of a node are called its children

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

Tree Terminology (cont.) dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors The predecessor of a node is called its parent
Tree Terminology (cont.) dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors Each node in a tree has exactly one parent except for the root node, which has no parent

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

Tree Terminology (cont.) dog dog cat cat wolf wolf canin e canin e A tree consists of a collection of elements or nodes, with each node linked to its successors Nodes that have the same parent are siblings
Tree Terminology (cont.)

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 '08
• GIRAUD
• Cont

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