binarytrees - Binary Trees A t ree is a data structure that...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Binary Trees A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: - In a linked list each node is connected to one “successor” node (via next pointer), that is, it is linear. - In a tree, the nodes can have several next pointers and thus are not linear. The top node in the tree is called the root and all other nodes branch off from this one. Every node in the tree can have some number of children. Each child node can in turn be the parent node to its children and so on. A common example of a tree structure is the binary tree. Definition: A binary tree is a tree that is limited such that each node has only two children. 2 Examples : The following are NOT binary trees: root root
Background image of page 1

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

View Full DocumentRight Arrow Icon
3 Definitions: If n1 is the root of a binary tree and n2 is the root of its left or right tree, then n1 is the parent of n2 and n2 is the left or right child of n1. A node that has no children is called a leaf . The nodes are siblings if they are left and right children of the same parent. The level of a node in a binary tree: - The root of the tree has level 0 - The level of any other node in the tree is one more than the level of its parent. Exercise : Construct all possible 5 binary trees with 3 nodes. root Level 0 Level 1 Level 2 Level 3 4 Implementation A binary tree has a natural implementation in linked storage. A separate pointer is used to point the tree (e.g. root)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

binarytrees - Binary Trees A t ree is a data structure that...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online