DSA MST Solution
DSA MST Solution
Ques on: Create a node for doubly linked list and circular linked list. Show the inser on of an
element at the end of the both lists, either by code or by algorithm. Also men on the advantages
and applica ons of both types of linked lists?
struct node {
int data;
struct node *next;
struct node *prev;
};
struct node {
int data;
struct node *next;
};
• Traverse the doubly linked list with temporary pointer temp, un ll temp->next ≠ NULL.
• New node right (next) pointer points to NULL and le (prev) pointer points to the temp
variable which is the end of the list.
• Update right (next) pointer of temp (earlier last) node to point to new node.
Algo:
• Traverse the doubly linked list with temporary pointer temp, un ll temp->next ≠ Head.
• New node right (next) pointer points to Head (or temp->next) and le (prev) pointer points
to the temp variable which is the end of the list.
Algo:
• The advantage of a doubly linked list is that it can be traversed in both direc ons (forward
and backward). Therefore, a node can be deleted or inserted in both direc ons and lost
pointers can be easily recovered.
• Undo/redo opera ons and data structures like tree, hash, etc. can be implemented through
doubly linked list. Other applica ons may include webpage naviga on.
• Allows any node to be a head node. Therefore, opera ons like shi ing or rota on are easy.
• Applicability of circular linked list is in situa ons where several processes are using the same
computer resource (CPU) for the same amount of me, we have to assure that no process
accesses the resource before all other processes do (round robin algorithm).
ti
ti
ti
ti
ti
ti
ti
ft
ti
ti
ti
ti
Q.4 (i) Consider a 2-D array A[-5…..20] [20….70]. The base address of
array in memory is 1020. Size of element is 8 bytes. Find the location of
A[0][30] in both column major order & row major order. [4
Marks]
Answer: At q0.