Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS QUESTION MUST BE ANSWERED WITH CLEAR ENGLISH PSEUDOCODE! At a certain theme park there are n rides, numbered from 1 to n. Before you

THIS QUESTION MUST BE ANSWERED WITH CLEAR ENGLISH PSEUDOCODE!

image text in transcribed

At a certain theme park there are n rides, numbered from 1 to n. Before you can go on ride i you must pay its cost C[i] dollars, plus a deposit, D[i] dollars. This means you must have at least C[i] + D[i] dollars to go on the ride. Once you have finished the ride, D[i] dollars are returned to you, as long as you did not damage the ride! Careful Cheryl never damages any rides, and currently has T dollars on her. Cheryl woulod like to know the maximum number of different rides she can go on. She can go on rides iin any order she chooses. You may assume C[1..n] and D[1..n] are both positive integer arrays of length rn (a) Prove that, if an amount of money T is enough for Cheryl to go on some subset S of all the rides in some order, then she can go on the same subset S of rides in a non-increasing order of deposit D[i] (breaking ties arbitrarily). (b) Hence, design an O(n log n+ nT ) algorithm to determine the maximum number of different rides Cheryl can go on (c) Does an O(n log n + nT) algorithm for this problem run in polynomial time? Why or why not? (d) Design an algorithm for the same task, but which runs in time O(n2) At a certain theme park there are n rides, numbered from 1 to n. Before you can go on ride i you must pay its cost C[i] dollars, plus a deposit, D[i] dollars. This means you must have at least C[i] + D[i] dollars to go on the ride. Once you have finished the ride, D[i] dollars are returned to you, as long as you did not damage the ride! Careful Cheryl never damages any rides, and currently has T dollars on her. Cheryl woulod like to know the maximum number of different rides she can go on. She can go on rides iin any order she chooses. You may assume C[1..n] and D[1..n] are both positive integer arrays of length rn (a) Prove that, if an amount of money T is enough for Cheryl to go on some subset S of all the rides in some order, then she can go on the same subset S of rides in a non-increasing order of deposit D[i] (breaking ties arbitrarily). (b) Hence, design an O(n log n+ nT ) algorithm to determine the maximum number of different rides Cheryl can go on (c) Does an O(n log n + nT) algorithm for this problem run in polynomial time? Why or why not? (d) Design an algorithm for the same task, but which runs in time O(n2)

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_2

Step: 3

blur-text-image_3

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

15-5 How will MIS help my career?

Answered: 1 week ago