...
Logical-Reasoning
October 12, 2023
Nielit Scientist-B CS 22-07-2017
October 12, 2023
Logical-Reasoning
October 12, 2023
Nielit Scientist-B CS 22-07-2017
October 12, 2023

Programming

Question 2

A program attempts to generate as many permutations as possible of the string, ‘abcd’ by pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at any time. Which one of the following strings CANNOT be generated using this program?

A
abcd
B
dcba
C
abad
D
cabd
Question 2 Explanation: 
A) push ‘a’ and pop ‘a’, push ‘b’ and pop ‘b’, push ‘c’ and pop ‘c’, and finally push ‘d’ and pop ‘d’. Sequence of popped elements will come to abcd.
B) First push abcd, and after that pop one by one. Sequence of popped elements will come to dcba.
C) push abc, and after that pop one by one. Sequence of popped elements will come to cba. Now push ‘d’ and pop ‘d’, final sequence comes to cbad.
D) This sequence is not possible because ‘a’ cannot be popped before ‘b’ anyhow.
Correct Answer: D
Question 2 Explanation: 
A) push ‘a’ and pop ‘a’, push ‘b’ and pop ‘b’, push ‘c’ and pop ‘c’, and finally push ‘d’ and pop ‘d’. Sequence of popped elements will come to abcd.
B) First push abcd, and after that pop one by one. Sequence of popped elements will come to dcba.
C) push abc, and after that pop one by one. Sequence of popped elements will come to cba. Now push ‘d’ and pop ‘d’, final sequence comes to cbad.
D) This sequence is not possible because ‘a’ cannot be popped before ‘b’ anyhow.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!