CS Atlas GATE 2027
PDS course
0 / 103 complete

PDS/Phase 7 · Integration & Final Test

Revision 7.2.2 · Item 99 of 103

Mixed practice set 2

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

On this page

Twelve more mixed questions. Aim for about 2 minutes per 1-mark and 4 minutes per 2-mark question.

Practice set

Q1MCQ1 markOutput

What does this print?

#include <stdio.h>
int main(void)
{
    int a[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
    printf("%d %d %d\n", *(*(a + 1) + 2), *(a[2] + 1), **a + 5);
    return 0;
}
  • (A) 7 10 6
  • (B) 7 10 2
  • (C) 3 10 6
  • (D) 6 9 6

Q2MCQ2 marksStrings

What does this print?

#include <stdio.h>
#include <string.h>
int main(void)
{
    char s[] = "GATE2027";
    char *p = s + 4;
    printf("%d %d %s %c\n", (int)sizeof(s), (int)strlen(p), p + 1, *s + 1);
    return 0;
}
  • (A) 8 4 027 H
  • (B) 9 4 2027 G
  • (C) 9 4 027 H
  • (D) 9 5 027 H

Q3MCQ1 markRecursion

What does this print?

#include <stdio.h>
void p(int n)
{
    if (n == 0) return;
    printf("%d ", n);
    p(n - 1);
    printf("%d ", n);
}

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

Q4MCQ2 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"); }

struct node *g(struct node *h)
{
    struct node *p = NULL, *q = h;
    if (h == NULL || h->next == NULL) return h;
    while (q->next != NULL) {
        p = q;
        q = q->next;
    }
    p->next = NULL;
    q->next = h;
    return q;
}

int main(void)
{
    show(g(build(5)));
    return 0;
}
  • (A) 5 1 2 3 4
  • (B) 5 4 3 2 1
  • (C) 2 3 4 5 1
  • (D) 1 2 3 4 5

Q5NAT1 markSwitch

What does this print?

#include <stdio.h>
int main(void)
{
    int x = 2, s = 0;
    switch (x) {
        case 1: s += 1;
        case 2: s += 2;
        case 3: s += 3; break;
        default: s += 10;
    }
    printf("%d\n", s);
    return 0;
}

Numerical answer: ________

Q6MCQ2 marksCircular queue

What does this print?

#include <stdio.h>
#define N 5
int q[N], front = 0, rear = 0;                 /* front: slot before the first element */

int enq(int x) { if ((rear + 1) % N == front) return 0; rear = (rear + 1) % N; q[rear] = x; return 1; }
int deq(void) { front = (front + 1) % N; return q[front]; }

int main(void)
{
    int i, ok = 0;
    for (i = 1; i <= 6; i++) ok += enq(i);
    deq();
    deq();
    ok += enq(7);
    printf("%d %d %d\n", ok, front, rear);
    return 0;
}
  • (A) 5 2 5
  • (B) 5 2 0
  • (C) 6 2 1
  • (D) 4 2 4

Q7NAT1 markAddress

int A[10][20] is stored row-major at base 1000 with 4-byte int. Address of A[5][7]?

Numerical answer: ________

Q8NAT2 marksTraversals

Inorder D B E A F C G and postorder D E B F G C A. Write the preorder as letters; how many nodes come before C in it?

Numerical answer: ________

Q9MCQ1 markTrees

A binary tree has 20 leaves. How many nodes have exactly two children?

  • (A) 21
  • (B) 19
  • (C) 20
  • (D) 10

Q10MCQ2 marksAVL

Insert 50, 40, 30, 35, 33 into an empty AVL tree. The preorder at the end is:

  • (A) 35 30 33 40 50
  • (B) 40 33 30 35 50
  • (C) 40 35 30 33 50
  • (D) 40 30 35 33 50

Q11NAT1 markHeaps

How many distinct max-heaps can be built with 6 distinct keys?

Numerical answer: ________

Q12MCQ2 marksGraphs

Graph with edges A–B, A–C, B–D, C–D, D–E, E–F. Which is a valid DFS order from A?

  • (A) A B D E C F
  • (B) A B C D E F
  • (C) A B D C E F
  • (D) A C B D E F

Answer Vault

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

Q1 Answer: (A)1 mark

a[1][2], a[2][1], a[0][0] + 5.

Output

7 10 6
  • (B) is wrong: **a + 5 is 1 + 5.
  • (C) is wrong: *(a + 1) is row 1.
  • (D) is wrong: Indices start at 0.

Re-read: Lesson 1.5.2 — 2-D arrays; row-major layout; pointer to array vs array of pointers; reading complex declarations

Q2 Answer: (C)2 marks

sizeof counts the '\0'; *s + 1 is 'G' + 1.

Output

9 4 027 H
  • (A) is wrong: The array has 9 bytes.
  • (B) is wrong: p + 1 skips the 2; *s + 1 is H.
  • (D) is wrong: strlen("2027") is 4.

Re-read: Lesson 1.5.3 — Strings: char arrays, '\0', read-only string literals, strlen vs sizeof, string functions and tracing string code

Q3 Answer: (D)1 mark

Print on the way down and on the way up.

Output

3 2 1 1 2 3
  • (A) is wrong: The second printf runs after each return.
  • (B) is wrong: Each level prints around the deeper calls.
  • (C) is wrong: The first print happens before the call.

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

Q4 Answer: (A)2 marks

The last node moves to the front.

Output

5 1 2 3 4
  • (B) is wrong: Only one node moves.
  • (C) is wrong: That moves the first node to the end.
  • (D) is wrong: g changes the list.

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

Q5 Answer: 51 mark

Falls from case 2 into case 3 and stops at break.

Output

5

Re-read: Lesson 1.2.1 — if / else if / else; nested conditions; switch and fall-through

Q6 Answer: (B)2 marks

Capacity 4: two enqueues fail; after two dequeues 7 wraps to slot 0.

Output

5 2 0
  • (A) is wrong: rear wraps with % N.
  • (C) is wrong: Only 4 of the first 6 succeed.
  • (D) is wrong: enq(7) succeeds after the dequeues.

Re-read: Lesson 3.3.2 — Circular queue: full/empty conditions and index arithmetic

Q7 Answer: 14281 mark

1000 + (5·20 + 7)·4.

Re-read: Lesson 3.1 — Arrays as a data structure: the ADT idea; address calculation (row-major, column-major, non-zero lower bounds); cost of insert, delete and search

Q8 Answer: 42 marks

Preorder A B D E C F G: A, B, D, E before C.

Re-read: Lesson 4.3.3 — Rebuilding a tree from two traversals; counting distinct binary trees (Catalan)

Q9 Answer: (B)1 mark

n₀ = n₂ + 1.

  • (A) is wrong: Off by one the other way.
  • (C) is wrong: Off by one.
  • (D) is wrong: Not half.

Re-read: Lesson 4.2.2 — Binary tree properties: nodes per level and height; n₀ = n₂ + 1; minimum and maximum height

Q10 Answer: (B)2 marks

LL at 50: right rotation; RL at 30: right rotation at 35, then left rotation at 30.

  • (A) is wrong: The root stays 40.
  • (C) is wrong: 33 rises above 30 and 35.
  • (D) is wrong: 30 becomes unbalanced after 33 and is fixed.

Re-read: Lesson 4.6 — Balanced BSTs — AVL idea, balance factor, rotations, minimum nodes for a given height

Q11 Answer: 201 mark

C(5, 3)·2·1.

Re-read: Lesson 5.4 — Heap GATE drills: k-th largest, number of heaps, comparisons, d-ary heaps

Q12 Answer: (C)2 marks

A → B → D → C (back up to D) → E → F.

  • (A) is wrong: After E, DFS goes to F before backing up.
  • (B) is wrong: C is not adjacent to B.
  • (D) is wrong: B is not adjacent to C.

Re-read: Lesson 6.3 — Graph traversals: BFS, DFS, connected components

Ready for the next idea?

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