Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. This question is about the greedy approach to algorithm design. The stacking problem is concerned with stacking items on top of one another. Items

image text in transcribed
2. This question is about the greedy approach to algorithm design. The stacking problem is concerned with stacking items on top of one another. Items i have a weight w and a crumple strengths, which is the total weight that they can hold. A stack is a sequence of items lila, which represents item i on the top, then is, etc, down to eat the bottom The problem is to assess whether there is a stacking ordering of all the items so that every item has strength to hold all of the items on top of it. The following is proposed as a greedy algorithm for this problem: Consider items in order of smallest w + s (sum of weight plus strength). In each case add an item to the end of the stack sequence if the strength can support all of the items already in the sequence If there is not sufficient strength at any point then the algorithm returns "not possible". and the sequence of items obtained to that point (not including the item that did not have sufficient strength), If all items have been added to the stack then the algorithm returns "stacking possible", and the sequence of items obtained. (a) What is the time complexity of this greedy algorithm? [5 marks) (b) Apply the greedy algorithm to the following set of items. What does the algorithm return? Name B D E F Weight Strength 1 8 3 7 5 1 6 25 7 17 8 9 [10 marks] (c) If a non-crumpling stack contains X immediately before Y at some point in the stack. but with Sa+w. > 5,+ w. show that the same stack except with the positions of X and Y exchanged is also non-crumpling [10 marks] (d) Explain briefly (by considering inversions or otherwise) why the result of part (c) means that this greedy algorithm does indeed give the correct solution [5 marks] (e) if the algorithm terminates with not possible", then is it the case that the sequence returned is a maximal set of items that can be stacked without crumpling? Justify your answer [5 marks) 3

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

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

create simple design pieces exhibiting visual and rhetorical focus.

Answered: 1 week ago