67% found this document useful (6 votes)
6K views16 pages

"Binary Search Tree": A Micro-Project Report On

This document contains a micro-project report on implementing a binary search tree using C programming language. It discusses the rationale, aim, methodology, and outputs of the project. The project was undertaken by 3 students to learn and apply basic operations on arrays and different searching techniques by developing a program to construct a binary search tree, perform insertion, deletion, and traversal operations on the tree. The report includes the source code, sample outputs, and screenshots of the binary search tree program implemented in C.

Uploaded by

Madhura Pansare
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
67% found this document useful (6 votes)
6K views16 pages

"Binary Search Tree": A Micro-Project Report On

This document contains a micro-project report on implementing a binary search tree using C programming language. It discusses the rationale, aim, methodology, and outputs of the project. The project was undertaken by 3 students to learn and apply basic operations on arrays and different searching techniques by developing a program to construct a binary search tree, perform insertion, deletion, and traversal operations on the tree. The report includes the source code, sample outputs, and screenshots of the binary search tree program implemented in C.

Uploaded by

Madhura Pansare
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/ 16

A

Micro-Project Report
On
“Binary Search Tree”

Submitted By
Atharva Thakare (40)
Yash Dhumal (43)
Atharva Javnajal (45)

Under Guidance Of
Ms. Sheetal. K. Kawale

Diploma Course in Computer Technology


(As per directives of I Scheme, MSBTE)

Sinhgad Technical Education Society’s


SOU. VENUTAI CHAVAN POLYTECHNIC, PUNE – 411046
The Academic Year 2020 – 2021
MAHARASHTRA STATE BOARD OF

TECHNICAL EDUCATION

Certificate
This is to certify that Mr. Atharva Thakare Roll No. 40 of Semester III of Diploma in

Computer Technology of Institute STES’s Sou. Venutai Chavan Polytechnic (Code: 0040)

has completed the Micro Project satisfactorily in Subject Data Structures using ‘C’ (22317)

for the academic year 2020 – 2021 as prescribed in the curriculum.

Program Code: CM

Course Code: CM/3/I

Place: Pune Enrollment No: 1900400169

Date: _________________ Exam. Seat No: __________

Subject Teacher HOD stamp/signature Institute stamp


MAHARASHTRA STATE BOARD OF

TECHNICAL EDUCATION

Certificate
This is to certify that Mr. Yash Dhumal Roll No. 43 of Semester III of Diploma in Computer

Technology of Institute STES’s Sou. Venutai Chavan Polytechnic (Code: 0040) has

completed the Micro Project satisfactorily in Subject Data Structures using ‘C’ (22317) for

the academic year 2020 – 2021 as prescribed in the curriculum.

Program Code: CM

Course Code: CM/3/I

Place: Pune Enrollment No: 1900400219

Date: _________________ Exam. Seat No: __________

Subject Teacher HOD stamp/signature Institute stamp


MAHARASHTRA STATE BOARD OF

TECHNICAL EDUCATION

Certificate
This is to certify that Mr. Atharva Javanjal Roll No. 45 of Semester III of Diploma in

Computer Technology of Institute STES’s Sou. Venutai Chavan Polytechnic (Code: 0040)

has completed the Micro Project satisfactorily in Subject Data Structures using ‘C’ (22317)

for the academic year 2020 – 2021 as prescribed in the curriculum.

Program Code: CM

Course Code: CM/3/I

Place: Pune Enrollment No: 1900400203

Date: _________________ Exam. Seat No: __________

Subject Teacher HOD stamp/signature Institute stamp


Data Structures using ‘C’-22317 Binary Search Tree

Annexure – I

Micro-Project Proposal

Binary Search Tree

1.0 Aim of the Micro – Project:


This Micro-Project aims at developing a ‘C’ program for Binary Search Tree using tree
data structure.

2.0 Intended Course Outcomes:


a. Apply different searching and sorting techniques.

b. Perform basic operations on arrays.

3.0 Proposed Methodology:


This Micro-Project aims at developing a ‘C’ program for Binary Search Tree.
I. Study all the concepts of Data Structures
II. Identify the requirements of project
III. Design the structure of project
IV. Debug code and eliminate errors occurred during compilation and execution
V. Test the working of project
VI. Prepare the final project

4.0 Action Plan:


Sr. Details of Activity Planned Planned Name of
No Start Date Finish Date Responsible Team
Member
01 Identify the requirements of 05/08/2020 19/09/2020 Yash Dhumal
the project
02 Design the structure of the 19/09/2020 30/09/2020 Atharva Thakare
project
03 Develop a program using Data 02/10/2020 19/10/2020 Atharva Javanjal
Structures in ‘C’
04 Debug code and eliminate 21/10/2020 31/10/2020 Atharva Javanjal
errors occurred during
compilation and execution
05 Test the project 06/11/2020 16/11/2020 Atharva Thakare
06 Prepare the final report 20/11/2020 30/11/2020 Yash Dhumal

Department of Computer Technology Academic Year 2020-2021 1


Data Structures using ‘C’-22317 Binary Search Tree

5.0 Resources Required:


Sr. No Resources Required Specifications
01 Computer System Pentium Intel CORE i5
02 Operating System Windows 10, 64 Bit Operating System
03 ‘C’ Compiler Turbo C Version 3.0

6.0 Team Members:


Sr. No Roll. No Name of Student
01 40 Atharva Thakare
02 43 Yash Dhumal
03 45 Atharva Javanjal

Department of Computer Technology Academic Year 2020-2021 2


Data Structures using ‘C’-22317 Binary Search Tree

Annexure – II
Micro-Project Report
Binary Search Tree

1.0 Rationale:
A Binary Search Tree (BST), also called an ordered or sorted binary tree, is a rooted binary
tree whose internal nodes each store a key greater than all the keys in the node's left subtree
and less than those in its right subtree. A binary tree is a type of data structure for storing
data such as numbers in an organized way. Binary search trees allow binary search for fast
lookup, addition and removal of data items, and can be used to implement dynamic
sets and lookup tables.

2.0 Aim of the Micro – Project:


This Micro-Project aims at developing a ‘C’ program for Binary Search Tree using tree
data structure.

3.0 Course Outcomes Addressed:


a. Perform basic operations on arrays.
b. Apply different searching and sorting techniques.

4.0 Literature Review:


Data Structure is a logical and mathematical model of storing and organizing data in a
particular way in a computer. The methods and ways of data structures are widely used in
industries. Binary search is an efficient algorithm for finding an item from a sorted list of
items. It works by repeatedly dividing in half the portion of the list that could contain the
item, until you've narrowed down the possible locations to just one.

5.0 Actual Methodology Followed:


I. Study all the concepts of Data Structures
II. Identify the requirements of project
III. Design the structure of project
IV. Debug code and eliminate errors occurred during compilation and execution
V. Test the working of project.
VI. Prepare the final project

6.0 Resources Required:


Sr. No Resources Required Specifications
01 Computer System Pentium Intel CORE i5
02 Operating System Windows 10, 64 Bit Operating System
03 ‘C’ Compiler Turbo C Version 3.0

Department of Computer Technology Academic Year 2020-2021 3


Data Structures using ‘C’-22317 Binary Search Tree

7.0 Outputs of Micro – Project:

7.1 Source Code:

/*
* C Program to Construct a Binary Search Tree and perform deletion, inorder
traversal on it
*/
#include <stdio.h>
#include <stdlib.h>

struct btnode
{
int value;
struct btnode *l;
struct btnode *r;
}*root = NULL, *temp = NULL, *t2, *t1;

void delete1();
void insert();
void delete();
void inorder(struct btnode *t);
void create();
void search(struct btnode *t);
void preorder(struct btnode *t);
void postorder(struct btnode *t);
void search1(struct btnode *t,int data);
int smallest(struct btnode *t);
int largest(struct btnode *t);

int flag = 1;

void main()
{
int ch;

printf("\nOPERATIONS ---");
printf("\n1 - Insert an element into tree\n");
printf("2 - Delete an element from the tree\n");
printf("3 - Inorder Traversal\n");
printf("4 - Preorder Traversal\n");
printf("5 - Postorder Traversal\n");
printf("6 - Exit\n");
while(1)

Department of Computer Technology Academic Year 2020-2021 4


Data Structures using ‘C’-22317 Binary Search Tree

{
printf("\nEnter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
inorder(root);
break;
case 4:
preorder(root);
break;
case 5:
postorder(root);
break;
case 6:
exit(0);
default :
printf("Wrong choice, Please enter correct choice ");
break;
}
}
}

/* To insert a node in the tree */


void insert()
{
create();
if (root == NULL)
root = temp;
else
search(root);
}

/* To create a node */
void create()
{
int data;

printf("Enter data of node to be inserted : ");

Department of Computer Technology Academic Year 2020-2021 5


Data Structures using ‘C’-22317 Binary Search Tree

scanf("%d", &data);
temp = (struct btnode *)malloc(1*sizeof(struct btnode));
temp->value = data;
temp->l = temp->r = NULL;
}

/* Function to search the appropriate position to insert the new node */


void search(struct btnode *t)
{
if ((temp->value > t->value) && (t->r != NULL)) /* value more than root
node value insert at right */
search(t->r);
else if ((temp->value > t->value) && (t->r == NULL))
t->r = temp;
else if ((temp->value < t->value) && (t->l != NULL)) /* value less than root
node value insert at left */
search(t->l);
else if ((temp->value < t->value) && (t->l == NULL))
t->l = temp;
}

/* recursive function to perform inorder traversal of tree */


void inorder(struct btnode *t)
{
if (root == NULL)
{
printf("No elements in a tree to display");
return;
}
if (t->l != NULL)
inorder(t->l);
printf("%d -> ", t->value);
if (t->r != NULL)
inorder(t->r);
}

/* To check for the deleted node */


void delete()
{
int data;

if (root == NULL)
{
printf("No elements in a tree to delete");
return;

Department of Computer Technology Academic Year 2020-2021 6


Data Structures using ‘C’-22317 Binary Search Tree

}
printf("Enter the data to be deleted : ");
scanf("%d", &data);
t1 = root;
t2 = root;
search1(root, data);
}

/* To find the preorder traversal */


void preorder(struct btnode *t)
{
if (root == NULL)
{
printf("No elements in a tree to display");
return;
}
printf("%d -> ", t->value);
if (t->l != NULL)
preorder(t->l);
if (t->r != NULL)
preorder(t->r);
}

/* To find the postorder traversal */


void postorder(struct btnode *t)
{
if (root == NULL)
{
printf("No elements in a tree to display ");
return;
}
if (t->l != NULL)
postorder(t->l);
if (t->r != NULL)
postorder(t->r);
printf("%d -> ", t->value);
}

/* Search for the appropriate position to insert the new node */


void search1(struct btnode *t, int data)
{
if ((data>t->value))
{
t1 = t;
search1(t->r, data);

Department of Computer Technology Academic Year 2020-2021 7


Data Structures using ‘C’-22317 Binary Search Tree

}
else if ((data < t->value))
{
t1 = t;
search1(t->l, data);
}
else if ((data==t->value))
{
delete1(t);
}
}

/* To delete a node */
void delete1(struct btnode *t)
{
int k;

/* To delete leaf node */


if ((t->l == NULL) && (t->r == NULL))
{
if (t1->l == t)
{
t1->l = NULL;
}
else
{
t1->r = NULL;
}
t = NULL;
free(t);
return;
}

/* To delete node having one left hand child */


else if ((t->r == NULL))
{
if (t1 == t)
{
root = t->l;
t1 = root;
}
else if (t1->l == t)
{
t1->l = t->l;

Department of Computer Technology Academic Year 2020-2021 8


Data Structures using ‘C’-22317 Binary Search Tree

}
else
{
t1->r = t->l;
}
t = NULL;
free(t);
return;
}

/* To delete node having right hand child */


else if (t->l == NULL)
{
if (t1 == t)
{
root = t->r;
t1 = root;
}
else if (t1->r == t)
t1->r = t->r;
else
t1->l = t->r;
t == NULL;
free(t);
return;
}

/* To delete node having two child */


else if ((t->l != NULL) && (t->r != NULL))
{
t2 = root;
if (t->r != NULL)
{
k = smallest(t->r);
flag = 1;
}
else
{
k =largest(t->l);
flag = 2;
}
search1(root, k);
t->value = k;
}

Department of Computer Technology Academic Year 2020-2021 9


Data Structures using ‘C’-22317 Binary Search Tree

/* To find the smallest element in the right sub tree */


int smallest(struct btnode *t)
{
t2 = t;
if (t->l != NULL)
{
t2 = t;
return(smallest(t->l));
}
else
return (t->value);
}

/* To find the largest element in the left sub tree */


int largest(struct btnode *t)
{
if (t->r != NULL)
{
t2 = t;
return(largest(t->r));
}
else
return(t->value);
}

Department of Computer Technology Academic Year 2020-2021 10


Data Structures using ‘C’-22317 Binary Search Tree

7.2 Output:

Department of Computer Technology Academic Year 2020-2021 11


Data Structures using ‘C’-22317 Binary Search Tree

8.0 Skills Developed:


1 During developing the Micro-Project, we learnt many practically applied
concepts of data structures and theory as well.
2 We learned to develop a program using various data structures.
3 We also learned how to develop, compile and execute a program using data
structures.

9.0 Applications of this Project:


1. Used to efficiently store data in sorted form in order to access and search stored
elements quickly.
2. They can be used to represent arithmetic expressions.
3. BST used in Unix kernels for managing a set of virtual memory areas.

10.0 Conclusion:
Thus, we developed a ‘Binary Search Tree’ using Data Structures.

Department of Computer Technology Academic Year 2020-2021 12

You might also like