8._The_Binary_Tree.pdf

# 8._The_Binary_Tree.pdf - Binary Trees CS221(A Data...

• 64

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

Binary Trees CS221(A) Data Structures & Algorithms

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

Binary Trees Tree with no node having more than two children. A finite set of nodes, one of which is designated as the root. The root node may have at most two sub-trees, each of which is also a binary tree. The two sub-trees of a given node are ordered and we refer to them as left child and the right child. Respectively.
Binary Trees Nodes in a binary tree may have zero, one or two children. A B C D E F G H

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

Binary Trees The maximum number of nodes for an entire binary tree of depth k is. 2 k - 1 for k ≥ 1 A full binary tree of depth k is a binary tree with 2 k - 1 nodes. That is the maximum number of nodes a binary tree can have. A B C D E F G H Max. No of Node = 15
Binary Tree Implementation typedef struct TreeNode *PtrToNode; typedef struct *PtrToNode Tree; Typedef struct *PtrToNode Root; struct TreeNode { ElementType Element; Tree Left; Tree Right; }

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

Binary Tree Implementation Element Variable will serve as our data field. Left and Right points to the two sub-trees. Value NULL indicates the absence of a sub- tree. Root points at the root node of the tree. Root == NULL indicates an empty tree.
Binary Tree Traversal Visiting each node exactly once, is called Traversal. When positioned at any given node a traversal function may Continue down to left sub-tree or Continue down to right sub-tree or Or process the current node

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

Binary Tree Traversal To process the data item we have the following options.
This is the end of the preview. Sign up to access the rest of the document.

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