Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Binary search tree programs

Rating
-
Sold
-
Pages
3
Grade
A+
Uploaded on
23-02-2026
Written in
2025/2026

Binary search trees which was one of the crucial and important topic in dsa this pdf covers the bst programs which are very useful for the exam preparation

Institution
Course

Content preview

Binary Tree & BST Lab Record Programs


Q1A: Binary tree implementation using recursion (BST Insert)

struct node{ int data; struct node *left,*right; };

struct node* create(int val){
struct node* n=(struct node*)malloc(sizeof(struct node));
n->data=val; n->left=n->right=NULL; return n;
}

struct node* insert(struct node* root,int key){
if(root==NULL) return create(key);
if(key<root->data) root->left=insert(root->left,key);
else root->right=insert(root->right,key);
return root;
}




Q1B: Insert nodes level wise

struct node* insertLevel(struct node* root,int val){
if(root==NULL) return create(val);
struct node* q[100]; int f=0,r=0;
q[r++]=root;
while(f<r){
struct node* t=q[f++];
if(t->left==NULL){ t->left=create(val); return root;}
else q[r++]=t->left;
if(t->right==NULL){ t->right=create(val); return root;}
else q[r++]=t->right;
}
}




Q2A: Count number of non-leaf nodes

int countNonLeaf(struct node* root){
if(root==NULL || (root->left==NULL && root->right==NULL))
return 0;
return 1 + countNonLeaf(root->left) + countNonLeaf(root->right);
}




Q2B: BST operations (search, min, max, height)

struct node* search(struct node* root,int key){
if(root==NULL || root->data==key) return root;
if(key<root->data) return search(root->left,key);
else return search(root->right,key);
}

int findMin(struct node* root){
while(root->left) root=root->left;
return root->data;
}

int findMax(struct node* root){

Written for

Institution
Course

Document information

Uploaded on
February 23, 2026
Number of pages
3
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$51.39
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
akulasundaramsai789

Get to know the seller

Seller avatar
akulasundaramsai789 Srm university ap
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 months
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions