0% found this document useful (0 votes)
14 views3 pages

21bca1953 DS (3.2)

Uploaded by

tomalexender1223
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)
14 views3 pages

21bca1953 DS (3.2)

Uploaded by

tomalexender1223
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/ 3

Experiment 3.

Student Name: Rahul Saini UID: 21BCA1953


Branch: BCA Section/Group: 5B
Semester: 3RD Date of Performance: 09-11-2022
Subject Name: DATA STRUCTURES LAB
Subject Code: 21CAP-214_PH21BCA-5_B

1. Aim/Overview of the practical: Binary Search.


2. Task to be done: How to create Binary Search Tree.
3. Concept used: Binary Search.
4. Steps/Commands involved to perform practical:

#include <iostream>
using namespace std;

struct node {
int key;
struct node *left, *right;
};
struct node *newNode(int item) {
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
void inorder(struct node *root) {
if (root != NULL) {
inorder(root->left);
cout << root->key << " -> ";
inorder(root->right);
}
}
struct node *insert(struct node *node, int key) {
if (node == NULL) return newNode(key);
if (key < node->key)
node->left = insert(node->left, key);
else
node->right = insert(node->right, key);

return node;
}
struct node *minValueNode(struct node *node) {
struct node *current = node;
while (current && current->left != NULL)
current = current->left;

return current;
}
struct node *deleteNode(struct node *root, int key) {
if (root == NULL) return root;
if (key < root->key)
root->left = deleteNode(root->left, key);
else if (key > root->key)
root->right = deleteNode(root->right, key);
else {
if (root->left == NULL) {
struct node *temp = root->right;
free(root);
return temp;
} else if (root->right == NULL) {
struct node *temp = root->left;
free(root);
return temp;
}
struct node *temp = minValueNode(root->right);
root->key = temp->key;
root->right = deleteNode(root->right, temp->key);
}
return root;
}
int main() {
struct node *root = NULL;
root = insert(root, 8);
root = insert(root, 3);
root = insert(root, 1);
root = insert(root, 6);
root = insert(root, 7);
root = insert(root, 10);
root = insert(root, 14);
root = insert(root, 4);
cout << "Inorder traversal: ";
inorder(root);

cout << "\nAfter deleting 10\n";


root = deleteNode(root, 10);
cout << "Inorder traversal: ";
inorder(root);
}
5. Result/Output/Writing Summary:

Learning outcomes (What I have learnt):

1. Learnt Binary Search

2. Learnt if statement.

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Worksheet 20
2. Demonstration/Performance / 10
Quiz/Viva

Worksheet Rubrics:
Understanding of Experiment 10% of total grade that is 2 marks

Command Description for all concepts covered in experiment 30% of total grade that is 6marks

Steps Involved in question 40% of total grade that is 8 marks

Writing Output/Screenshot 20% of total grade that is 4 marks

You might also like