Create greedy algorithm to find market to buy apples

Assignment Help Data Structure & Algorithms
Reference no: EM1367292

Suppose we drive a pickup truck from city A to city B. Along the high way, we will go through n apple markets, labeled with 1, 2, ..., n, where you can buy or sell apples. City A and city B also have an apple market each. For convenience, we label city A with 0 and city B with n+1. From a customer point of view, the buying price B[i] and selling price S[i] (dollar per pound) at market i are known. An example with n = 4 is given below.

Now, we will stop at one of the stations to buy apples and then stop at another station to sell apples. Please design an O(n) greedy algorithm to find market i to buy apples, and find market j i to sell apples such that the profit will be maximized. We assume that it would be too costly and forbidden to drive backward. In the above example, the best result is to buy apples at market 3 and sell them at market 5 with profit of (7-2 = 5) dollars per pound. It is allowed that i = j which means you buy and sell apples at the same market i.

 

Reference no: EM1367292

Questions Cloud

Determine the factors that affect dollar yen exchange rate : n the flexible exchange rate system, discuss the effects of the following events on the exchange rate between U.S. dollar and Japanese Yen: Please indicate whether US$ will appreciate or depreciate.
By what percentage must the tension in the string be changed : A hot (70°C) lump of metal has a mass of 250g and a specific heat of 0.25 cal/g°C. John drops the metal into a 500 g calorimeter containing 75g of water at 20°C.
Concept to analyze nursing profession : Give a brief example of a concept to analyze in our nursing profession (example: caring, healing, comfort, diversity). Briefly outline the steps in the analysis of this concept.
Clarification of marginal cost : Demand for DVD rentals at a video store is described by the equation: Q= 4,000-500P, where Q denotes the number of DVDs rented per week and P is the rental price in dollars.
Create greedy algorithm to find market to buy apples : Assume we drive pickup truck from city A to city B. Along high way, we will go through n apple markets, labeled with 1, 2, ..., n, where you can buy or sell apples. which means you buy and sell apples at the same market i.
Determine the mechanical energy of the system : A block-spring system oscillates with amplitude of 3.70 cm. The spring constant is 250 N/m and the mass of the block is 0.500 kg.
Concepts of scarcity and opportunity costs : Could you identify and describe the concepts of scarcity and opportunity costs. Also, explain the laws of supply and demand and how they are related to the concepts of scarcity and opportunity costs in decision-making.
What is the minimum value of the acceleration : A force vector has a magnitude of 590 newtons and points at an angle 44o of below the positive x axis. What is (a) x scalar component and (b) y scalar component of the vector.
Assess or evaluate problem-solving skills : Discuss how you might assess or evaluate problem-solving skills and critical thinking skills for nursing students.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd