Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3 ) We are given an array of integers stones where stones [ i ] is the weight of the i - th stone.

Question 3) We are given an array of integers stones where stones[i] is the weight of the
i-th stone. We are playing a game with the stones. On each turn, we choose the heaviest two
stones and smash them together.
Suppose the heaviest two stones have weights x and y with xy. The result of this smash
is:
If (x==y), both stones are destroyed, and
If (y is greater than x), the stone of weight x is destroyed, and the stone of weight y has a new
weight y-x.
At the end of the game, there is at most one stone left.
Write an algorithm using a priority queue to return the weight of the last remaining stone.
If there are no stones left, return 0. What is the time complexity of your program? Explain
your answer. what is the time complexity of your program?
(10 points)
image text in transcribed

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

5. How do instructional objectives help learning to occur?

Answered: 1 week ago