A social graph contains all the friendship relations (edges) among a group of n people (vertices). The friendship relationship is symmetric. Two vertices with no edge between them are enemies. Design and implement a class called Graph for a social graph. It should have an adjacency matrix as a data member to represent the graph. The nodes in the graph are numbered from 0..n-1 graph[i][i] - is always true (1) graph[i][j] is true if i and j are friends and false (0) if they are enemies.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Assignment on Graph
A social graph contains all the friendship relations (edges) among a group of n people
(vertices). The friendship relationship is symmetric. Two vertices with no edge between
them are enemies.
Design and implement a class called Graph for a social graph. It should have an
adjacency matrix as a data member to represent the graph. The nodes in the graph are
numbered from 0..n-1
graph[i][i] - is always true (1)
graph[i][j] is true if i and j are friends and false (0) if they are enemies.
• In the constructor, initialize all entries to false (0) and all graph[i][i] to true (1)
Include the following member functions.
o void makeFriends(int i,intj)- make i and j friends
int countFriends(int i) - will return the number of friends of i, excluding
itself
int countEnemies(int i)- will return the number of enemies of i
int countCommonFriends(int i,intj) - the number of common friends of i
and j
int countCommonEnemies(int i,intj) - the number of common enemies of
i and j
int findBestFriends(int i)- will return a possible best friend of i. The
possible best friend is the friend with the most number of common friends
with i. There may be more than one possible best friend, return only 1. If
there is none, return i.
int friendliest()- will return the node with the most number of friends
int loner() - will return the node with the least number of friends.
boolean recluse(int i) - will return true if i has no friends.
boolean famous(int i) - will return true if node i is a friend of everybody in
the group
For each function, write a comment identifying the running time of each function in
terms of big-oh notation. Create a program testing all the functions of the class.
Transcribed Image Text:Assignment on Graph A social graph contains all the friendship relations (edges) among a group of n people (vertices). The friendship relationship is symmetric. Two vertices with no edge between them are enemies. Design and implement a class called Graph for a social graph. It should have an adjacency matrix as a data member to represent the graph. The nodes in the graph are numbered from 0..n-1 graph[i][i] - is always true (1) graph[i][j] is true if i and j are friends and false (0) if they are enemies. • In the constructor, initialize all entries to false (0) and all graph[i][i] to true (1) Include the following member functions. o void makeFriends(int i,intj)- make i and j friends int countFriends(int i) - will return the number of friends of i, excluding itself int countEnemies(int i)- will return the number of enemies of i int countCommonFriends(int i,intj) - the number of common friends of i and j int countCommonEnemies(int i,intj) - the number of common enemies of i and j int findBestFriends(int i)- will return a possible best friend of i. The possible best friend is the friend with the most number of common friends with i. There may be more than one possible best friend, return only 1. If there is none, return i. int friendliest()- will return the node with the most number of friends int loner() - will return the node with the least number of friends. boolean recluse(int i) - will return true if i has no friends. boolean famous(int i) - will return true if node i is a friend of everybody in the group For each function, write a comment identifying the running time of each function in terms of big-oh notation. Create a program testing all the functions of the class.
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY