0% found this document useful (0 votes)
2 views2 pages

Data Structures: Linked Lists & Algorithms

The document outlines algorithms for insertion and deletion operations in a circular linked list with a header node, as well as stack and queue operations using linked lists. It also describes the conversion of prefix expressions to postfix using a stack and the evaluation of postfix expressions. Each section provides step-by-step algorithms for the respective data structure operations.

Uploaded by

aartisaini5348
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Data Structures: Linked Lists & Algorithms

The document outlines algorithms for insertion and deletion operations in a circular linked list with a header node, as well as stack and queue operations using linked lists. It also describes the conversion of prefix expressions to postfix using a stack and the evaluation of postfix expressions. Each section provides step-by-step algorithms for the respective data structure operations.

Uploaded by

aartisaini5348
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Data Structures Assignment

Q1: Explain with algorithm insertion and deletion operation in


circular linked list with header node.
A circular linked list is a type of linked list in which the last node points back to the first node,
forming a circle. A header node is a special node that stores no data but helps in performing
operations easily.

Algorithm for Insertion:


1. Create a new node. 2. Set data in the new node. 3. Traverse the list to find the position. 4. Insert
the node by adjusting links. 5. If inserting at the end, connect last node to the header.

Algorithm for Deletion:


1. Search the node to delete. 2. Adjust previous node's link to skip the deleting node. 3. Free the
memory of deleted node. 4. If last node is deleted, connect previous node back to header.

Header 10 20

Q2: Explain with suitable algorithm the operation of stack and


queue using Linked list
A stack follows LIFO (Last In First Out) principle. A queue follows FIFO (First In First Out) principle.
Both can be implemented using linked lists.

Stack Operations (using Linked List):


Push Algorithm: 1. Create new node. 2. Insert it at the beginning of the list. 3. Update top pointer.
Pop Algorithm: 1. Delete node from beginning. 2. Update top pointer.

Top

30

20

10
Queue Operations (using Linked List):
Enqueue Algorithm: 1. Create new node. 2. Insert node at the end. 3. Update rear pointer. Dequeue
Algorithm: 1. Delete node from the front. 2. Update front pointer.

Front Rear

10 20 30

Q3: Explain with algorithm the conversion of prefix expression


into postfix using stack
Algorithm: 1. Read prefix expression from right to left. 2. If operand, push onto stack. 3. If operator,
pop two operands from stack, combine them in postfix order, and push back. 4. Repeat until
expression ends. 5. The result on stack top is postfix expression.

Q4: Explain with algorithm the evaluation of postfix expression


using stack
Algorithm: 1. Read postfix expression from left to right. 2. If operand, push onto stack. 3. If operator,
pop two elements from stack, apply operation, and push result back. 4. Repeat until expression
ends. 5. Final result in stack top is the answer.

You might also like