Create divide and conquer algorithm to solve problem

Assignment Help Data Structure & Algorithms
Reference no: EM1367204

1 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.

Also Design a divide and conquer algorithm to solve problem 2. The time complexity of your algorithm must be O(nlgn) or better.

Reference no: EM1367204

Questions Cloud

Find the height from the top : A flower pot falls from the roof and passes in front of a window of height h as it falls to the ground to smash to pieces. If the flower pot takes a time T to pass from top to bottom in front of window. Find the (as-yet-unknown) height H from the ..
Calculate contribution margin of the product : Ann Page Corporation has fixed expenses of $30,000 per year. Variable expenses per unit are $17. Sales price per unit is $30.
Intra-community territoriality : Territoriality of communities within communities often creates division and conflict. What is an example that reflects such intra-community territoriality?
Elucidate how income changes along demand curve : elucidate how income changes along demand curve and why a local builder seeking to maximize income on a small site would be interested in elasticity of demand.
Create divide and conquer algorithm to solve problem : Create a divide and conquer algorithm to solve problem. The time complexity of your algorithm must be O(nlgn) or better.
Breast cancer chemotherapy : For example, do you know any women who have had their breast cancer chemotherapy paid for by Avon? by Mary Kay? through a drug company?
Implication of demand of law : Your are the chief economic advisor to the King of Terra. The king has observed that while the price of energy has increased 20 percent over the past five years, consumers have actually increased their energy consumption by 10 percent over the sam..
Illustrate cost of good x to drive it to equilibrium : Find out QD and QS when cost of good X is $12.00. Is re a surplus or shortage. Illustrate what should happen to cost of Good X to drive it to Equilibrium.
Flexible exchange rate system : Suppose that expectation of reducing housing values cause households to decrease their demand for new houses and the financing that accompanies it.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Find shortest path tree by bellman-ford-dijkstra algorithm

Find the shortest path tree from every node to node 1for the graph of following figure using Bellman-Ford and Dijkstra algorithm.

  Write algorithm find intersection of two singly-linked list

Write an algorithm (pseudocode) to find the intersection of two singly-linked lists. Assume that the data in each list are in nondecreasing order.

  Algorithm for finding smallest element in unsorted array

Consider the following algorithm for finding the smallest element in an unsorted array: RANDOMMIN(A[1 .. n]). What is the exact expected number of executions of line ( )?

  Users and it organizations arm against phishing attacks

How users and IT organizations must arm themselves against these attacks?

  Generalize 2-3 algorithms for insert and delete

Generalize the 2-3 algorithms for INSERT and DELETE to K-J trees, where non-leaf vertices have between K and J children for fixed integers K >=2, and J>= 2K-1.

  Primitives-remove ambiguities in algorithm-s representation

Describe how the use of primitives helps remove ambiguities in an algorithm's representation.

  Devise ef?cient algorithm for computing probability

Given the probabilities r1, · · · , rn, the costs c1, · · · , cn, and the budget B, ?nd the redundancies m1, · · · , mn that are within the available budget and that maximize the probability that the system works correctly. Devise an ef?cient algo..

  Addition and subtraction of numbers in binary

Addition and Subtraction of numbers in binary and round to the nearest decimal number with three significant decimal digits

  Computing minimal length of key-average cracking time given

If Encrypt-It-Rite would like to increase average cracking time to at least 100 years, determine the minimal length of the key?

  C++ program to evaluate expressions combining set union

Create a C++ program to evaluate expressions combining set union, set intersection and parentheses

  Sort array of elements using the quick sort algorithm

"sort an array of 10,000 elements using quick sort algorithm as follows: sort the array using pivot as middle element of the array

  Program for stack by using dynamically allocated array

Write a C++ class which implements stack by using a dynamically allocated array. Initial size of particular stack must be determined when it is created.

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