ds imp
ds imp
Data Structure is a way of collecting and organising data in such a way that we
can perform operations on these data in an effective way.
Displaying (or) visiting order of nodes in a binary tree is called as Binary Tree
Traversal.
There are three types of binary tree traversals.
1. In - Order Traversal
2. Pre - Order Traversal
3. Post - Order Traversal
1. In - Order Traversal
( leftChild - root - rightChild )
in In-Order traversal, the
root node is visited between
the left child and right child. In this traversal, the left child node is visited
first, then the root node is visited and later we go for visiting the right child
node. This is performed recursively for all nodes in the tree.
In the above example of a binary tree, first we try to visit left child of root
node 'A', but A's left child 'B' is a root node for left subtree. so we try to
visit its (B's) left child 'D' and again D is a root for subtree with nodes D, I
and J. So we try to visit its left child 'I' and it is the leftmost child. So first we
visit 'I' then go for its root node 'D' and later we visit D's right child 'J'. With
this we have completed the left part of node B. Then visit 'B' and next B's
right child 'F' is visited. With this we have completed left part of node A.
Then visit root node 'A'. With this we have completed left and root parts of
node A. Then we go for the right part of the node A. In right of A again
there is a subtree with root C. So go for left child of C and again it is a
subtree with root G. But G does not have left part so we visit 'G' and then
visit G's right child K. With this we have completed the left part of node C.
Then visit root node 'C' and next visit C's right child 'H' which is the
rightmost child in the tree. So we stop the process.
In-Order Traversal for above example of binary tree is I - D - J - B - F - A - G
-K-C–H
Singly Linked List: It is the simplest type of linked list in which every node
contains some data and a pointer to the next node of the same data type. The
node contains a pointer to the next node means that the node stores the address
of the next node in the sequence. A single linked list allows traversal of data only
in one way. HEADER is an empty node (having data content NULL) and only used
to store a pointer to the first node Thus, if
one knows the address of the HEADER
node from the link field of this node, the
next node can be traced, and so on. This
means that starting from the first node
one can reach to the last node whose link
field does not contain any address but
has a null value.
Doubly Circular linked list: A Doubly Circular linked list or a circular two-way
linked list is a more complex type of linked-list that contains a pointer to the next
as well as the previous node in the sequence. The difference between the doubly
linked and circular doubly list is the same as that between a singly linked list and a
circular linked list. The circular doubly linked list does not contain null in the
previous field of the first node
Types of Queues
1. Simple Queue or ordinary queue
2. Circular Queue
3. Dequeue
4. Priority Queue
Simple Queue
A simple queue are the general queue that we use on perform insertion and
deletion on FIFO basis i.e. the new element is inserted at the rear of the queue
and an element is deleted from the front of the queue
Applications of Simple Queue
1.CPU scheduling
2. Disk Scheduling
3. Synchronization between two process
Circular Queue
Circular queue is a type of queue in which all nodes are treated as circular such
that the first node follows the last node. It is also called ring buffer. In this type of
queue operations are performed on first in first out basis i.e the element that has
inserted first will be one that will be deleted first.
Applications of Circular Queue
1.CPU scheduling
2.Memory management
3.Traffic Management
Priority Queue
Priority Queue is a special type of queue in which elements are treated according
to their priority. Insertion of an element take place at the rear of the queue but
the deletion or removal of an element
take place according to the priority of the
element. Element with the highest priority is removed first and element wit h the
lowest priority is removed last.