0
0
DSA Cprogramming~5 mins

Adjacency List Representation in DSA C - 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 neighboring nodes. It saves space by only storing edges that exist.
Click to reveal answer
beginner
How does an adjacency list differ from an adjacency matrix?
An adjacency list stores neighbors for each node in lists, using less space for sparse graphs. An adjacency matrix uses a 2D array to store edge presence, using more space.
Click to reveal answer
intermediate
In C, what data structure is commonly used to implement an adjacency list?
A common approach is to use an array of pointers, where each pointer points to a linked list of neighbors for that vertex.
Click to reveal answer
beginner
Why is adjacency list preferred for sparse graphs?
Because it only stores existing edges, it uses less memory and is faster to iterate over neighbors 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 vertex using adjacency list?
It is O(k), where k is the number of neighbors of that vertex, since we directly access the list of neighbors.
Click to reveal answer
What does each element in an adjacency list represent?
AA graph color
BA matrix row
CA vertex and its neighbors
DAn edge weight
Which data structure is commonly used to store neighbors in C adjacency lists?
AArray of arrays
BStack
CQueue
DLinked lists
What is the main advantage of adjacency lists over adjacency matrices?
AFaster edge lookup
BLess memory for sparse graphs
CSimpler to implement
DSupports weighted graphs only
How do you add an edge from vertex u to vertex v in an adjacency list?
AAdd v to u's neighbor list
BSet matrix[u][v] = 1
CAdd u to v's neighbor list
DIncrement edge count
What is the space complexity of adjacency list for a graph with V vertices and E edges?
AO(V + E)
BO(V^2)
CO(E^2)
DO(V)
Explain how an adjacency list represents a graph and why it is efficient for sparse graphs.
Think about how you would list friends for each person instead of a big table.
You got /3 concepts.
    Describe how you would implement an adjacency list in C using arrays and linked lists.
    Imagine each vertex has a pointer to a chain of neighbors.
    You got /3 concepts.