C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
Transcribed Image Text:Consider a list of n unique ordered integers, where you are allowed
to remove m of them. The goal is to maximize the distance between the
remaining closest numbers. As an example, consider the list [1, 4, 5, 6, 8, 9],
where we are allowed to remove two numbers. Here, an optimal solution would
be to remove the numbers 5 and 8, leaving us with the list [1,4,6,9]. The
distance between the closest remaining numbers is 2 (between 4 and 6). The
proposed greedy algorithm to this problem is to take a pair of numbers which
are currently closest together and remove the one which would result in the
better solution. Using [1, 4, 5, 6, 8, 9] again as an example, the greedy algorithm
would look at one of the closest pairs of numbers (4,5), (5,6) or (8,9). Without
loss if generality assume it examines the pair (4,5), 5 is closer to 6 than 4 is to
1, so the algorithm would choose to remove 5, leaving the list [1,4,6,8,9]. The
algorithm would then look again at a closest pair of numbers, (8,9) and remove
8, terminating to the solution [1,4,6,9]. Prove or disprove the optimality of
this algorithm.
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
Step by stepSolved in 2 steps
Knowledge Booster
Background pattern image
Recommended textbooks for you
- Text book imageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningText book imageOperations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks ColeText book imageProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage