0% found this document useful (0 votes)
16 views7 pages

Lab Binary Tree

The document defines common terms related to binary trees and describes operations on binary trees like search, insertion, and deletion. It also provides examples of binary search trees and heaps with explanations of traversal methods and construction algorithms.

Uploaded by

Aini Ayunni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Lab Binary Tree

The document defines common terms related to binary trees and describes operations on binary trees like search, insertion, and deletion. It also provides examples of binary search trees and heaps with explanations of traversal methods and construction algorithms.

Uploaded by

Aini Ayunni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Binary Tree

Definitions:
Term Definition
a. Depth of a node Number of edges on path from root to the node
b. Depth of a tree Number of edges on the longest path between root and a leaf
c. Height of a node Number of edges on the longest downward path between that node and
a leaf
d. Height of a tree Number of edges on the longest downward path between root and a leaf
e. Binary tree A tree where a parent can only have up to 2 children
f. Proper binary tree A parent can only have 2 children or none at all
g. Complete binary All levels must be completed, except for the last level, but it must be filled
tree as left as possible
h. Perfect binary tree All levels are completely filled
i. Binary search tree A binary tree where the left side children of a parent must be smaller than
the parent, while the right side is equal or larger than the parent
j. Heap A complete binary tree, where the children of a parent must be equal or
smaller than the parent (satisfy heap-order property)

Describe and explain the operations (tree, binary tree, BST & heap):
a. In above tree, F is the root node.

b. A,C,E,H are the leaf nodes.

c. B,D,F are the common ancestors of C and A.

d. C,E,H are the common descendants of D and I.

e. Depth of node B is '1'.

f. Level of node I is Level 3.

g. Height of this tree is 3.

h. The maximum nodes that contains at the level of node I are 4 nodes.

i. The minimum number of nodes that needs to be added to this tree to be called complete binary
tree are 2 nodes.

j. The maximum number of nodes in this tree if it is a perfect binary tree are 15 nodes.

k. The number of nodes that needs to be added to this tree to be called a perfect binary tree are 6
nodes.

Complexity of operations (Big O notation):


Array (unsorted) Linked List Array (sorted) Balanced BST
Search O(n) O(n) O(log n) O(log n)
Insertion O(1) O(1) O(n) O(log n)
Deletion O(n) O(n) O(n) O(log n)
Binary Search Tree:
1. (a) Given a sequence of numbers 50, 6, 4, 19, 4, 10, 5, 9, 17, 35, 67, 49, 31

(b) Two trees illustration as a result after the removal of 50 from tree in (a)
(c) Trace the breadth-first traversal (top down left to right) using queue for the binary tree
in (a)

Iteration Queue Print


1 50
2 6 67 50
3 67 4 19 6
4 4 19 67
5 19 4 4
6 4 10 35 19
7 10 35 5 4
8 35 5 9 17 10
9 5 9 17 31 49 35
10 9 17 31 49 5
11 17 31 49 9
12 31 49 17
13 49 31
14 49
Breadth First traversal of binary tree is -

50 6 67 4 19 4 10 35 5 9 17 31 49
(d) Trace the depth-first traversal using queue for binary tree in (a)

Preorder traversal of binary tree is - 50 6 4 4 5 19 10 9 17 35 31 49 67

Inorder traversal of binary tree is - 4 4 5 6 9 10 17 19 31 35 49 50 67

Postorder traversal of binary tree is - 5 4 4 9 17 10 31 49 35 19 6 67 50


Heap (John William Algorithm – top-down, Floyd Algorithm – bottom-up):
(e) A heap and its array using top-down approach using similar sequence number as above:
Given the elements 10 4 13 6 10 2 5 9 , a heap and its related array using the top-down approach
method:
(f) A heap and its array using bottom-up approach using similar sequence number as above:

You might also like