dsaAssignment3FALL2024
dsaAssignment3FALL2024
Assignment 3
SE – 203T Data Structures and Algorithms
Q1) Consider Problem Solving Scenario (case study/research paper) for non-linear type and apply
appropriate data structure. Also you have to suggest or replace already implemented data stricture
to improve complexity for selected scenario.
Note: Attach the case study / research paper with the assignment.
In this scenario, we are working with a social network platform, where we want to analyze connections
between users. The network has millions of users, and each user can be connected to hundreds or
thousands of other users.
Each user has certain attributes such as name, age, location, interests, etc. We are interested in:
The platform needs to handle real-time updates like adding or removing users and connections
(friendships), and quickly process complex queries about user connections.
Non-linear Data Structures for the Scenario
Given that the problem involves relationships between users, a graph is an ideal data structure to represent
the network. In a graph:
Graphs are inherently non-linear data structures because there is no hierarchical order (unlike trees) —
each node can have multiple connections, and the relationships between nodes are more flexible.
Types of Graphs:
1. Undirected Graph: This is ideal for representing friendships, as if User A is friends with User B,
then User B is also friends with User A.
2. Directed Graph: Useful in cases where one-way relationships exist, e.g., user A follows user B,
but user B doesn't necessarily follow user A.
1. Adjacency List: A space-efficient representation of a graph, where each node has a list of adjacent
nodes (friends). This is particularly useful if the graph is sparse, meaning not every user is friends
with every other user.
2. Adjacency Matrix: An alternative representation where a 2D matrix is used to represent edges
between nodes. This is more useful for dense graphs but uses more memory. It’s less efficient for
sparse graphs.
3. Hash Map of Adjacency Lists: A hash map could be used to dynamically store the list of friends
for each user. This allows for fast access and updates.
Instead of iterating over each user’s friend list for mutual friends, you can store the friends in a
hash set and perform efficient set intersections for recommendations.
Conclusion
In this social network scenario, using non-linear data structures like graphs is essential to represent
complex relationships between users. Implementing adjacency lists with hash sets for fast lookups, BFS for
shortest paths, and Union-Find for dynamic connectivity will improve both the time complexity and
scalability of the system. For very large-scale networks, transitioning to a graph database would be a
further improvement.
This approach ensures that we can efficiently solve problems related to friendship recommendations,
pathfinding, and community detection, all of which are crucial for real-time social network analysis.