DS Lab 11 - Binary Search Trees IterativeTraversals
DS Lab 11 - Binary Search Trees IterativeTraversals
Lab 11
Binary Search Trees Iterative Traversals
Table of Contents
1. Introduction 128
1.1 Iterative Traversals in Binary Search Tree 128
1.2 Relevant Lecture Readings 129
8. Evaluation Task (Unseen) [Expected time = 60 mins for two tasks] 133
1. Introduction
This lab will introduce concept of generic binary trees, how they can be used to store
information. Further this lab will provide information about concept of performing different
traversal operations like pre order, in order and post order on binary trees.
When we need to insert, update or lookup items in a binary tree we need to perform
traversal of tree. Traversal of a binary tree means visiting each node of binary tree. Traversal
must start from the root node, for each node we have two options to traverse
These choices lead to three different traversals of a binary tree—inorder, preorder, and post
order.
Pre order Traversal: In a pre order traversal, the binary tree is traversed as follows:
Post order Traversal: In a post order traversal, the binary tree is traversed as follows:
For a binary tree shown in figure 2 following are results of pre order, in order and post
order traversals.
In order sequence: B D A C
Pre order sequence: A B D C
Post order sequence: D B C A
4. Concept Map
This concept map will help students to understand the main concepts of topic covered in
lab.
There are three types of traversal of binary trees. Post order, in order and pre order
traversals. We will discuss code segments to be used for traversal of a binary tree which is
represented by an array.
After studying the introduction and concept map sections you should be ready to provide
the solution of following problems. Design the solutions of the problems in C++ and
bring your code to lab so that lab instructor should assess and grade it.
Write a program of general binary tree using array. Elements of this array will be objects
of person class. Attributes of Book (privately defined) are
1. ISBN (String) (e.g. 1235-123-1)
2. author_name (string)
3. Edition (int)
Book class contains member functions (publicly defined): constructor, input and output
functions. You are required to define insert, delete and search functions for this binary
tree. Insert function should allow insertion of object of book class at appropriate location
in general binary tree, delete should delete an object of book class from tree whose ISBN
is specified by user. Search function should search an object of book class from this tree
whose ISBN is specified by user. You are required to implement pre order, in order and
post order traversal functions for this binary tree.
5.3.1 Task-1
Distinguish between recursive and iterative traversal in binary trees.
6.1 Tools
Following screens in figure 3 represent the implementation of binary tree using array in
Microsoft Visual Studio 2008 for in order traversal. You are required to type, debug and execute
this program in Microsoft Visual Studio 2008.
7. Practice Tasks
This section will provide information about the practice tasks which are required to be performed
in lab session. Design solutions of problems discussed in each task and place solution code in a
folder specified by your lab instructor.
After completing this lab, student will be able to understand and develop programs related to
operate general binary trees using linked list in C++ using Microsoft Visual Studio 2008
environment. Further students will be able to implement iterative traversal operations like pre
order, in order and post order traversal on general binary trees in C++.
The lab instructor will give you unseen task depending upon the progress of the class.
9. Evaluation criteria
The evaluation criteria for this lab will be based on the completion of the following tasks. Each
task is assigned the marks percentage which will be evaluated by the instructor in the lab whether
the student has finished the complete/partial task(s).