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

DS Lab 8 Manual

This document provides instructions for Lab #7 on data structures involving binary search trees (BSTs). Students are asked to write C++ code for various BST functions: [1] Creating and inserting nodes into an empty BST; [2] Counting internal nodes of a BST; [3] Searching for a node by key; [4] Removing leaf nodes from a BST; [5] Finding the closest element to a given key; [6] Iterative and recursive search; [7] Various tree traversals on a sample pre-order traversal; [8] Finding the minimum value in a BST; [9] Creating a balanced BST from a sorted array. Students are instructed to comment their code, indent

Uploaded by

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

DS Lab 8 Manual

This document provides instructions for Lab #7 on data structures involving binary search trees (BSTs). Students are asked to write C++ code for various BST functions: [1] Creating and inserting nodes into an empty BST; [2] Counting internal nodes of a BST; [3] Searching for a node by key; [4] Removing leaf nodes from a BST; [5] Finding the closest element to a given key; [6] Iterative and recursive search; [7] Various tree traversals on a sample pre-order traversal; [8] Finding the minimum value in a BST; [9] Creating a balanced BST from a sorted array. Students are instructed to comment their code, indent

Uploaded by

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

National University

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

CL-210
Data Structures
Lab # 7
Objectives:
1. Binary Search Tree
a) Insertion
b) Deletion
c) Traversal

Note: Carefully read the following instructions (Each instruction contains a


weightage)

1. There must be a block of comments at start of every question's code; the block should contain
brief description about functionality of code
2. Proper indentation of code is essential
3. Variable name should be meaningful
4. Make a Microsoft Word file and past all of your C++ code with screenshot of outputs in MS
word.
5. First think about statement problems and then write/draw your logic on copy.
6. After copy pencil work, code the problem statement on MS Studio C++ compiler.
7. At the end when you done your today lab tasks, attached only MS word file and make your
submission on Google Classroom.
8. Late and email submission is not accepted. All tasks must be submitted during the lab time.

Page 1
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Problem 1:

Write a code for the following functions in a Binary Search Tree.


a) Creation of BST.
b) Insertion of the following node values in BST
a. 9,14,19,12,23,17,50,72,54,76,67 (Ensure that the tree is a BST after
insertion)
c) A function to count the internal nodes in the BST (HINT: internal nodes are nodes
which are not leaves)
d) Search (node, key) where key is to be inserted by user.
e) Remove all leaf nodes from BST.
f) Find the closest element in a BST where the closest element is closest in terms of
numeric value to the given key.
g) Iterative search (root, key) where the user search a key element non-recursively.
h) Construct the BST on the following pre order traversal.
a. {10, 5, 1, 7, 40, 50}
b. Write a function to check if the above mentioned insertion results in a BST
or not i.e. check if the above mentioned tree is BST or not.
c. Write a recursive function for the following.
i. In-order traversal
ii. Pre-order traversal
iii. Post-order traversal
i) Write a function to find minimum value in a BST.
j) Given a sorted array. Write a function that creates a Balanced Binary Search Tree
using array elements.
k)

Page 2

You might also like