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
The first row of a table is often called the _____ row.
satela [25.4K]

ANSWER:

The first row of a table is often called the header row.

~batmans wife

7 0
3 years ago
Read 2 more answers
A system that organizes and controls website content and can include features that help team members work together on webpages a
BlackZzzverrR [31]

Answer:

A system that organizes and controls website content and can include features that help team members work together on webpages and other documents is referred to as a​ __groupware__ system.

Explanation:

Groupware is also know as collaborative software. This software allows multiple people to works collectively in solving a problem. It helps solving problems in an easier and in an efficient manner, because anyone in the group can solve it. It is a sort of group/team work.

3 0
3 years ago
What is the recommended solution to configure this automated behavior? UC has a requirement that an opportunity should have a fi
Dmitry_Shevchenko [17]
The answer will need to be workflow.
8 0
4 years ago
Match each operating system drawback to its respective operating system.
Lena [83]

Answer:

Microsoft Windows - More susceptible to viruses

Linux - Limited support system

Apple - Fewer compatible applications

Explanation:

Generally windows is more susceptible to viruses.

Linux is open source meaning it's up to the community to help you.

Apple has been supporting more applications in these coming years but it still lacks the wide range of apps windows supports.

4 0
3 years ago
Read 2 more answers
Importance of computer education​
Stells [14]

Answer:

hope this helped

Explanation:

Computer technology has helped the world to grow and evolve quickly. By performing tasks quickly, computers make daily activities more convenient. They give people access to a wide array of information and can reach even the most remote locations on the planet.

6 0
3 years ago
Other questions:
  • Complete the function ConvertToFeetAndInches to convert totalInches to feet and inches. Return feet and inches using the HeightF
    5·1 answer
  • A network TAP serves what purpose on a network?
    7·1 answer
  • If there is no index.html file in the root folder nothing will be displayed when you navigate to the site address
    14·1 answer
  • Microsoft windows is the least used operating system true or false?
    15·2 answers
  • Edhesive silly questionsj
    8·1 answer
  • Which is the most common drive letter where Windows stores most data and programs? A. A B. B C. C D. E
    12·2 answers
  • What are the pros and cons of the internet’s ability to access information
    8·2 answers
  • In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or
    15·1 answer
  • How do you create a IOS app?
    12·1 answer
  • Jason is working on a Microsoft Excel worksheet and he wants to create a Print Preview shortcut. His teacher asks him to access
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!