Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

PART A

DSA – IT, AIDS & M.Tech


1. Create a program to delete the last node of a singly linked list.

2. Explain the concept of a head pointer in a singly linked list.

3. Compare the memory overhead of a doubly linked list node with that of a singly linked list node.

4. List the concept of a self-adjusting list and how it can be implemented using a circular linked list.

5. Illustrate does the LIFO (Last In, First Out) principle relate to the stack model?

6. Demonstrate the dynamic resizing strategy used in array-based stack implementations to handle overflow conditions.

7. Can you illustrate the process of converting an infix expression to prefix notation using an example, highlighting the role of
stacks at each step?
8. Compare and contrast the memory usage of array-based and linked list-based queue implementations, considering factors such
as memory allocation and deallocation.
9. Discuss the importance of priority queue in applications such as task scheduling in operating systems or event management in
simulations.
10. Describe an algorithm to efficiently merge two priority queues while preserving the order of elements.

11. Implement a program to delete the first node of a singly linked list.

12. Compare the memory overhead of a singly linked list node with that of an array element.

13. Describe how a circular linked list can be used in implementing a round-robin scheduling algorithm.

14. Enumerate the basic operations that can be performed on a doubly linked list.

15. Discuss the dynamic resizing strategy used in array-based stack implementations to handle overflow conditions.

16. Illustrate how you would implement additional stack operations such as peek (or top) and isEmpty.

17. Infer In what real-world scenarios can the application of stacks in infix to prefix conversion be beneficial?

18. Relate how you would implement additional queue operations such as peek (or front), isEmpty, and size.

19. Explain how a priority queue can be implemented using an array-based approach, highlighting the challenges and advantages.

20. Compare and contrast the time complexity of enqueue, dequeue, and peek operations in a priority queue implemented using
different data structures.
21. Implement a singly linked list and describe the process of inserting an element at the beginning.

22. Demonstrate the deletion of an element from the end of a doubly linked list through a practical example.

23. Implement the process of reversing a linked list with a coded example to illustrate how memory pointers are manipulated.

24. Traverse a linked list and print each element using a loop or recursion, explaining each step in the traversal process.

25. Describe the memory allocation processes for arrays and linked lists, illustrating how dynamic arrays expand in memory.

26. Implement a function to push an element onto a stack using an array, and discuss the efficiency of this operation.

27. Describe a real-world application of a queue and implement a simple simulation.

28. Illustrate the process of checking for balanced parentheses in an expression using a stack, and discuss its importance in compilers.

29. Describe the working of a circular queue and its advantages over a linear queue in scenarios like CPU scheduling.

30. Compare the primary differences between a stack and a queue by implementing both and applying them to a problem-solving
scenario.
31. Write a C++ function to define a linked list node structure and explain its components.

32. Illustrate the steps to insert an element at a specific position in an array and discuss the implications on array structure.

33. Differentiate between singly and doubly linked lists by implementing both and showcasing a specific operation where their
differences are critical.
34. Discuss the advantages and disadvantages of using arrays over linked lists with examples from real-world applications.

35. Compare the characteristics of arrays and linked lists by implementing examples that highlight their respective access times and
memory use.
36. Develop a function to dequeue an element from a queue implemented using a linked list, and analyze its performance.

37. Create a queue using two stacks, explaining each step and its effect on the time complexity of enqueue and dequeue operations.

38. Describe the concepts of stack overflow and underflow with examples that demonstrate error handling in stack operations.

39. Describe how a priority queue differs from a regular queue using a real-world example such as emergency services dispatch.

40. Implement a dynamic array and discuss how it differs from static arrays in terms of resizing and memory use.

PART -B
1. Write a program to create a singly linked list and display the added elements.
Note : Insert the elements in the end of the list.
Input Format
Number of list elements in the first line
List elements in the second line separated by space.
Output Format
Display the list as shown in the sample output.
Sample Input
5
3 4 21 232 89
Sample Output
3 4 21 232 89

2. Write a C++ program to create a singly linked list and display the added elements.
Sample Input
5
3 4 21 232 89
Sample Output
89 232 21 4 3

3. Node swap
Write a program to reverse all the values in the linked list and swap the nodes a and b of linked list rather than swapping the field from the
nodes.
Example
Input
10
99 64 84 79 61 62 89 63 67 74
84 62
Output
74 67 63 89 84 61 79 62 64 99

4. Write a C++ program to delete the node at the end of the singly linked list.
Sample Input
5
3 4 21 232 89
2
Sample Output
89 232 21 4 3
89 232 21

5. Write a program to delete a node at the beginning of a circular linked list.


Example
Input
7
11 59 2 70 71 33 77
Output
59 2 70 71 33 77
Explanation
List has "11 59 2 70 71 33 77" values, delete the first node in the list i.e. 11 and print the list.
6. Vanessa is learning about doubly linked list and is eager to play around with it. She decides to find out how the elements are inserted in
the list and understands that the insertion happens in the reverse order. Now she plans to print the original list and reversed list one below
the other. Help her in implementing the same.
Sample Input
12345
Sample Output
54321
12345

7. People from a group are asked to form a circle for an activity. Then this group has to be split into two halves so that each group does a
different activity as part of the original one. The task is to split it into two halves with exact same count or if there odd number of people, the
first half can have more people than the other.

Consider the arrangement to be in the form a circular linked list and split accordingly.
Sample Input
5
12345
Sample Output
543
21

8. Bala is a software engineer and he is developing a text editor. He needs to implement UNDO and REDO functionality. His friend
Chandra suggested to use Doubly Linked List to implement the required functionality. Since Bala is new to data structures, Chandra asked
him to learn Doubly Linked List.

After few days, Chandra asked Bala to write a program to create a doubly linked list and delete the node at the given position from the
beginning. Write a suitable code to help Bala.
Sample Input
8
15 21 32 47 53 65 71 82
2
Sample Output
15 32 47 53 65 71 82

9. Write a code to implement stack using linked list and perform push and pop using underflow and overflow condition. The pop is done
only once after the elements are put into the stack.
Sample Input
5
121
125
158
148
198
Sample Output
148
158
125
121

10. Lalit and his friends are playing cards sitting around a circular table. After the first game, first-person and last person exchange their
position. Pranav is watching this game and he relates this with Circular Linked List.

So he decided to write a program to exchange first and last nodes in Circular Linked List. Help Pranav to complete this program.
Sample Input
10
3456781239
Sample Output
Before Swap : 3 4 5 6 7 8 1 2 3 9
After Swap : 9 4 5 6 7 8 1 2 3 3
11. Write a program to check whether the string is palindrome or not using Stack.
Example
Input
malayalam
Output
malayalam is palindrome
Explanation
Push the string into the stack, then invert the string by popping the characters. Compare the two strings and print a palindrome if they are the
same otherwise not a palindrome.

12. Find the size of stack


Write a C++ program to find the size of stack using Linked List.

Note : Calculate the size using required function.


Sample Input
2
1
5
-1
Sample Output
16

13. A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed
from the front and new elements to be added to the rear. This is called a First-In-First-Out (FIFO) data structure because the first element
added to the queue (i.e., the one that has been waiting for the longest) is always the first one to be removed.

A basic queue has the following operations:

Enqueue: add a new element to the end of the queue.


Dequeue: remove the element from the front of the queue and return it.
In this challenge, you must first implement a queue using two stacks. Then process q queries, where each query is one of the
following 3 types:
1 x: Enqueue element x into the end of the queue.
2: Dequeue the element at the front of the queue.
3: Print the element at the front of the queue.
Sample Input:
10
1 42
2
1 14
3
1 28
3
1 60
1 78
2
2
Sample Output:
14
14

18. Ramu want to implement a fixed size queue of maximum size 5 using an array. His friend Priya has typed some code and asked Ramu to
complete the missing code to implement. Help Ramu by writing suitable functions to do the basic queue operations.

Structure declaration and main functions are already implemented. Write the suitable code for functions only.
Example
Input
140
255
145
985
215
Output
140 255 145 985 215
145 985 215
Queue is empty
Explanation
First Enqueue 140,255,145,985,215 and display queue values.
Second Dequeue two values 140 and 255 and print all the queue values i.e.145,985,215 .
Last dequeue all the elements from the queue and print "Queue is empty".

19. Write a C++program to insert and delete an element from the queue.
Sample Input
3
12
13
14
2
Sample Output
Element deleted from queue is : 12
Element deleted from queue is : 13

20. Write a C++ program to insert and delete elements from both queues.
Note: n is always 10 (5 each).
Input Format
The first line of the input consists of the queue 1 elements.
The next line consists of the queue 2 elements.
Output Format
The output prints the dequeued elements from both queues separated by a space.
Sample Input
10 9 8 7 6
12345
Sample Output
10 1

21. Reverse a queue using stack


Problem statement
You are given a Queue containing N elements. Reverse the Elements of the Queue using Stack.
Sample Input
5
2 4 6 8 10
Sample Output
10 8 6 4 2

22. You are given a Queue containing N Integers and an integer K. Reverse the order of the first K elements of the Queue, leaving the other
elements in the same relative order.

Sample Input
8
2 4 6 8 10 12 14 16
4
Sample Output
8 6 4 2 10 12 14 16

23. Write a C++ program to implement the priority queue.


Sample Input
5
62435
Sample Output
The priority queue elements are:
65432

24. Rakesh gets to know that binary numbers are formed with just 0 and 1. He gets excited and decides to find all the binary numbers
starting from 1 by adding/replacing a 0 or 1.
For example, after 1, he adds a 0 to it and arrives 10. Then, he replaces 0 with 1 to get 11 as the next digit and so on. Upon seeing the work,
his mentor planned to play a game with him where Rakesh will be given a number N and he has to arrive at the first N binary numbers using
this method.
To check the correctness of Rakesh, his mentor decided to build a code that does the same process. Since he is not well -versed in
programming he has employed you to do the same. Since you are good at data structures, you think queues will be of good use in this
scenario.

Sample Input
5
Sample Output
1
10
11
100
101

25. Mr.john is doing a transport business. As he had a lot of customers for registering the car, he wants to give the preference for the person
who comes first, if the car is filled with n number after that who comes with EVEN is added and the first element is removed .If ODD
means do nothing.
Sample Input
5
8
2 4 3 5 6 1 10 12
Sample Output
3 5 6 10 12

26. Design and implement a food ordering system for a restaurant using a circular queue data structure. The system should manage
incoming food orders from multiple customers and allocate kitchen staff to prepare the orders efficiently.

The system should allow the user to perform the following operations:
1. Enqueue a food order into the queue with a unique order number, customer name, and list of food items ordered.
2. Dequeue an order from the queue (when it has been processed by the kitchen staff).
3. Display the current state of the queue with the order numbers, customer names, and list of food items ordered.
4. Exit the program.

The program should be able to handle invalid inputs and display appropriate error messages. The program should also be able t o handle the
circular nature of the queue, ensuring that when the last element is reached, the next enqueued order is added at the beginning of the queue.

Note: There is a new line space after the last line of the output.
If the queue reaches its maximum size, then display "Queue is full".
If the dequeue is performed on an empty queue, then display "Queue is empty".
If the input is any of the mentioned options, then print "Invalid choice".
Sample Input
1
1
John
3
burger
fries
coke
1
2
Sarah
2
Pizza
Soda
3
2
4
Sample Output
Order added to queue
Order added to queue
Order number Customer name Food items
1 John burger, fries, coke,
2 Sarah Pizza, Soda,
Order number: 1
Customer name: John
Food items:
burger
fries
coke
4

1. Implement a program that compares memory management and access time between arrays and linked lists, discussing specific
scenarios where each is most efficient.
2. Develop a program to insert an element at a specific position in an array, addressing edge cases like array overflow, and provide
a code sample to illustrate.
3. Implement a doubly linked list with operations for insertion, deletion, and traversal, discussing the comparative benefits over a
singly linked list with examples.
4. Develop code to merge two sorted linked lists into a single sorted list, providing a detailed example and explanation.
5. Implement a sparse matrix using linked lists, explaining the advantages over using arrays in terms of memory efficiency and
computational complexity, with code examples.
6. Design a stack using an array and explain the time complexities of push, pop, and peek operations with code examples.
7. Implement a program to evaluate postfix expressions using a stack, detailing the underlying logic and providing a code exampl e.
8. Create a simulation of an elevator system using queues, explaining how to manage requests efficiently with operations for adding
and processing requests, including code examples.
9. Analyze the use of stack and queue data structures in backtracking algorithms, providing code examples and discussing their
roles in complex problem-solving scenarios.
10. Evaluate different queue implementations (array-based, linked list-based, circular) in terms of time complexity, memory usage,
and suitability for various applications, with code examples and discussion.
11. Design a program to implement a singly linked list with operations for inserting, deleting, and displaying elements, including
detailed code snippets and commentary.
12. Implement a solution to reverse a singly linked list in a programming language of your choice and analyze the time complexity of
your implementation.
13. Describe and demonstrate the use of dynamic arrays, including their memory allocation and resizing processes, with code
examples.
14. Implement and explain the creation and use of a circular linked list, including the insertion process and its benefits.
15. Illustrate the performance differences between arrays and linked lists in scenarios with frequent insertions and deletions through
theoretical analysis and practical benchmarks.
16. Develop a printer queue simulation using a linked list, describing the operations for adding and processing print jobs, especially
in high-volume scenarios.
17. Design and implement a stack to solve the Tower of Hanoi problem, explaining the role of the stack in managing the recursive
solution with a complete code example.
18. Apply deques to solve the sliding window maximum problem in arrays, and analyze the time complexity and benefits of your
implementation.
19. Implement the use of priority queues in Dijkstra’s shortest path algorithm, providing a detailed code implementation and
explanation of efficiency improvements.
20. Discuss and demonstrate the use of stacks and queues in algorithm design, focusing on recursion and task scheduling, with
practical examples from real-world applications.

You might also like