Graph
Graph
Graph
Code Implementation
Task 1
#include <stdio.h>
#include <stdlib.h>
inOrder(root->left);
printf("%d ", root->data);
inOrder(root->right);
}
// Post-order traversal
void postOrder(struct Node* root) {
if (root == NULL)
return;
postOrder(root->left);
postOrder(root->right);
printf("%d ", root->data);
}
// Function to find the height of the binary tree
int findHeight(struct Node* node) {
if (node == NULL)
return 0;
int main() {
int arr[] = { 1, 2, 3, 4, 5, 6, 7 };
int n = sizeof(arr) / sizeof(arr[0]);
#include <stdlib.h>
int data;
} Node;
newNode->data = data;
return newNode;
if (root == NULL) {
*height = 0;
return 0;
// Calculate the diameter: max of (left diameter, right diameter, height of left + right + 1)
return (leftHeight + rightHeight + 1 > leftDiameter && leftHeight + rightHeight + 1 > rightDiameter)
int height = 0;
int main() {
root = createNode(10);
root->left = createNode(5);
root->right = createNode(20);
root->left->left = createNode(3);
root->left->right = createNode(8);
root->right->right = createNode(25);
while (1) {
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
if (isBalanced(root))
else
break;
case 2:
if (isBST(root))
else
break;
case 3:
break;
case 4:
exit(0);
default:
return 0;