Why your program should require o(logn) time per order

Assignment Help Basic Computer Science
Reference no: EM13307262

The double action system operates as follows. When a new buy order of $x arrives it is simply stored for future use if none of the stored sell orders has an asking price lower than or equal to $x. Otherwise, the new buying bid is matched with the sell order with lowest asking price (earliest such order if there are ties). The two matched orders are removed from the system, and the buyer receives the item in exchange for paying a clearing price equal to the matched sell order asking price, i.e., the lowest asking price available at the time the new buy order was received.

Processing of a new sell order with an asking price of $y is done in a similar way. If all stored buying orders have a bid price strictly lower than $y, then no matches can be made and the new order is simply stored for possible future matching. Otherwise, the new sell order is matched with the stored buy order with highest bid price, handling ties as above. The two matched orders are again removed from the system, and the clearing price paid in this case is the bid price of the matched buy order, i.e., the highest bid price available at the time the new sell order was received. your program should require O(logn) time per order when processing a list of n orders.

Sample Input 1

order 1 sell at 30
order 2 buy at 20
Output for Sample Input 1

units exchanged 0 total clearing price 0
Sample Input 2

order 1 sell at 30
order 2 buy at 20
order 3 buy at 40
order 4 buy at 30
order 5 sell at 10
Output for Sample Input 2

units exchanged 2 total clearing price 60

Reference no: EM13307262

Questions Cloud

Determine her metabolic power : For exercise, a 60 kg athlete runs up a 10-m high hill in 30 seconds. Assume the efficiency of the human body is 25%. Determine her metabolic power
How the typical sources of business growth : Speculate on how the typical sources of business growth might evolve over the coming decade. Explicate how these changes might affect businesses in the industry you have selected for this course. Support your speculations with examples and discuss wh..
Create a student class which will contain the following : Demonstrate the correct working of your classes by reading in a collection of student records from a file, sort the records, and print them. If a name is "EOF" it will mark the end of the file.
Derermine the velocity and acceleration of point p : At the same instant the frame h, not the horizontal blade, rotates about a vertical axis with a constant angular velocity w=0.9 rad/s, measured relative to h
Why your program should require o(logn) time per order : The double action system operates as follows. When a new buy order of $x arrives it is simply stored for future use if none of the stored sell orders has an asking price lower than or equal to $x.
Determine the time it takes for the light to strike ground : Falling light. According to general relativity and the equivalence principle, light is bent by gravity. Determine the time it takes for the light to strike the ground
What was the initial concentration of cocl2 : What was the initial concentration of COCl2?
Particle of mass m in a uniform gravitational field : Consider a particle of mass m in a uniform gravitational field. Its potential energy is E(h) = mgh,where h is the height above sea level and g is the earth's gravitational constant, g = 9:8 m/s2.
Determine the distance that a particle on the rim moves : The flywheel of a prototype car engine is under test. The angular position of the flywheel is given by x = (3.0rad/s3)t3 and the diameter of the flywheel is 36cm.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Write a statement that assigns true to recalled

A bool variable named recalled has been declared. Given an int variable modelYear write a statement that assigns true to recalled if the value of modelYear falls within the recall range and assigns false otherwise. Do not use an if statement in th..

  Becoming cluster master and successfully

HCHLock lock, what will happen if the time between becoming cluster master and successfully splicing the local queue into the global queue is too small? Suggest a remedy to this problem.

  What would be the largest number of frames lost

Assuming PPP-like framing, what would be the largest number of frames lost at the receiving end if one if the flag bytes were changed due to error. The only error that can occur is a single flag byte turning into a non-flag byte. Explain your answ..

  Itsec measurably show practical effectiveness of security

To what extent does ITSEC quantitatively and measurably illustrate practical effectiveness of the security measures it mandates?

  How could a business use information technology

How could a business use information technology to increase switching costs and lock in its customers and suppliers? Use business examples to support your answers

  Confidentiality and integrity for transaction to secure

Make a list of at least 10 confidentiality, integrity, and availability requirements which should be met for transaction to be secure.

  Explain copyright implications for web site development

Study and explain copyright implications associated to Web site development. Write down the minimum of 350 words expalining the implications of copyrights on usage of content on Web site.

  How to restore and recover your database

Because of the nature of this lab, it is best to do the lab in one sitting. This will minimize the possibility of causing a problem with the database.

  What is the name of the keyboard

research the Internet and find out all that you can about the keyboard layout that you are using. Then write me a one page essay on what you found.

  Design an application to take and process a pizza order

Design an application to take and process a pizza order. The user should be able to make pizza order choices from listboxes, and the application should display the order price.

  Design a class numbers

Design a class Numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number.

  Determine the mix of cargo

The load master for a freighter wants to determine the mix of cargo to be carried on the next trip. The ship's volume limit for cargo is 100,000 cubic meters, and its weight capacity is 2,310 tons.

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