Question 8905 – ISRO CS 2020
December 26, 2023
Question 72 – ISRO-2018
December 26, 2023
Question 8905 – ISRO CS 2020
December 26, 2023
Question 72 – ISRO-2018
December 26, 2023

Question 8907 – ISRO CS 2020

A stack is implemented with an array of ‘A [0…N-1]’ and a variable ‘pos’. The push and pop

operations are defined by the following code.

push(x)

A[pos] x

pos pos+1

end push

pop()

pospos+1

Return A[pos]

end pop

Which of the following will initialize an empty stack with capacity N for the above implementation?

Correct Answer: D

Question 36 Explanation: 
If you check push function, for every push we are decrementing pos by one.
Now if you imagine an array of length N-1, for every push the empty indices are getting decremented.
To explain in detail,
consider an empty array, so number of empty indices are N-1 ……(1)
When we push one element into it, the empty indices will reduce by 1 (i.e. decreented.)
Hence, From equation 1 we can say that pos is initialised to N-1
A
pos ← -1
B
pos ← 0
C
pos ← 1
D
pos ←N-1
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!!