DSA Viva Stack Tree Graph Test Practice
2025-2026
1. Given the following sequence of letters and asterisks:
(a) Consider the stack data structure, supporting two operations push and pop, as discussed in
class. Suppose that for the above sequence, each letter (such as E) corresponds to a push of that
letter onto the stack and each asterisk (*) corresponds to a pop operation on the stack. Show the
sequence of values returned by the pop operations.
(b) Consider the queue data structure, supporting two operations insert and remove, as discussed
in class. Suppose that for the above sequence, each letter (such as E) corresponds to an insert of
that letter into the queue and each asterisk (*) corresponds to a remove operation on the queue.
Show the sequence of values returned by the remove operations.
Answer:
a).Answer for stack Output: SYEUQTSAONIE.
b).Answer for Queue Output: EASYQUESTION
2. Suppose you were asked to write a method that will take two sorted stacks A and B (min on top)
and create one stack that is sorted (min on top). You are allowed to use only the stack operations
such as pop, push, size and top. No other data structure such as arrays are not allowed. You are
allowed to use stacks. Note that elements on the stack can be compared using compareTo.
Public Stack mergeSortedStacks(Stack A, Stack B)
{
…...
}
Answer:
,3. Evaluate the postfix expression: 10 5 + 60 6 / * 8 -
, Answer :142
4. Write a recursive delete method for singly-linked lists with integer data that deletes the
first occurrence of a given integer from the list and returns the resulting list.
class ListNode
{
private int value; //data value
Public ListNode next; //next element of list, or null if last
public ListNode(int v)
{
value = v;
}
public int value()
{
return value;
}
}
Answer :
static ListNode delete(int i, ListNode s)
{
if (s == null)
return s;
if (s.value() == i)
return s.next;
s.next = delete(i, s.next);
return s;
}
5. If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push
(2), pop are performed on a stack, then what will be the sequence of popped out values?
Answer:
Question 6 :-Suppose you want to get from s to t on weighted graph G with
nonnegative edge weights, but you would like to stop by u if it isn’t too
inconvenient. (Here too inconvenient means that it increases the length of
2025-2026
1. Given the following sequence of letters and asterisks:
(a) Consider the stack data structure, supporting two operations push and pop, as discussed in
class. Suppose that for the above sequence, each letter (such as E) corresponds to a push of that
letter onto the stack and each asterisk (*) corresponds to a pop operation on the stack. Show the
sequence of values returned by the pop operations.
(b) Consider the queue data structure, supporting two operations insert and remove, as discussed
in class. Suppose that for the above sequence, each letter (such as E) corresponds to an insert of
that letter into the queue and each asterisk (*) corresponds to a remove operation on the queue.
Show the sequence of values returned by the remove operations.
Answer:
a).Answer for stack Output: SYEUQTSAONIE.
b).Answer for Queue Output: EASYQUESTION
2. Suppose you were asked to write a method that will take two sorted stacks A and B (min on top)
and create one stack that is sorted (min on top). You are allowed to use only the stack operations
such as pop, push, size and top. No other data structure such as arrays are not allowed. You are
allowed to use stacks. Note that elements on the stack can be compared using compareTo.
Public Stack mergeSortedStacks(Stack A, Stack B)
{
…...
}
Answer:
,3. Evaluate the postfix expression: 10 5 + 60 6 / * 8 -
, Answer :142
4. Write a recursive delete method for singly-linked lists with integer data that deletes the
first occurrence of a given integer from the list and returns the resulting list.
class ListNode
{
private int value; //data value
Public ListNode next; //next element of list, or null if last
public ListNode(int v)
{
value = v;
}
public int value()
{
return value;
}
}
Answer :
static ListNode delete(int i, ListNode s)
{
if (s == null)
return s;
if (s.value() == i)
return s.next;
s.next = delete(i, s.next);
return s;
}
5. If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push
(2), pop are performed on a stack, then what will be the sequence of popped out values?
Answer:
Question 6 :-Suppose you want to get from s to t on weighted graph G with
nonnegative edge weights, but you would like to stop by u if it isn’t too
inconvenient. (Here too inconvenient means that it increases the length of