Singly Linked List and Doubly Linked List in Data Structure
What is singly Linked List-?
It is linear collection of data item called node where each node has divided into parts, i.e.., "Data part and link part". Data part store the data item and link part store the address of next node.
Linked list start with a special pointer called start pointer and terminated with Null pointer.
Algorithm of Singly Linked List in Data Structure
Step 1:- begin i=7
Step 2:- Set i ⬅ st
Step 3:- Repeat step 4 and 5, while i≠null
Step 4:- Print data [i]
Step 5:- i ⬅ link [i]
Step 6:- Exit
What is Circular Singly Linked List-?
If a last node of singly linked list hold the address of start node, then the linked list is called circular linked list
Algorithm of Circular Singly Linked List
Step 1:- Begin
Step 2:- Set i ⬅ st
Step 3:- Print data [i]
Step 4:- i ⬅ linked [i]
Step 5:- Goto step 3, while i≠st
Step 6:- Exit
Algorithm to print content of Circular Linked List more then one time
Step 1:- Begin
Step 2:- Set i ⬅ st, j ⬅ 1
Step 3:- Repeat step 4 to 7 while j<=2
Step 4:- Print data [i]
Step 5:- i ⬅ link [i]
Step 6:- if i=st then
Step 7:- j ⬅ j+1
Step 8:- Exit
What is Doubly Linked List-?
It is the linear collection of data item called node where each node has divided into three point, i.e.., data point, previous point and next point. Data part store the data item previous point store address of previous node. It starts with special pointer called first pointer and ending with last pointer.
Algorithm for Forward Traversing
Step 1:- Begin
Step 2:- Set i ⬅ first
Step 3:- Repeat step 4 and 5 while i≠null
Step 4:- Print data [i]
Step 5:- i ⬅ next [i]
Algorithm for Backward Traversing
Step 1:- Begin
Step 2:- Set i ⬅ last 5
Step 3:- Repeat step 4 and 5 while i≠null
Step 4:- Print data [i]
Step 5:- i ⬅ previous [i]
Step 6:- Exit
What is Circular Doubly Linked List-?
If a last node of doubly linked list hold the address of first node and first node of doubly linked list hold the address of last node then, the linked list is called circular doubly linked list.
Algorithm for Forward traversing of Circular Doubly Linked List
Step 1:- Begin
Step 2:- Set i ⬅ first
Step 3:- Print data [i]
Step 4:- i ⬅ next [i]
Step 5:- Goto step 3, while i≠first
Step 6:- Exit
Algorithm for Backward traversing of Circular Doubly Linked List
Step 1:- begin
Step 2:- Set i ⬅ last
Step 3:- Print data [i]
Step 4:- i ⬅ previous [i]
Step 5:- Goto step 3, while i=last
Step 6:- Exit
Difference between Tree and Graph in Data Structure and C Language
S.no | Tree | Graph |
1 | It is non-linear data structure | It is also non-linear data structure |
2
| It is a collection of nodes and edges | It is a collection of vertices and edges |
| T={nodes, edges} | G={vertices, edges} |
3
| There is a unique node is called root in tree
| There is no unique node called root in graph
|
4
| There will not be any cycle or loop | A cycle can be formed |
5 | Tree is a herarical model | Graph is a network model |
6
| It's always contains N-1 edges | It contains number of edges depends on graph |
| Applications:- | Applications:- |
| It is used to Searching, Inserting and Deleting any element in tree | It is used to finding the shortest path in networking graph |
No comments:
Post a Comment