1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Viktor [21]
3 years ago
8

Greedy Algorithm Design

Computers and Technology
1 answer:
Alik [6]3 years ago
8 0

Answer:

The algorithm is as follows:

1. Start

2. Get the number of items (n)

3. Get the current price of the n items (a1, a2..... an)

4. Get the possible hiked price of the n items (b1, b2..... bn)

5. Calculate the difference between the current and hiked prices for each item i.e. d_i = b_i - a_i

6. Sort the differences in descending order (i.e. from the greatest to the least)

7. Buy items in this order of difference

8. Stop

Explanation:

The algorithm is self-explanatory; however, what it does is that:

It takes a list of the current price of items (say list a)

E.g: a = [100, 150, 160]

Then take a list of the hiked price of the items (say list b)

E.g: b = [110, 180, 165]

Next, it calculates the difference (d) between corresponding prices d_i = b_i - a_i

d = [(110 - 100),(180-150),(165-160)]

d = [10,30,5]

Sort the difference from greatest to lowest (as the difference is sorted, lists a and b are also sorted)

d = [30,10,5]

a = [150, 100, 160]

b = [180, 110, 165]

If there is no hike up to item k, the couple would have saved (i = 1 to d[k-1])

Assume k = 3

The couple would have saved for 2 item

Savings = d[1] + d[2]

Savings = 30 +10

Savings = 40

The saved amount will then be added to the kth item in list a i.e. a[k](in this case k = 3) in order to buy b[k]

Using the assumed value of k

a[k] = a[3]

a[3] = 160

b[3] = 165

Add the saved amount (40) to a[3]

New\ Amount = 40 + 160

New\ Amount = 200

This new amount can then be used to buy b[3] i.e. 165, then they save the change for subsequent items

You might be interested in
When using a spreadsheet, sum in the expression =sum(b10:b16), is called a(n) ________?
Marianna [84]
It is called a function.
4 0
3 years ago
Information systems include all of these
Ulleksa [173]

Answer:

D

Explanation:

because you need people to access software through hardware and data through information and procedures.

4 0
3 years ago
In the context of the components of a typical expert system, _____ is a software package with manual or automated methods for ac
Pani-rosa [81]

Answer:

knowledge acquisition facility

Explanation:

In the context of the components of a typical expert system, Knowledge acquisition facility is defined as that component of an expert system that is responsible for providing an effective and efficient medium for collecting and incorporating relevant information such as data, new rules, relationships and facts used by the expert system.

6 0
3 years ago
How Charles Babbage Concept of<br>Computer has help the modern<br>Computer​
OLga [1]

English mathematician and inventor Charles Babbage is credited with having conceived the first automatic digital computer. During the mid-1830s Babbage developed plans for the Analytical Engine. Although it was never completed, the Analytical Engine would have had most of the basic elements of the present-day computer.

6 0
3 years ago
One lap around a standard high-school running track is exactly 0.25 miles. Write the function miles_to_laps() that takes a numbe
Cerrena [4.2K]

def miles_to_laps(mi):

   return f"{mi} mile(s) is {mi/0.25} lap(s)"

print(miles_to_laps(1))

I wrote my code in python 3.8. I hope this helps!

6 0
3 years ago
Other questions:
  • At the end of your presentation, the main points should be a. Summarized c. Handed to your teacher b. Written on the board d. Re
    7·2 answers
  • One important inheritance characteristic is that all entity subtypes inherit their ____ key attribute from their supertype. prim
    9·1 answer
  • What are two ways to access the options for scaling and page orientation? click the home tab, then click alignment, or click the
    10·1 answer
  • 2.24 Write the relevant Python expression or statement, involving a list of numbers lst and using list operators and methods for
    11·1 answer
  • Which of the following technologies allows you to decouple the physical storage hardware from the storage requirements of the ap
    6·1 answer
  • Dusk is considered “a magic hour” by photographers and is the time when light is the least harsh. True or false.
    12·2 answers
  • Someone pleaseee answer my last question i just posted ;-;
    6·2 answers
  • Explain Spreadsheet and its Basics
    13·1 answer
  • ____ loses data when it stops receiving electrical power.
    10·1 answer
  • I have a .NET 6 basic website that I built using Entity Framework as the database for updating pages. I am ready to deploy the s
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!