CS Atlas GATE 2027
PDS course
0 / 103 complete

PDS/Phase 7 · Integration & Final Test

Revision 7.2.1 · Item 98 of 103

Mixed practice set 1

Read at your own pace. Try the questions before opening the answers.

On this page

Twelve questions across all phases, in random order — the mix forces you to decide which tool applies before using it. Work on paper, then open the vault. Each answer names the lesson to re-read.

Practice set

Q1MCQ1 markOutput

What does this print?

#include <stdio.h>
int main(void)
{
    int a = 0, b = 5, c;
    c = a++ && b++;
    printf("%d %d %d\n", a, b, c);
    c = a++ || b++;
    printf("%d %d %d\n", a, b, c);
    return 0;
}
  • (A) 1 5 0 then 2 5 1
  • (B) 1 5 0 then 2 6 1
  • (C) 1 6 0 then 2 7 1
  • (D) 0 5 0 then 1 5 1

Q2NAT1 markOutput

What does this print?

#include <stdio.h>
int f(void)
{
    static int s = 1;
    s = s * 2;
    return s;
}

int main(void)
{
    int i, t = 0;
    for (i = 0; i < 4; i++) t += f();
    printf("%d\n", t);
    return 0;
}

Numerical answer: ________

Q3MCQ2 marksOutput

What does this print?

#include <stdio.h>
int main(void)
{
    int a[] = {10, 20, 30, 40, 50};
    int *p = a + 1, *q = &a[4];
    printf("%d %d %d\n", *p + 2, *(p + 2), (int)(q - p));
    return 0;
}
  • (A) 12 40 3
  • (B) 22 40 12
  • (C) 22 30 3
  • (D) 22 40 3

Q4NAT2 marksRecursion

What is the second number printed?

#include <stdio.h>
int calls = 0;

int f(int n)
{
    calls++;
    if (n <= 1) return 1;
    return f(n - 1) + f(n - 2);
}

int main(void)
{
    int r = f(5);
    printf("%d %d\n", r, calls);
    return 0;
}

Numerical answer: ________

Q5MCQ1 markMacros

What does this print?

#include <stdio.h>
#define SQ(x) x * x

int main(void)
{
    printf("%d %d\n", SQ(2 + 3), 100 / SQ(5));
    return 0;
}
  • (A) 11 4
  • (B) 25 4
  • (C) 25 100
  • (D) 11 100

Q6MCQ2 marksLinked list

What does this print?

#include <stdio.h>
#include <stdlib.h>
struct node {
    int data;
    struct node *next;
};

struct node *build(int n)            /* list 1 -> 2 -> ... -> n */
{
    struct node *h = NULL, *p;
    while (n > 0) {
        p = malloc(sizeof(struct node));
        p->data = n--;
        p->next = h;
        h = p;
    }
    return h;
}

void show(struct node *h) { for (; h != NULL; h = h->next) printf("%d ", h->data); printf("\n"); }

void f(struct node *h)
{
    if (h == NULL) return;
    if (h->next != NULL) f(h->next->next);
    printf("%d ", h->data);
}

int main(void)
{
    f(build(5));
    printf("\n");
    return 0;
}
  • (A) 5 4 3 2 1
  • (B) 4 2
  • (C) 5 3 1
  • (D) 1 3 5

Q7MCQ1 markPostfix

The postfix form of a + b * (c − d) / e is:

  • (A) a b c d - e / * +
  • (B) a b c - d * e / +
  • (C) a b c d - * e / +
  • (D) a b + c d - * e /

Q8MSQ2 marksStack permutations

Input 1 2 3 4 5 is pushed in order (pops allowed any time). Which output sequences are possible?

  • (A) 5 1 2 3 4
  • (B) 4 5 3 1 2
  • (C) 2 4 3 1 5
  • (D) 3 2 5 4 1

Q9NAT1 markBST

A BST has preorder 15 10 8 12 20 17 25. How many leaves does it have?

Numerical answer: ________

Q10NAT2 marksHeap

Keys 3, 1, 6, 5, 2, 4 are inserted one by one into an empty max-heap. What key is at 0-based index 2 at the end?

Numerical answer: ________

Q11MCQ1 markGraphs

Maximum edges in a simple undirected graph with 7 vertices:

  • (A) 21
  • (B) 14
  • (C) 49
  • (D) 42

Q12MCQ2 marksBig-O

for (i = n; i > 0; i /= 2) for (j = 0; j < i; j++) count++; runs count++ how many times, in Θ terms?

  • (A) Θ(log n)
  • (B) Θ(n)
  • (C) Θ(n log n)
  • (D) Θ(n²)

Answer Vault

Try the questions first. Open when you are ready to check.

Q1 Answer: (A)1 mark

Both right-hand sides are skipped by short-circuiting.

Output

1 5 0
2 5 1
  • (B) is wrong: In the second line a++ yields 1, so || skips b++.
  • (C) is wrong: b++ never runs.
  • (D) is wrong: a++ still increments a.

Re-read: Lesson 1.1.2 — Operators: arithmetic, relational, logical with short-circuiting, bitwise, assignment, ++ and --; precedence and associativity; undefined behavior

Q2 Answer: 301 mark

2 + 4 + 8 + 16.

Output

30

Re-read: Lesson 1.3.2 — Scope vs lifetime; local, global, static, extern, register; shadowing in blocks; static local variables

Q3 Answer: (D)2 marks

p points to 20; p + 2 to 40; q − p counts 3 elements.

Output

22 40 3
  • (A) is wrong: *p is 20, not 10.
  • (B) is wrong: Pointer difference counts elements, not bytes.
  • (C) is wrong: p + 2 is a[3].

Re-read: Lesson 1.4.3 — Pointer arithmetic and why it scales by type size

Q4 Answer: 152 marks

calls = 2·f(5) − 1 = 15.

Output

8 15

Re-read: Lesson 2.1.2 — Recursion trees; counting calls; work done before vs after the recursive call

Q5 Answer: (D)1 mark

2 + 3 * 2 + 3 = 11; 100 / 5 * 5 = 100.

Output

11 100
  • (A) is wrong: 100 / 5 * 5 evaluates left to right.
  • (B) is wrong: The macro has no parentheses.
  • (C) is wrong: SQ(2 + 3) is not 25.

Re-read: Lesson 1.8 — Preprocessor macros and their expansion traps; function pointers

Q6 Answer: (C)2 marks

Every second node is visited; printing happens after the call returns.

Output

5 3 1
  • (A) is wrong: The call skips one node each time.
  • (B) is wrong: It starts at node 1.
  • (D) is wrong: Printing comes after the recursive call.

Re-read: Lesson 3.4.5 — GATE drill: tracing pointer-manipulation code on linked lists

Q7 Answer: (C)1 mark

  • and / are left-associative: (b * (c − d)) / e.
  • (A) is wrong: That divides (c − d) by e first.
  • (B) is wrong: d belongs inside the bracket.
  • (D) is wrong: a + b is not formed first.

Re-read: Lesson 3.2.2 — Stack applications: parenthesis matching; infix → postfix/prefix conversion; postfix evaluation

Q8 Answer: (C) (D)2 marks

Simulated.

  • (A) is wrong: After 5, the top is 4.
  • (B) is wrong: After 4 5 3, the top is 2, so 1 cannot come next.

Re-read: Lesson 3.2.3 — Valid stack permutations; Catalan numbers

Q9 Answer: 41 mark

8, 12, 17, 25.

Re-read: Lesson 4.5.4 — BST GATE drills: BST from a preorder/postorder sequence; number of BSTs; valid search paths; insertion orders giving the same BST

Q10 Answer: 42 marks

Final array 6 5 4 1 2 3.

Re-read: Lesson 5.2 — Heap insertion (sift-up) and deleting the root (sift-down)

Q11 Answer: (A)1 mark

7 · 6 / 2.

  • (B) is wrong: Too small.
  • (C) is wrong: That allows loops in both directions.
  • (D) is wrong: That counts directed edges.

Re-read: Lesson 6.1 — Graph vocabulary

Q12 Answer: (B)2 marks

n + n/2 + n/4 + … ≤ 2n.

  • (A) is wrong: The first pass alone is n.
  • (C) is wrong: The inner loop shrinks each time.
  • (D) is wrong: Far too large.

Re-read: Lesson 2.2 — Counting work: a Big-O primer

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.