Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, can anyone translate the following code into an algorithm/java code? I don't understand pointers but I do understand algorithms/java programming language, so it'll be

Hi, can anyone translate the following code into an algorithm/java code? I don't understand pointers but I do understand algorithms/java programming language, so it'll be easier to understand

The problem is :

You want to throw a big party and have put together a list of your n friends. You also know who knows whom, so you have a list containing which pairs of people know each other. Being a major socialite and a networking guru, you decide that it would best to invite the maximum number of friends possible, subject to the following constraint: at the party, each person should have at least four people they know and at least four people they do not know.

Design an efficient algorithm that takes as input the list of n people and the list of pairs who know each other and outputs the best choice of party invitees. Analyze the worst-case running time in terms of n. The more efficient your algorithm is in terms of its asymptotic worst-case running time, the more credit you may get.

Code :

#include #include

Void main() { char **ppl,**prs,*p; int num_elements,i,num_pairs,j,*know_count; printf("How Many People"); scanf("%d",num_elements); *know_count = (int*) calloc(num_elements, sizeof(int)); **ppl = (char**) calloc(num_elements, sizeof(char*));

for ( i = 0; i < num_elements; i++ ) { ppl[i] = (char*) calloc(10, sizeof(char)); } printf("Enter the name of %d People",num_elements); for(i = 0; i < num_elements; i++) scanf("%s",ppl[i]);

printf("How Many Pairs"); scanf("%d",num_pairs); **prs = (char**) calloc(num_pairs, sizeof(char*));

for ( i = 0; i < num_pairs; i++ ) { prs[i] = (char*) calloc(21, sizeof(char)); }

printf("Enter Pairs(Names seperated by -)"); for(i = 0; i < num_pairs; i++) scanf("%s",prs[i]);

for(i=0;i5 && ((num_elements-know_count)>5)) printf("%s /n",ppl[i]); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

What is a break-even point?

Answered: 1 week ago