ds key
ds key
Stack
queue
Level – The level of a node is defined by 1 + (the number of connections between the
node and. the root).
Height. In a tree data structure, the number of edges from the leaf node to the particular
node in the longest path is known as the height of that node.
// Driver method
int main()
{
int arr[] = { 12, 11, 13, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, n);
printArray(arr, n);
return 0;
}
Inserting a new node in a doubly linked list is very similar to inserting new node in
linked list. There is a little extra work required to maintain the link of the previous
node. In this article, we will learn about different ways to insert a node in a doubly
linked list.
To implement a stack using the singly linked list concept, all the singly linked
list operations should be performed based on Stack operations LIFO(last in first out)
and with the help of that knowledge, we are going to implement a stack using a singly
linked list.
So we need to follow a simple rule in the implementation of a stack which is last in
first out and all the operations can be performed with the help of a top variable. Let us
learn how to perform Pop, Push, Peek, and Display operations in.
In the stack Implementation, a stack contains a top pointer. which is the “head” of the
stack where pushing and popping items happens at the head of the list. The first node
has a null in the link field and second node-link has the first node address in the link
field and so on and the last node address is in the “top” pointer.
The main advantage of using a linked list over arrays is that it is possible to implement
a stack that can shrink or grow as much as needed. Using an array will put a
restriction on the maximum capacity of the array which can lead to stack overflow.
Here each new node will be dynamically allocated. so overflow is not possible.
Binary tree is a tree data structure (non-linear) in which each node can have at
most two children which are referred to as the left child and the right child. The
topmost node in a binary tree is called the root, and the bottom-most nodes are
called leaves. A binary tree can be visualized as a hierarchical structure with the root
at the top and the leaves at the bottom.
Binary trees can be represented in multiple ways, each with its own advantages,
depending on the use case. Let's explore the two common methods: linked node
representation and array implementation.
Representation of Binary Trees
There are two primary ways to represent binary trees:
1. Linked Node Representation
2. Array Representation
1. Linked Node Representation
This is the simplest way to represent a binary tree. Each node contains data and
pointers to its left and right children.
This representation is mostly used to represent binary tree with multiple advantages.
The most common advantages are given below.