GATE DA 2025 — Question 64

Programming, Data Structures and Algorithmsbasic data structures: stacks, queues, linked lists, trees, hash tablesNAT2 marksMedium

Consider the following pseudocode.
code
1Create empty stack S
2Set x=0, flag=0, sum=0
3Push x onto S
4while (S is not empty){
5  if (flag equals 0){
6    Set x = x+1
7    Push x onto S}
8  if (x equals 8):
9    Set flag=1
10  if (flag equals 1){
11    x = Pop(S)
12    if (x is odd):
13      Pop(S)
14    Set sum = sum + x}
15}
16Output sum
17
The value of sum output by a program executing the above pseudocode is ____________ (Answer in integer)
Practise the full 2025 paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on basic data structures: stacks, queues, linked lists, trees, hash tablesTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group