0
0
Data Structures Theoryknowledge~30 mins

Graphs in social networks in Data Structures Theory - Mini Project: Build & Apply

Choose your learning style9 modes available
Graphs in Social Networks
📖 Scenario: Imagine you are analyzing a small social network where people are connected as friends. Each person is a node, and each friendship is an edge connecting two nodes.
🎯 Goal: You will build a simple representation of a social network using a graph structure. You will create the data, set a threshold for popular users, find users with many friends, and finally mark those popular users.
📋 What You'll Learn
Create a dictionary representing the social network graph with exact people and their friends
Add a variable for the minimum number of friends to be considered popular
Use a loop to find all popular users based on the threshold
Add a final dictionary marking popular users with a boolean value
💡 Why This Matters
🌍 Real World
Social networks use graphs to represent connections between people, helping to analyze relationships and suggest new friends.
💼 Career
Understanding graph structures is important for roles in data analysis, social media management, and software development involving network data.
Progress0 / 4 steps
1
Create the social network graph
Create a dictionary called social_graph with these exact entries: 'Alice': ['Bob', 'Charlie'], 'Bob': ['Alice', 'David', 'Eve'], 'Charlie': ['Alice'], 'David': ['Bob'], 'Eve': ['Bob'].
Data Structures Theory
Need a hint?

Use a dictionary where keys are names and values are lists of friends.

2
Set the popularity threshold
Create a variable called popularity_threshold and set it to 2 to represent the minimum number of friends needed to be considered popular.
Data Structures Theory
Need a hint?

This variable helps decide who is popular based on friend count.

3
Find popular users
Create an empty list called popular_users. Use a for loop with variables user and friends to iterate over social_graph.items(). Inside the loop, if the length of friends is greater than or equal to popularity_threshold, append user to popular_users.
Data Structures Theory
Need a hint?

Check each user's friend list length and add to popular_users if it meets the threshold.

4
Mark popular users in a dictionary
Create a dictionary called popularity_status using a dictionary comprehension. For each user in social_graph, set the value to true if user is in popular_users, otherwise false.
Data Structures Theory
Need a hint?

Use a dictionary comprehension to assign true or false for each user.