DEA-C01 Question 136
Single answerYou are designing a data pipeline for a social networking application. The application needs to recommend new friends to users based on mutual connections. Which data structure and algorithm would be the most appropriate to model the relationships and compute mutual connections efficiently?
- A
Graph data structure with Breadth-First Search (BFS)
- B
Tree data structure with Depth-First Search (DFS)
- C
Hash table with linear probing
- D
Array with binary search
Show answer and explanation
Correct answer: A
Explanation
Social networks are naturally represented as graphs, where nodes represent users and edges represent connections between them. Breadth-First Search (BFS) is a common algorithm for traversing graphs and is particularly effective for finding all neighbors of a node or mutual connections between nodes. Therefore, a graph data structure with BFS is the most appropriate choice for this scenario.
- A. Correct.
Graph data structures are ideal for modeling relationships between entities, such as users in a social network. Breadth-First Search (BFS) can be used to traverse the graph and find mutual connections efficiently.
- B. Incorrect.
Tree data structures are hierarchical and not well-suited for representing complex relationships like those in a social network. DFS is also less efficient for finding mutual connections in this context compared to BFS.
- C. Incorrect.
A hash table is useful for quick lookups but isn’t suitable for modeling complex relationships like mutual connections in a social network.
- D. Incorrect.
An array is a basic data structure that lacks the ability to represent relationships between entities, making it unsuitable for this use case.