DSA Lab Assignment 10 D0
DSA Lab Assignment 10 D0
Binary Tree
Batch – D0
(March, 2024)
3. Create another directory named “LAB number” within the roll number directory.
4. Within the “LAB_number” directory place your files. Follow the naming convention as
“RollNumber_PracticeQuestionNumber.c” (for example 23200100_p1.c) for practice
questions. Follow the naming convention as “RollNumber_TestQuestionNumber.c” (for
example 23200100 test1.c) for test questions.
2. Ensure your assigned TA has checked your practice question and test question solutions
and you are evaluated for the same.
[6 Points]
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
Test cases:
int main() {
// Test case 1: Valid BST
struct TreeNode* root1 = createNode(5);
root1->left = createNode(3);
root1->right = createNode(7);
root1->left->left = createNode(2);
root1->left->right = createNode(4);
printf("Test Case 1: %s\n", isBST(root1) ? "Valid BST" : "Not a
BST");
return 0;
}
2. Write a C program to implement a binary search tree (BST). Include functions for insertion,
deletion, and searching for a key in the BST. Use in-order traversal to print the elements of
the tree.
[6 Points]
#include <stdio.h>
#include <stdlib.h>
Test cases:
int main() {
struct TreeNode* root = NULL;
return 0;
}
3. Implement a function in C to find the height of a binary tree. The height of a binary tree is the
maximum distance from the root node to any leaf node. Test your function by creating multiple bi-
nary trees with varying structures and sizes, and verify that the height is calculated correctly for each
tree.
[8 Points]
#include <stdio.h>
#include <stdlib.h>
Test cases:
int main() {
struct TreeNode* root1 = createNode(1);
root1->left = createNode(2);
root1->right = createNode(3);
root1->left->left = createNode(4);
root1->left->right = createNode(5);
root1->right->left = createNode(6);
root1->right->right = createNode(7);
printf("Height of Binary Tree 1: %d\n", height(root1));
return 0;
}