How to implement (using C++ ) and a worst-case run-time analysis of the code . -
ID: 3635320 • Letter: H
Question
How to implement (using C++ ) and a worst-case run-time analysis of the code .-----------------------------------------
Consider a straight road with houses scattered very sparsely along it. You want to place cell phone base stations at certain points along the road, so that every house is within four miles of one of the base stations. Give a greedy algorithm that achieves this goal, using as few base stations as possible. Compute the worst-case run-time complexity of your algorithm and prove the optimality of the solution it gives.
Assume that the road is a straight line with a western end and an eastern end. The input would be the distance of each house from the western end. A sample input would be:
House number 1, 2, 3, 4 ,5 ,6 ,7 ,8, 9 ,10, 11, 12, 13 ,14, 15
Distance 10, 36, 21, 30 ,47, 44, 16 ,31, 25, 54, 13, 39, 6 ,19, 53
Explanation / Answer
Please Rate:Thanks my friend u can tell that`s it is dynamic programming and graph algorithms can work if we took every comuter as a node and u can travel from every node to some node with some cost u will enter them into a table and map inisde the table and sum the minumum sum for it i will explain a program nearly like it u can change it the way u wantthe problem i like this http://livearchive.onlinejudge.org/external/49/p4967.png u can go from each node to the nodes around it and u will find the mimunm cost between them this program will find it u can understantd it tell me if there s something u do`nt understand message me the program below will take this as input first the number of rows then the cost for each node eg: 3 1 9 4 1 5 5 1 1 1 the answer is 4 #include #include #include #include using namespace std; int main() { int temp[4]; int input,n; int count_input=1; cin>>n; while(n!=0) { // int *came_from; vectorcost; maptable; // came_from=new int[n*3]; cost.push_back(0); for(int i=0;i>input; cost.push_back(input); } //came_from[0]=0; table[1]=cost[1]; // came_from[1]=0; table[2]=cost[2]; // came_from[2]=0; table[3]=cost[3]+table[2]; // came_from[3]=2; if(n>1) { table[4]=cost[4]+table[2]; // came_from[4]=2; } int counter=2; int min; for(int j=5;j
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.