0
0
DSA Typescriptprogramming~10 mins

Adjacency List vs Matrix When to Choose Which in DSA Typescript - Interactive Comparison Practice

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

Complete the code to create an adjacency list for a graph with 3 nodes.

DSA Typescript
const graph: number[][] = [[], [], []];
graph[0].[1](1);
graph[1].push(2);
console.log(graph);
Drag options to blanks, or click blank then click option'
Aadd
Bappend
Cpush
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which is not a method in TypeScript arrays.
2fill in blank
medium

Complete the code to initialize an adjacency matrix for a graph with 3 nodes.

DSA Typescript
const size = 3;
const matrix: number[][] = Array(size).fill(0).map(() => Array(size).[1](0));
console.log(matrix);
Drag options to blanks, or click blank then click option'
Aslice
Bpush
Cmap
Dfill
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'push' which adds elements instead of filling existing ones.
3fill in blank
hard

Fix the error in the code to add an edge in the adjacency matrix.

DSA Typescript
const matrix = [[0, 0], [0, 0]];
matrix[0][[1]] = 1;
console.log(matrix);
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which points to the same node, not the edge.
4fill in blank
hard

Fill both blanks to create an adjacency list and add an edge from node 2 to node 0.

DSA Typescript
const graph: number[][] = [[], [], []];
graph[[1]].[2](0);
console.log(graph);
Drag options to blanks, or click blank then click option'
A2
Bpush
C1
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which is not a TypeScript array method.
5fill in blank
hard

Fill all three blanks to create an adjacency matrix and add an edge from node 1 to node 2.

DSA Typescript
const size = 3;
const matrix: number[][] = Array(size).fill(0).map(() => Array(size).[1](0));
matrix[[2]][[3]] = 1;
console.log(matrix);
Drag options to blanks, or click blank then click option'
Afill
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices or methods that don't exist.