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

DSA Stack Queue LinkedList Questions Sample

The document contains practice questions on data structures, focusing on stack, queue, linked list, and deque implementations. It includes pseudocode and Java code for various operations, highlighting common errors and solutions. Each question is categorized by difficulty level: easy, medium, and hard.

Uploaded by

nema.yashu26
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)
0 views2 pages

DSA Stack Queue LinkedList Questions Sample

The document contains practice questions on data structures, focusing on stack, queue, linked list, and deque implementations. It includes pseudocode and Java code for various operations, highlighting common errors and solutions. Each question is categorized by difficulty level: easy, medium, and hard.

Uploaded by

nema.yashu26
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
You are on page 1/ 2

Data Structures Practice Questions

Q1 [Easy] - Write pseudocode to implement a stack using an array. Identify any logical error in the push

operation.

Solution:
Pseudocode:
procedure PUSH(stack, item)
if top == size - 1 then
print 'Stack Overflow'
else
top = top + 1
stack[top] = item
Java Equivalent:
if(top == stack.length - 1) {
System.out.println("Overflow");
} else {
stack[++top] = item;
}

Q2 [Easy] - Fill in the blank: In a circular queue implemented with an array, the condition for queue full is

______.

Solution:
Solution: (rear + 1) % size == front

Q3 [Medium] - Detect the error in this singly linked list deletion pseudocode:

procedure DELETE(head, key)

curr = head

while curr != null and curr.data != key do

prev = curr

curr = curr.next

prev.next = curr.next

Solution:
Error: prev is uninitialized if the key is at the head. Fix by checking if head.data ==
key before the loop.

Q4 [Medium] - Implement a deque using a doubly linked list. Provide Java code for insertFront().

Solution:
Java:
void insertFront(int key) {
Node newNode = new Node(key);
newNode.next = front;
Data Structures Practice Questions

if (front != null) front.prev = newNode;


front = newNode;
if (rear == null) rear = newNode;
}

Q5 [Hard] - Write pseudocode to reverse a stack using recursion only (no loop).

Solution:
Pseudocode:
procedure REVERSE(stack)
if stack is not empty then
temp = stack.pop()
REVERSE(stack)
insertAtBottom(stack, temp)

You might also like