1.What is Complete Binary Tree?
Ans.A Complete Binary Tree is a binary tree in which:
1. All levels are fully filled, except possibly the last level.
2. The last level is filled from left to right.
Properties:
1. Every node has 0 or 2 children.
2. All internal nodes have two children.
3. All leaf nodes are at the same level.
Types of Complete Binary Trees:
1. Perfect Binary Tree: All levels are fully filled.
2. Almost Complete Binary Tree: Last level has one or two nodes missing.
Examples:
``` 1
/ \
2 3
/ \ / \
4 5 6 7
Complete Binary Trees are used in:
1. Heaps
2. Priority Queues
3. Binary Search Trees (BSTs)
4. Data Compression
2.Different between array and queue.
Ans.Array:-
An Array is a collection of items stored at contiguous memory locations. The idea
is to store multiple items of the same type together. This makes it easier to
calculate the position of each element by simply adding an offset to a base value,
i.e., the memory location of the first element of the array (generally denoted by
the name of the array).
The diagrammatic representation of the Array is given below:
______________________________________
40|55|63|17|22|68|89|97|89|
______________________________________
0 |1 | 2 | 3 | 4 | 5| 6| 7|8. |<=array indices
Array length -9
First index-0
Last index-8
Queue:-
A Queue is a linear structure that follows a particular order in which the
operations are performed. The order is First In First Out (FIFO). A good example of
a queue is any queue of consumers for a resource where the consumer that came first
Ans.A Complete Binary Tree is a binary tree in which:
1. All levels are fully filled, except possibly the last level.
2. The last level is filled from left to right.
Properties:
1. Every node has 0 or 2 children.
2. All internal nodes have two children.
3. All leaf nodes are at the same level.
Types of Complete Binary Trees:
1. Perfect Binary Tree: All levels are fully filled.
2. Almost Complete Binary Tree: Last level has one or two nodes missing.
Examples:
``` 1
/ \
2 3
/ \ / \
4 5 6 7
Complete Binary Trees are used in:
1. Heaps
2. Priority Queues
3. Binary Search Trees (BSTs)
4. Data Compression
2.Different between array and queue.
Ans.Array:-
An Array is a collection of items stored at contiguous memory locations. The idea
is to store multiple items of the same type together. This makes it easier to
calculate the position of each element by simply adding an offset to a base value,
i.e., the memory location of the first element of the array (generally denoted by
the name of the array).
The diagrammatic representation of the Array is given below:
______________________________________
40|55|63|17|22|68|89|97|89|
______________________________________
0 |1 | 2 | 3 | 4 | 5| 6| 7|8. |<=array indices
Array length -9
First index-0
Last index-8
Queue:-
A Queue is a linear structure that follows a particular order in which the
operations are performed. The order is First In First Out (FIFO). A good example of
a queue is any queue of consumers for a resource where the consumer that came first