0% found this document useful (0 votes)
20 views5 pages

Dsa Practice Questions

Dsa
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)
20 views5 pages

Dsa Practice Questions

Dsa
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/ 5

Stack Practice Questions

1. Push and Pop:

Implement a stack using an array or a linked list.

Write a function to push elements into the stack.

Write a function to pop elements from the stack and display the updated stack.

2. Reverse a Stack:

Write a function to reverse a stack using recursion.

Implement a program that pushes elements to the stack, reverses the stack, and then
displays the reversed stack.

3. Sort a Stack:

Implement a function to sort a stack in ascending order without using any additional data
structure (only recursion).

4. Find Minimum in a Stack:

Write a program to find the minimum element in a stack in constant time.

5. Balanced Parentheses:

Write a program to check if the given parentheses are balanced or not using a stack. For
example, for input "((()))", the output should be "balanced", and for input "(()", the output
should be "unbalanced".

Queue Practice Questions

1. Implement a Queue:
Implement a queue using an array or a linked list.

Write functions to enqueue (insert) and dequeue (remove) elements from the queue.

2. Circular Queue:

Implement a circular queue. Write a function for insertion, deletion, and display of the queue.

3. Reverse a Queue:

Write a function to reverse the elements in a queue using a stack or recursion.

4. Generate Binary Numbers Using Queue:

Write a function to generate binary numbers from 1 to N using a queue. For example, for
N=5, the output should be 1, 10, 11, 100, 101.

5. Queue Using Stacks:

Implement a queue using two stacks. Write functions for enqueue and dequeue.

Linked List Practice Questions

1. Insert and Delete Operations:

Implement a singly linked list. Write functions to:

Insert an element at the beginning, end, or any given position.

Delete an element from the beginning, end, or any given position.

2. Reverse a Linked List:

Write a function to reverse a singly linked list iteratively and recursively.


3. Search in a Linked List:

Write a function to search for a given element in a linked list.

4. Count Elements in a Linked List:

Write a function to count the number of elements in a linked list.

5. Find Nth Node from the End:

Write a function to find the nth node from the end of a singly linked list.

6. Remove Duplicates:

Write a function to remove duplicate elements from a sorted linked list.

7. Merge Two Sorted Linked Lists:

Write a function to merge two sorted linked lists into a single sorted linked list.

8. Detect and Remove Loop:

Write a function to detect if a loop exists in a linked list and, if it does, remove it.

9. Intersection of Two Linked Lists:

Write a function to find the intersection point of two singly linked lists.

10. Delete Node by Value:

Write a function to delete the first occurrence of a given value in a linked list.
Combined Stack, Queue, and Linked List Questions

1. Implement a Queue using a Stack:

Implement a queue data structure using two stacks. Write functions to insert and delete
elements.

2. Reverse a Linked List Using Stack:

Write a function that uses a stack to reverse a linked list.

3. Linked List as Stack and Queue:

Implement a singly linked list and use it to mimic the behavior of both a stack (LIFO) and a
queue (FIFO).

4. Palindrome Check Using Stack and Linked List:

Write a program to check if a linked list is a palindrome using a stack.

Advanced

1. LRU Cache Implementation:

Design and implement a Least Recently Used (LRU) cache using a combination of a doubly
linked list and a hash map.

2. Clone a Linked List with Random Pointers:

Given a linked list where each node has a next pointer and a random pointer, clone the
linked list.

You might also like