Question

Suppose you received a loyalty promotion that lets you purchase one item, valued up to $100,...

Suppose you received a loyalty promotion that lets you purchase one item, valued up to $100, from an online catalog. You want to make the best of the offer. You have a list of all items for sale, some of which are less than $100, some more. Write an algorithm to produce the item that is closest to $100. If there is more than one such item, list them all. Remember that a computer will inspect one item at a time––it can’t just glance at a list and find the best one.

just an algorithm does not have to be coded

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The algorithm will be

  1. Traverse the list and have a variable difference initialized to infinity
  2. for item in list
    • difference = min(difference,abs(getPrice(item)-100))
  3. Now difference will contain the minimum absolute difference between any item's price and $100
  4. Now again traverse the list and output all the items that have this difference
  5. for item in list
    • if getPrice(item)-100 == difference
      • Output item details

Do give a thumbs up and in case there are doubts leave a comment.

Add a comment
Know the answer?
Add Answer to:
Suppose you received a loyalty promotion that lets you purchase one item, valued up to $100,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • When Walmart sells an item for $100, what was their cost on that item? Do you...

    When Walmart sells an item for $100, what was their cost on that item? Do you have a number in your head? OK, now let’s find out. Here is a link to Walmart’s 2018 annual report. Walmart 2018 Annual Report Look on page 55 of the report (page 61 of the PDF) and you will find their income statement. You will see that their net sales for the year were $495,761 (that’s in millions; i.e. they left off six zeros,...

  • Suppose you want to buy an item whose current price is $1000. You consider the following...

    Suppose you want to buy an item whose current price is $1000. You consider the following two options. • Finance the item now, i.e. take out a loan for $1000 and buy the item immediately. The loan company charges 9% interest, compounded monthly, and they offer you a one year loan with payments due at the end of each month. • Create a sinking fund now and make monthly deposits (at the end of each month) for one year, then...

  • An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests...

    An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests the return value of floatLargestToTop0 to see if it can return "early".) Check all the true statements about the sort algorithm, i.e., the sort method and its support methods. (Check all that apply.) It will sometimes return (completely sorted) after only 99 data comparisons. It will always require at least one swap. It will always require at least 99 comparisons...

  • Need assistance responding to this DB post in personal opinion in 100 words The Internet has...

    Need assistance responding to this DB post in personal opinion in 100 words The Internet has afforded a wide opportunity to the consumer goods industry. As a result, consumers are going directly to the Internet to buy their basic and common necessities. Based on Parnell (2014), “As Internet usage expanded and capabilities and security grew more sophisticated, consumers learned to integrate technology into their daily lives” (p. 42). I include myself among the consumers for which these words apply. I’ve...

  • Can you answer only question 5and 6 Questions: 1. How could the promotion of UK Hoover...

    Can you answer only question 5and 6 Questions: 1. How could the promotion of UK Hoover have been better designed? Be as specific as you can. 2. Given the fiasco that did occur, how do you think Maytag should have responded? 3. Comment on the following statement: “Firing the three top executives of UK Hoover is unconscionable. It smacks of a vendetta against European managers by an American parent. After all, their only ‘crime’ was a promotion that was too...

  • Answer the case study questions please and thank you BUSINESS PROBLEM-SOLVING CASE Walmart Versus Amazon and...

    Answer the case study questions please and thank you BUSINESS PROBLEM-SOLVING CASE Walmart Versus Amazon and the Future of Retail Walmart is the world's largest and most success- ful retailer, with more than $485 billion in 2016 For online shopping, Amazon has some clea advantages. Amazon has created a rec sales and nearly 11,700 stores worldwide, including and highly successful brand in online retailing. The more than 4,600 in the United States. Walmart has company has developed extensive warehousing facili...

  • Standing in the showroom of a local appliance store, you realise the problem almost immediately. Virtually...

    Standing in the showroom of a local appliance store, you realise the problem almost immediately. Virtually all of the washers, dryers, refrigerators, freezers and dishwashers are white. It is tough to tell one company’s product from another, and the biggest signs in the place announce the low prices on this versus that model. This is the exact reason that Vortex’s senior management team developed the ‘brand-focused value creation’ strategy: to create innovative, branded solutions that consumers will find appealing, that...

  • There are two parts to this journal: 1. Create a one- two page contract for those...

    There are two parts to this journal: 1. Create a one- two page contract for those students you are a Peer Educator for explaining THEIR duties as a student and what you as a Peer Educator will do for them. Think of it as a Learning Agreement! You can format any way you like. 2. Briefly explain what a typical Peer Education session for you looks like. Do you use any of the mentions skills? How do you Peer Educate?...

  • This program will provide the user the tools to make up trains from a file of...

    This program will provide the user the tools to make up trains from a file of available cars. The car data will be the reporting identifier, car type, weight (in tons) and length (in feet) for each car. The user can select to make up a train by total weight, total length or car type. The user will be able to display any train’s consist, and will be able to delete a train (returning the cars to the pool of...

  • One day su 100 del Price in Passes sold Passes sold Type of Price in Total...

    One day su 100 del Price in Passes sold Passes sold Type of Price in Total Total 2010 2011 in 2010 in Revenue Revenue 2011 2010 2011 $22 32,000 1999 $152.000 $439,758 200 15000 Annual 9500 $1,500,000 $1,900,000 1. You have been assigned by the mayor to rise the rent on park district courses in order to generate more revenue. The tennis courts are located in an area where real estate serves at a premium and there is always activity...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT