0
0
DSA Typescriptprogramming~10 mins

Adjacency List Representation in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize an empty adjacency list for a graph.

DSA Typescript
const adjacencyList: Record<number, number[]> = [1];
Drag options to blanks, or click blank then click option'
A[]
Bnew Map()
Cnull
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using an empty array instead of an object.
Using null which is not a valid adjacency list.
Using Map without proper initialization.
2fill in blank
medium

Complete the code to add an edge from node 1 to node 2 in the adjacency list.

DSA Typescript
if (!adjacencyList[1]) adjacencyList[1] = [];
adjacencyList[1].[1](2);
Drag options to blanks, or click blank then click option'
Apush
Bpop
Cshift
Dunshift
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes the last element.
Using shift which removes the first element.
Using unshift which adds at the start, not end.
3fill in blank
hard

Fix the error in the code to correctly add an undirected edge between nodes 3 and 4.

DSA Typescript
if (!adjacencyList[3]) adjacencyList[3] = [];
adjacencyList[3].push(4);
if (!adjacencyList[4]) adjacencyList[4] = [];
adjacencyList[4].[1](3);
Drag options to blanks, or click blank then click option'
Apush
Bpop
Cshift
Dunshift
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes elements instead of adding.
Using shift or unshift which are not appropriate here.
4fill in blank
hard

Fill both blanks to create an adjacency list for nodes 1 to 3 with edges 1->2 and 2->3.

DSA Typescript
const adjacencyList = {
  1: [[1]],
  2: [[2]],
  3: []
};
Drag options to blanks, or click blank then click option'
A2
B3
C1
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up which node connects to which.
Adding extra nodes or edges not specified.
5fill in blank
hard

Fill all three blanks to add edges 5->6, 6->7, and 7->5 in the adjacency list.

DSA Typescript
const adjacencyList = {};

if (!adjacencyList[5]) adjacencyList[5] = [];
adjacencyList[5].push([1]);

if (!adjacencyList[6]) adjacencyList[6] = [];
adjacencyList[6].push([2]);

if (!adjacencyList[7]) adjacencyList[7] = [];
adjacencyList[7].push([3]);
Drag options to blanks, or click blank then click option'
A6
B7
C5
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong neighbor numbers.
Forgetting to initialize adjacencyList entries.