Original array in place in time nk log

Assignment Help Macroeconomics
Reference no: EM131214730

1. Acme company buys and sells oil futures over the Internet. Its trading system receives buy orders from customers that seek to buy from the company. Each order has a bidding price. Orders may be deleted by the customer at any point in time and new orders may also come in at any time.The trading desk would like you to implement a system that keeps track of the top 100 highest buy orders at any point in time.You decide to build a data structure that has two parts: Minheap M of the top 100 orders, and a maxheap H that stores the remaining orders. The contents of the minheap are then displayed to the trading desk, whenever demanded.You are allowed heap operations: (a) min(M): returns the minimum element of a minheap M,(b) max(H): returns the maximum element of maxheap H, (c) insert(G,x): insert the element x in heap G and (d) delete(G,i): delete the ith element G[i] from heap G.Write down pseudocode for how you would update the M and H, under the following situations.Also, write down the worst-case running time in terms of the number of orders n that are currently active. You can assume for simplicity that n 100.

(A) A new order with price $B arrives. (Hint: You will first have to decide if the price is a top 100 price or not. Based on that you have to perform the appropriate heap operations).

(B) The top 100 order M[i] is withdrawn by the customer

2. An array is almost k sorted if every element is no more than k positions away from where it would be if the array were actually sorted in an ascending order.

(A) Write down pseudo code for an algorithm that sorts the original array in place in time nk log(k).Your algorithm can use a function sort(A, l, r) that sorts the subarray A[l], . . . , A[r].

(B) Suppose you are allowed extra array of size k + 1 on the side. Modify heap sort using a minheap of size k + 1, to sort the given array in time n log(k). (Hint: Take the first k + 1 elements and make a min heap. Keep extracting the minimum element from this min heap and adding anew element from the original array.).

Reference no: EM131214730

Questions Cloud

Where do the voltage maxima and minima in occur : Application: Standing wave ratio and minima and maxima on the line. For a line with characteristic impedance Z0 = 50 Ω and a load R = 220 Ω
Find the pm : Highway A and Highway B merge to form Highway C - Find the PM.-  Is also a Poisson random varialbe or does it follow some other distribution?
What are the uses of context free grammars : What are the uses of Context Free Grammars? What are the applications of Context Free Languages?
Find the maximum and minimum voltage on the line : If the voltage at the load is 100 V, find the maximum and minimum voltage on the line.
Original array in place in time nk log : Write down pseudo code for an algorithm that sorts the original array in place in time nk log(k).Your algorithm can use a function sort(A, l, r) that sorts the subarray A[l], . . . , A[r].
Identify various social trends that affect marketing : To complete this assignment, students must prepare a real-world marketing news example, event, or success story and communicate it to the class. Students should use popular resources such as The Wall Street Journal, Bloomberg Businessweek, Inc., e..
Analyse principles and trends in performance : Performance Management and Control - Identify and critically analyse principles and trends in Performance Measurement and Control and Determine the different budgeting techniques and critically evaluate their use in short term decision making
What mechanism is responsible for the formation of products : If k1 > k2, is the overall reaction SN1 or SN2? Research and Explain what chemical mechanism is responsible for the formation of the products.
Calculate and plot the line impedance as a function : At the frequency at which the line operates, the reactance of the load is -j50 Ω and the phase constant on the line is 20π rad/m. Calculate and plot the line impedance as a function of distance from load.

Reviews

Write a Review

Macroeconomics Questions & Answers

  Inflation targeting be a good policy

Why might it be difficult for the Fed to formally adopt inflation targeting?  Would inflation targeting be a good policy for the Fed in the present economic environment

  In using the taylor rule

In using the Taylor Rule as a guideline for monetary policy, what are the pros and cons of using forecasted values of inflation and output rather than observed values of these variables?

  Describe the present economic crisis situation in europe

Describe the present economic crisis situation in Europe.  Why has it been so difficult for the Europeans to find a solution to this problem?   Comment on what implications the crisis may have for the rest of the world if Europeans are not able to ag..

  Long-term federal government budget problems

Question:. Explain why there are long-term Federal government budget problems. Explain why the base-line forecast of the CBO is misleading.

  Derive and compare demand curve

Question based on Derive and compare demand curve,  Derive Ambrose's demand function for peanuts. How does it compare with Johnny's demand curve for peanuts?

  Problem based on utility function

Problem based on  Utility Function - Problem,  Answer and explain the following using a diagram which is completely labeled.

  Laffer curve : tax rate and tax revenue

Question based on Laffer Curve : Tax Rate and Tax Revenue,  Do raising tax rates necessarily raise tax revenue? What factors affect how tax revenue changes when tax rates change?

  Problem - income elasticity of demand

Problem - Income Elasticity of Demand,  Interpret the following Income Elasticities of Demand (YED) values for the following and state if the good is normal or inferior; YED= +0.5 and YED= -2.5

  Positive balance of payment

Question Positive Balance of Payment: "Things will look good for the US if we could just get to where we are consistently running a positive Balance of Payments."

  Effect of recession on the investment curve

Comment on the effect of a recession on the investment curve (only) and on the level of savings, investment, and the equilibrium real interest rate in the financial crisis that hits United States first starting in fall 2007.

  Affect of falling domestic investment on trade surplus and

How will a fall in domestic investment affect the trade surplus and net capital outflows in the domestic economy, the trade deficit and capital inflows in the rest of the world.

  Crises in the banking sector and bank run

Banking crises crisis decreases depositors' confidence in the banking system. What would be the effect of a rumor about a banking crisis on checkable deposits in such a country?

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