0% found this document useful (0 votes)
59 views

DSP PR 20

This document outlines a practical lab experiment on implementing binary search trees (BSTs) in Python. The objectives are to apply operations on BSTs to solve problems. Students will create and manipulate a BST by inserting, traversing, and deleting nodes. The document provides background on BST operations like search, insert, preorder, inorder and postorder traversal, and deletion. It includes expected outcomes, skills developed, prerequisites, and equipment required for the lab. Source code for a BST program is not included.

Uploaded by

Dhvanil Tanti
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)
59 views

DSP PR 20

This document outlines a practical lab experiment on implementing binary search trees (BSTs) in Python. The objectives are to apply operations on BSTs to solve problems. Students will create and manipulate a BST by inserting, traversing, and deleting nodes. The document provides background on BST operations like search, insert, preorder, inorder and postorder traversal, and deletion. It includes expected outcomes, skills developed, prerequisites, and equipment required for the lab. Source code for a BST program is not included.

Uploaded by

Dhvanil Tanti
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/ 12

Data Structure with Python (4331601)

Date: ……………

Practical No.20: Write a menu driven program to perform following operation on Binary Search
Tree:
a. Create a BST.
b. Insert an element in BST.
c. Pre-order traversal of BST.
d. In-order traversal of BST.
e. Post-order traversal of BST.
f. Delete an element from BST.

A. Objective:

Apply operation on Binary Search Tree to solve particular problem.

B. Expected Program Outcomes (POs)


1. Basic and Discipline specific knowledge: Be able to apply engineering knowledge
of computing appropriate to the problem
2. Problem Analysis: Identify and analyse well-defined engineering problems using
codified standard methods.
3. Design/ development of solutions: Be able to design, implement, and evaluate
a computer-based system, process, component, or program to meet the desired
needs
4. Engineering Tools, Experimentation and Testing: Be able to use and apply
current technical concepts and best practices in information technologies
5. Project Management: Use engineering management principles individually, as a
team member or a leader to manage projects and effectively communicate about
well-defined engineering activities.
6. Life-long learning: Ability to analyse individual needs and engage in updating in
the context of technological changes in field of engineering. C. Expected Skills
to be developed based on competency:
This practical is expected to develop the following skills for the industryidentified
competency:

1. Problem solving skill using operation on Binary Search Tree.

D. Expected Course Outcomes(COs)


CO5: Implement nonlinear data structures like trees.

E. Practical Outcome(PRO)
Write a program to implement different operations on Binary Search Tree.

136 | Page
226120316058
Data Structure with Python (4331601)

F. Expected Affective domain Outcome(ADOs)

1. Handle computer systems carefully with safety and necessary precaution


2. Turn off systems after completion of practical lab to save power
G. Prerequisite Theory:
Basic Operations on Binary Search Tree:
Following are the basic operations of a tree −
Search − Searches an element in a tree. Insert
− Inserts an element in a tree.
Pre-order Traversal − Traverses a tree in a pre-order manner.
In-order Traversal − Traverses a tree in an in-order manner.
Post-order Traversal − Traverses a tree in a post-order manner.
Delete - Delete an element from BST

Search Operation:
Whenever an element is to be searched, start searching from the root node. Then if
the data is less than the key value, search for the element in the left subtree.
Otherwise, search for the element in the right subtree. Follow the same algorithm for
each node.
The basic steps to perform search operation:
• Check whether the tree is empty or not If the tree is empty, search is not
possible
• Otherwise, first search the root of the tree.
• If the key does not match with the value in the root, search its subtrees. If
the value of the key is less than the root value, search the left subtree If the
value of the key is greater than the root value, search the right subtree.
• If the key is not found in the tree, return unsuccessful search.
Insert Operation:
Whenever an element is to be inserted, first locate its proper location. Start searching
from the root node, then if the data is less than the key value, search for the empty
location in the left subtree and insert the data. Otherwise, search for the empty
location in the right subtree and insert the data.
The basic steps to perform insert operation:
• If the tree is empty, insert the first element as the root node of the tree. The
following elements are added as the leaf nodes.
• If an element is less than the root value, it is added into the left subtree as a
leaf node.

137 | Page
226120316058
Data Structure with Python (4331601)

• If an element is greater than the root value, it is added into the right subtree
as a leaf node.
• The final leaf nodes of the tree point to NULL values as their child nodes.

Inorder Traversal:
The inorder traversal operation in a Binary Search Tree visits all its nodes in the
following order:

• Traverse the left subtree, recursively


• Then, traverse the root node
• Traverse the right subtree, recursively Preorder Traversal:
The preorder traversal operation in a Binary Search Tree visits all its nodes. However,
the root node in it is first printed, followed by its left subtree and then its right subtree.

• Traverse the root node first.


• Then traverse the left subtree, recursively
• Later, traverse the right subtree, recursively Postorder Traversal:
Like the other traversals, postorder traversal also visits all the nodes in a Binary
Search Tree and displays them. However, the left subtree is printed first, followed by
the right subtree and lastly, the root node.

• Traverse the left subtree, recursively Traverse the right subtree, recursively.
• Then, traverse the root node Delete Operation:
The basic steps to perform delete operation:
• Create a recursive function which returns the correct node that will be in the
position.
• If the root is NULL, then return root (Base case)
• If the key is less than the root’s value, then set root->left = deleteNode (root-
>left, key)
• If the key is greater than the root’s value, then set root->right = deleteNode
(root->right, key)
• Else check o If the root is a leaf node then return null o Else if it has only the
left child, then return the left child o Else if it has only the right child, then
return the right child o Otherwise, set the value of root as of its inorder
successor and recur to delete the node with the value of the inorder successor.

H. Program Logic-Flow chart:


Example: To implement different operations on Binary Search Tree.

138 | Page
226120316058
Data Structure with Python (4331601)

Following is a pictorial representation of BST −

We observe that the root node key (27) has all less-valued keys on the left sub-tree
and the higher valued keys on the right sub-tree.

I. Resources/Equipment Required
Sr.No. Instrument/Equipment Specification
Quanti
/Components/Trainer kit
ty

1 Computer system with 1


operating system

2. PYTHON IDE(any) 1

J. Safety and necessary Precautions followed

1. Turn off power switch only after computer is shut down.


2. Do not plug out any computer cables

K. Source code:

_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________

139 | Page
226120316058
Data Structure with Python (4331601)

_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________

140 | Page
226120316058
Data Structure with Python (4331601)

_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________

141 | Page
226120316058
Data Structure with Python (4331601)

_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________

142 | Page
226120316058
Data Structure with Python (4331601)

_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________

143 | Page
226120316058
Data Structure with Python (4331601)

OUTPUT :

144 | Page
226120316058
Data Structure with Python (4331601)

L. Practical related Quiz.


1. The task is to print the elements in inorder, preorder, and postorder traversal of the
Binary Search Tree.

2. Draw the binary search tree that is created if the following numbers are inserted in
the tree in the given order.
12 15 3 35 21 42 14

145 | Page
226120316058
Data Structure with Python (4331601)

N. References / Suggestions ( lab manual designer should give)

1. Data structures and algorithms in python by M.Goodrich


2. https://www.w3resource.com/python-exercises

O. Assessment-Rubrics
Agenda Rubric Level of Achievement
Paramet
ers Excellent Very Good Good (3) Average Poor (1)
(5) (4) (2)

Problem Understa Able to Able to Able to Able to Able to


Understandin nd the define & identify all identify identify identify
g problem, explain the almost all some very few
identify concept problem/Ta problem/Ta problem/Ta problem/
the properly sk and able sk and able sk and able Task and
concept and able to to apply all to apply to apply able to
for identify concept in almost all some apply very
solution, application problem/Ta concept in concept in few
explain of concept. sk properly problem/Ta problem/Ta concept in
concept with 6 sk with few sk problem/
and exceptions. Task.
+very few
ab
help.
le
to
identify
applicatio
n of
concept.
Design Concept Properly Properly Properly Partially Partially
Methodolog ual Followed & Followed & followed & Followed followed
y design, Properly Justified Not and and Not
Division Justified partly Justified Partially justified
of Justified
problem
into
modules,
Selection
of design
framewo
rk

146 | Page
226120316058
Data Structure with Python (4331601)

Implementat Design, Properly Properly Properly Partially Partially


ion Algorith Followed & Followed & followed & Followed followed
m, Properly implement Not and and Not
Coding implement ed partly implement Partially implement
ed ed implement ed
ed

Demonstrati Executio Properly Properly Partially Partially Partially


on n of demonstra demonstra demonstra demonstra demonstra
source ted & ted & ted & ted and ted and no
code, Properly Partially Justified Partially justificatio
Working Justified Justified Justified n
and output output
results

Viva Handling Answered Answered Answered Answered Answered


Question all 80% 60% 40% 20%
s questions questions questions questions questions
with
proper
justificatio
n

Sign with Date

147 | Page
226120316058

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy