0
0
DSA Typescriptprogramming~5 mins

Adjacency List Representation in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an adjacency list in graph representation?
An adjacency list is a way to represent a graph where each node stores a list of its neighbors. It shows which nodes are directly connected to each node.
Click to reveal answer
intermediate
How does an adjacency list differ from an adjacency matrix?
An adjacency list stores neighbors only, saving space for sparse graphs. An adjacency matrix uses a 2D array showing connections between all pairs, using more space.
Click to reveal answer
beginner
TypeScript code snippet: How to declare an adjacency list for a graph with 3 nodes?
const graph: Map<number, number[]> = new Map();
graph.set(0, [1, 2]);
graph.set(1, [0]);
graph.set(2, [0]);
Click to reveal answer
intermediate
Why is adjacency list preferred for sparse graphs?
Because it only stores existing edges, saving memory and making traversal faster compared to adjacency matrix which stores all possible edges.
Click to reveal answer
intermediate
What is the time complexity to find all neighbors of a node in adjacency list?
It is O(k), where k is the number of neighbors of that node, because the list directly stores neighbors.
Click to reveal answer
What data structure is commonly used to implement an adjacency list?
AQueue
B2D array
CStack
DArray of lists or Map of lists
Which graph representation uses less space for a graph with few edges?
AAdjacency matrix
BAdjacency list
CEdge list
DIncidence matrix
In an adjacency list, how do you find neighbors of a node?
ALook up the node's list of neighbors
BScan the entire matrix row
CCheck all nodes in the graph
DUse a stack to traverse
What is the main disadvantage of adjacency matrix compared to adjacency list?
AUses more memory for sparse graphs
BSlower to find neighbors
CCannot represent directed graphs
DHard to implement
Which of these is a valid TypeScript type for an adjacency list?
Astring[]
Bnumber[][]
CMap<number, number[]>
DSet<number>
Explain how an adjacency list represents a graph and why it is efficient for sparse graphs.
Think about how you store only connected nodes, not all possible pairs.
You got /3 concepts.
    Describe how you would implement an adjacency list in TypeScript for an undirected graph.
    Remember undirected means two-way connections.
    You got /3 concepts.