CS Atlas GATE 2027
PDS course
0 / 103 complete

PDS/Phase 6 · Graphs

Checkpoint CP6 · Item 96 of 103

Graphs

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

On this page

⏱️

15 questions · 24 marks · 40 minutes. Negative marking on MCQ only: −1/3 mark for a wrong 1-mark MCQ, −2/3 for a wrong 2-mark MCQ. No negative marking for MSQ or NAT; MSQ has no partial credit.

Q1NAT1 markHandshake

A simple graph has 9 vertices of degree 2 and 6 vertices of degree 3. How many edges?

Numerical answer: ________

Q2NAT2 marksComponents

Maximum edges in a simple graph with 12 vertices and 4 components?

Numerical answer: ________

Q3MCQ1 markDAG

A DAG is a directed graph with:

  • (A) no vertex of in-degree 0
  • (B) all edges in both directions
  • (C) exactly one source
  • (D) no directed cycle

Q4MSQ2 marksDegrees

Which degree sequences belong to some simple graph?

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

Q5NAT1 markGraphs

Number of simple undirected graphs on 3 labelled vertices?

Numerical answer: ________

Q6MCQ1 markSpace

A sparse graph with n = 10⁵ and e = 3·10⁵ is best stored as:

  • (A) adjacency lists
  • (B) an adjacency matrix
  • (C) an incidence matrix
  • (D) any; all use Θ(n + e)

Q7NAT2 marksOnes

A directed simple graph has 25 edges. How many 1s are in its adjacency matrix?

Numerical answer: ________

Q8MCQ2 marksOutput

What is the line printed for vertex 5?

#define N 8
struct node {
    int v;
    struct node *next;
};
struct node *adj[N];                      /* adjacency lists, all NULL at start */

void addEdge(int a, int b)                /* insert b at the head of a's list */
{
    struct node *p = malloc(sizeof(struct node));
    p->v = b;
    p->next = adj[a];
    adj[a] = p;
}

int main(void)
{
    int e[][2] = {{0, 1}, {0, 2}, {1, 3}, {1, 4}, {2, 4}, {3, 5}, {4, 5}, {6, 7}};
    int i;
    struct node *p;
    for (i = 0; i < 8; i++) {
        addEdge(e[i][0], e[i][1]);
        addEdge(e[i][1], e[i][0]);
    }
    for (i = 0; i < 6; i++) {
        printf("%d:", i);
        for (p = adj[i]; p != NULL; p = p->next) printf(" %d", p->v);
        printf("\n");
    }
    return 0;
}
  • (A) 5: 4
  • (B) 5: 3 4 5
  • (C) 5: 3 4
  • (D) 5: 4 3

Q9NAT2 marksA²

In the running example, what is (A²)[0][0]?

Numerical answer: ________

Q10MCQ2 marksValid BFS

Which is NOT a valid BFS order of the running example from 0?

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

Q11MCQ2 marksOutput

What does this print?

#define N 8
int g[N][N];

void build(void)
{
    int e[][2] = {{0, 1}, {0, 2}, {1, 3}, {1, 4}, {2, 4}, {3, 5}, {4, 5}, {6, 7}};
    int i;
    for (i = 0; i < 8; i++) g[e[i][0]][e[i][1]] = g[e[i][1]][e[i][0]] = 1;
}

int seen[N];

void dfs(int v)
{
    int w;
    seen[v] = 1;
    printf("%d ", v);
    for (w = 0; w < N; w++)
        if (g[v][w] && !seen[w]) dfs(w);
}

int main(void)
{
    int v, c = 0;
    build();
    for (v = 0; v < N; v++)
        if (!seen[v]) {                   /* a new component starts here */
            printf("{ ");
            dfs(v);
            printf("} ");
            c++;
        }
    printf("\n%d\n", c);
    return 0;
}
  • (A) { 0 2 4 5 3 1 } { 6 7 } then 2
  • (B) { 0 1 3 5 4 2 } { 6 7 } then 2
  • (C) { 0 1 3 5 4 2 6 7 } then 1
  • (D) { 0 1 2 3 4 5 } { 6 7 } then 2

Q12MCQ1 markCost

DFS on adjacency lists runs in:

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

Q13NAT2 marksLevels

BFS from 0 in the running example: how many vertices are at distance exactly 1?

Numerical answer: ________

Q14MSQ1 markFacts

Which are true?

  • (A) DFS needs a queue.
  • (B) BFS gives fewest-edge paths from the start.
  • (C) Counting components restarts a traversal at unseen vertices.
  • (D) A traversal visits only the start’s component.

Q15MCQ2 marksDirected BFS

BFS from 1 in 1→2, 1→3, 2→4, 3→4, 4→5, 5→2 (smaller first) visits:

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

Answer Vault

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

Q1 Answer: 181 mark

(18 + 18)/2 = 18.

Re-read: Lesson 6.1 — Graph vocabulary

Q2 Answer: 362 marks

(12 − 4)(12 − 4 + 1)/2 = 8·9/2 = 36.

Re-read: Lesson 6.1 — Graph vocabulary

Q3 Answer: (D)1 mark

Directed acyclic.

  • (A) is wrong: A DAG always has a source.
  • (B) is wrong: Then 2-cycles exist.
  • (C) is wrong: It may have several.

Re-read: Lesson 6.1 — Graph vocabulary

Q4 Answer: (A) (C) (D)2 marks

C: two disjoint edges; D: K₅; A: e.g. a 5-cycle plus one chord.

  • (B) is wrong: Forces the last vertex to degree 3.

Re-read: Lesson 6.1 — Graph vocabulary

Q5 Answer: 81 mark

2³.

Re-read: Lesson 6.1 — Graph vocabulary

Q6 Answer: (A)1 mark

Θ(n + e) space.

  • (B) is wrong: 10¹⁰ cells.
  • (C) is wrong: n × e cells.
  • (D) is wrong: Matrices are Θ(n²) or Θ(n·e).

Re-read: Lesson 6.2 — Graph representations: adjacency matrix, adjacency list, incidence matrix

Q7 Answer: 252 marks

One per directed edge.

Re-read: Lesson 6.2 — Graph representations: adjacency matrix, adjacency list, incidence matrix

Q8 Answer: (D)2 marks

Output

0: 2 1
1: 4 3 0
2: 4 0
3: 5 1
4: 5 2 1
5: 4 3
  • (A) is wrong: 3–5 also appears.
  • (B) is wrong: No self-loop.
  • (C) is wrong: Input order; head insertion reverses it.

Re-read: Lesson 6.2 — Graph representations: adjacency matrix, adjacency list, incidence matrix

Q9 Answer: 22 marks

deg(0) = 2.

Re-read: Lesson 6.2 — Graph representations: adjacency matrix, adjacency list, incidence matrix

Q10 Answer: (B)2 marks

If 2 is dequeued before 1, 4 is enqueued before 3.

  • (A) is wrong: Valid.
  • (C) is wrong: Valid.
  • (D) is wrong: Valid.

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

Q11 Answer: (B)2 marks

Output

{ 0 1 3 5 4 2 } { 6 7 } 
2
  • (A) is wrong: The matrix scan takes smaller neighbours first.
  • (C) is wrong: 6 and 7 are not reachable from 0.
  • (D) is wrong: That is BFS order.

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

Q12 Answer: (B)1 mark

Each vertex once, each list once.

  • (A) is wrong: Matrix cost.
  • (C) is wrong: Too large.
  • (D) is wrong: No sorting.

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

Q13 Answer: 22 marks

1 and 2.

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

Q14 Answer: (B) (C) (D)1 mark

DFS uses a stack or recursion.

  • (A) is wrong: That is BFS.

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

Q15 Answer: (C)2 marks

Rings: {1}, {2, 3}, {4}, {5}.

  • (A) is wrong: That is DFS.
  • (B) is wrong: 2 comes before 3.
  • (D) is wrong: 5 is reached only via 4.

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

If you got these wrong, re-read

QuestionMarksTopicRe-read
Q11HandshakeLesson 6.1
Q22ComponentsLesson 6.1
Q31DAGLesson 6.1
Q42DegreesLesson 6.1
Q51GraphsLesson 6.1
Q61SpaceLesson 6.2
Q72OnesLesson 6.2
Q82OutputLesson 6.2
Q92A²Lesson 6.2
Q102Valid BFSLesson 6.3
Q112OutputLesson 6.3
Q121CostLesson 6.3
Q132LevelsLesson 6.3
Q141FactsLesson 6.3
Q152Directed BFSLesson 6.3

Ready for the next idea?

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