Dsa Practice Questions
Dsa Practice Questions
Write a function to pop elements from the stack and display the updated stack.
2. Reverse a Stack:
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).
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".
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 generate binary numbers from 1 to N using a queue. For example, for
N=5, the output should be 1, 10, 11, 100, 101.
Implement a queue using two stacks. Write functions for enqueue and dequeue.
Write a function to find the nth node from the end of a singly linked list.
6. Remove Duplicates:
Write a function to merge two sorted linked lists into a single sorted linked list.
Write a function to detect if a loop exists in a linked list and, if it does, remove it.
Write a function to find the intersection point of two singly linked lists.
Write a function to delete the first occurrence of a given value in a linked list.
Combined Stack, Queue, and Linked List Questions
Implement a queue data structure using two stacks. Write functions to insert and delete
elements.
Implement a singly linked list and use it to mimic the behavior of both a stack (LIFO) and a
queue (FIFO).
Advanced
Design and implement a Least Recently Used (LRU) cache using a combination of a doubly
linked list and a hash map.
Given a linked list where each node has a next pointer and a random pointer, clone the
linked list.