1. Define Tree

A Tree is a non-linear data structure consisting of nodes connected by edges with a root node and hierarchical relationships.


2. What is a Binary Tree?

A Binary Tree is a tree in which each node has at most two children (left and right).


3. Define Binary Search Tree (BST)

A Binary Search Tree (BST) is a binary tree where:

  • Left subtree contains values less than root
  • Right subtree contains values greater than root

4. List types of Tree Traversals
  • Inorder (Left, Root, Right)
  • Preorder (Root, Left, Right)
  • Postorder (Left, Right, Root)

5. What is AVL Tree?

An AVL Tree is a self-balancing binary search tree where the balance factor is -1, 0, or +1.


6. Define Heap

A Heap is a complete binary tree that satisfies the heap property (min or max).


7. What is Minimum Heap?

A Min Heap is a heap where the parent node is smaller than its children.


8. What is Maximum Heap?

A Max Heap is a heap where the parent node is greater than its children.


9. Define Height of a Tree

The height of a tree is the number of edges on the longest path from the root to a leaf node.


10. What is Threaded Binary Tree?

A Threaded Binary Tree is a binary tree where NULL pointers are replaced with links to inorder predecessor or successor.

Q1. Explain Tree Terminologies with Diagram.

A tree is a non-linear hierarchical structure made up of nodes and edges, and the tree-related topics in your notes include tree traversal, BST, AVL tree, threaded binary tree, and applications of trees.

🔷 TREE

A tree is a collection of nodes connected by edges in a hierarchical manner. It starts from a root node and extends into subtrees.

📌 TREE TERMINOLOGIES
1. Node

A node is an element of a tree that stores data.

2. Root

The topmost node of the tree. It has no parent.

3. Edge

A connection between two nodes.

4. Parent

A node that has one or more children.

5. Child

A node directly connected below a parent.

6. Siblings

Nodes having the same parent.

7. Leaf Node

A node with no children.

8. Internal Node

A node with at least one child.

9. Degree of a Node

The number of children of a node.

10. Degree of a Tree

The maximum degree among all nodes in the tree.

11. Level

The number of edges from root to the node.

12. Height

The length of the longest path from a node to a leaf.

13. Depth

The number of edges from the root to a node.

14. Subtree

A part of a tree formed by a node and all its descendants.

📊 DIAGRAM
A / | \ B C D / \ \ E F G Root = A Children of A = B, C, D Leaf nodes = C, E, F, G Internal nodes = A, B, D Degree of A = 3
📌 KEY POINTS

Tree is hierarchical.

One node is selected as root.

Every node except root has exactly one parent.

Leaf nodes do not have children.


Q2. Discuss Binary Tree Traversals (Inorder, Preorder, Postorder).

Tree traversal methods are explicitly included in your unit notes, where inorder, preorder, and postorder traversals are discussed with algorithms and examples.

🔷 TREE TRAVERSAL

Tree traversal means visiting every node of a tree exactly once in a systematic order.

The three main traversals are:

1. Inorder Traversal

2. Preorder Traversal

3. Postorder Traversal

📌 1. INORDER TRAVERSAL
Definition

In inorder traversal, the order is:

Left Subtree → Root → Right Subtree

Algorithm
Inorder(tree) 1. Traverse left subtree 2. Visit root 3. Traverse right subtree
Example
A / \ B C / \ \ D E F
Inorder Output

D → B → E → A → C → F

📌 2. PREORDER TRAVERSAL
Definition

In preorder traversal, the order is:

Root → Left Subtree → Right Subtree

Algorithm
Preorder(tree) 1. Visit root 2. Traverse left subtree 3. Traverse right subtree
Preorder Output

A → B → D → E → C → F

📌 3. POSTORDER TRAVERSAL
Definition

In postorder traversal, the order is:

Left Subtree → Right Subtree → Root

Algorithm
Postorder(tree) 1. Traverse left subtree 2. Traverse right subtree 3. Visit root
Postorder Output

D → E → B → F → C → A

📊 COMPARISON TABLE
TraversalOrder
InorderLeft, Root, Right
PreorderRoot, Left, Right
PostorderLeft, Right, Root
📌 APPLICATIONS

Inorder: binary search tree gives sorted output

Preorder: copying tree

Postorder: deleting tree, evaluating expressions


Q3. Explain BST with Insertion and Searching Algorithms.

BST operations such as insertion, deletion, and searching are clearly part of your notes and syllabus material.

🔷 BINARY SEARCH TREE (BST)

A Binary Search Tree is a binary tree in which:

left subtree contains only smaller values

right subtree contains only larger values

📊 BST PROPERTY

For every node:
Left subtree < Root < Right subtree

📊 DIAGRAM
50 / \ 30 70 / \ / \ 20 40 60 80
📌 INSERTION IN BST
Algorithm
Insert(root, value) 1. If root is NULL, create new node and return it 2. If value < root->data, insert into left subtree 3. If value > root->data, insert into right subtree 4. Return root
Example

Insert 25 into the tree:

25 < 50 → go left

25 < 30 → go left

25 > 20 → go right

Insert at correct position

Result
50 / \ 30 70 / \ / \ 20 40 60 80 \ 25
📌 SEARCHING IN BST
Algorithm
Search(root, key) 1. If root is NULL or root->data == key, return root 2. If key < root->data, search left subtree 3. If key > root->data, search right subtree
Example

Search 60:

60 > 50 → right

60 < 70 → left

Found at node 60

📊 TIME COMPLEXITY
OperationBest/AverageWorst
InsertionO(log n)O(n)
SearchO(log n)O(n)

Worst case happens when the BST becomes skewed.

📌 ADVANTAGES OF BST

Fast searching in average case

Maintains ordered data

Useful for dynamic data

📌 DISADVANTAGES

Can become skewed

Performance drops to O(n) in worst case


Q4. Explain AVL Tree and Rotations with Examples.

AVL trees are part of your unit coverage and are listed along with BST and heap topics in the course outline.

🔷 AVL TREE

An AVL tree is a self-balancing binary search tree.
For every node, the height difference between left and right subtree is at most 1.

Balance Factor

BF = Height(Left Subtree) - Height(Right Subtree)

Allowed values:

-1, 0, +1

If balance factor goes beyond this range, rotations are used.

📌 ROTATIONS IN AVL TREE

There are four types of rotations.

1. LL Rotation

Used when insertion occurs in the left subtree of the left child.

Before:

30 / 20 / 10

After right rotation:

20 / \ 10 30
2. RR Rotation

Used when insertion occurs in the right subtree of the right child.

Before:

10 \ 20 \ 30

After left rotation:

20 / \ 10 30
3. LR Rotation

Used when insertion occurs in the right subtree of the left child.

Before:

30 / 10 \ 20

Steps:

Left rotate 10

Right rotate 30

After:

20 / \ 10 30
4. RL Rotation

Used when insertion occurs in the left subtree of the right child.

Before:

10 \ 30 / 20

Steps:

Right rotate 30

Left rotate 10

After:

20 / \ 10 30
📊 ROTATION SUMMARY
CaseRotation
LLRight Rotation
RRLeft Rotation
LRLeft then Right
RLRight then Left
📌 ADVANTAGES OF AVL TREE

Strictly balanced

Fast searching

Height always O(log n)


Q5. Explain Heap Construction and Deletion Operations.

Heap-related topics are part of your syllabus and unit outline, including minimum heap construction and heap data structure.

🔷 HEAP

A heap is a complete binary tree that satisfies the heap property.

Two types:

1. Min Heap

2. Max Heap

📌 1. MIN HEAP

In a min heap, parent node is smaller than or equal to its children.

Example
10 / \ 20 30 / \ 40 50

Root is the smallest element.

📌 2. MAX HEAP

In a max heap, parent node is greater than or equal to its children.

Example
50 / \ 30 40 / \ 10 20

Root is the largest element.

📌 HEAP CONSTRUCTION
Steps

1. Insert the new element at the last position.

2. Compare it with parent.

3. Swap if heap property is violated.

4. Repeat until property is satisfied.

Example for Min Heap

Insert 15 into:

10 / \ 20 30

Insert at last:

10 / \ 20 30 / 15

Since 15 > 10, no swap needed.
If inserted value were smaller than parent, swap upward.

📌 DELETION IN HEAP

Deletion usually removes the root node.

Steps

1. Remove root.

2. Replace it with last element.

3. Heapify down.

4. Restore heap property.

Example

Min Heap:

10 / \ 20 30 / \ 40 50

Delete 10:

Replace root with 50

Heapify down

After heapify:

20 / \ 40 30 / 50
📊 COMPLEXITY
OperationTime
InsertO(log n)
Delete rootO(log n)
Get min/maxO(1)

Q6. Compare AVL Tree and BST.

BST and AVL tree are both covered in your notes, and AVL is specifically described as a height-balanced binary tree while BST is the ordered binary search structure.

📊 COMPARISON TABLE
FeatureBSTAVL Tree
BalanceMay be unbalancedAlways balanced
HeightCan become O(n)Always O(log n)
SearchSlower in worst caseFaster and reliable
RotationsNot usedRequired
ComplexityAverage O(log n), worst O(n)O(log n) for search/insert/delete
ImplementationSimplerMore complex
📌 KEY DIFFERENCE

BST is easy to implement but can become skewed.

AVL tree maintains balance using rotations, so performance stays efficient.


Q7. Discuss Applications of Trees and Heaps.

Your notes mention applications of trees and BSTs, including file systems, databases, routing, AI, syntax parsing, searching, and priority queues.

🔷 APPLICATIONS OF TREES

1. File Systems

Trees are used to represent folders and subfolders.

2. Databases

Trees help in indexing and fast searching.

3. Expression Evaluation

Expression trees are used to represent arithmetic expressions.

4. Syntax Parsing

Compilers use trees to analyze syntax.

5. Artificial Intelligence

Decision trees are used in AI and machine learning.

6. Network Routing

Trees help model routing structures.

🔷 APPLICATIONS OF HEAPS

1. Priority Queue

Heap is used to implement priority queues efficiently.

2. Heap Sort

Heap sort uses heap structure to sort data.

3. Scheduling

Operating systems use heaps for job and process scheduling.

4. Graph Algorithms

Heaps are used in algorithms like Dijkstra and Prim for efficient minimum selection.

5. Event Simulation

Heaps help process events based on priority or time.

📊 SUMMARY TABLE
Data StructureMain Use
TreeHierarchical representation
BSTFast ordered searching
AVL TreeBalanced searching
HeapPriority-based access