Question

In: Computer Science

An Antique dealer needs to store records of the items in the inventory into a stack...

An Antique dealer needs to store records of the items in the inventory into a stack (the dealer believes that keeping items longer will be beneficial; nonetheless, the business logic here is not important!). Besides the usual push() and pop(); the dealer needs to always know what is the most expensive item in the inventory/stack. You are hired to implement a new method, called max(), which returns the current maximum value for any item in the stack. Notice that the stack grows and shrinks dynamically as elements are added or removed from the stack (i.e. the contents of the stack are not fixed).

a. Write the pseudocode of the max() method.

b. What is the Big-O complexity of your solution? Explain clearly how you obtained such complexity.

c. Is it possible to have all three methods (push(), pop() and max()) be designed to have a complexity of O(1)? If no; explain why this is impossible. If yes; provide the pseudocode of the algorithm that would allow O(1) for all three methods

Solutions

Expert Solution


Related Solutions

An antique collector takes data on 32 recently auctioned items. For each item the collector records...
An antique collector takes data on 32 recently auctioned items. For each item the collector records the selling price (Price), the age of the item (Age) and the number of bidders on the item (Bidders). The data appear in the Auction worksheet of the Simple Regression data workbook below. a) The collector believes that the older an item, the more bidders it will have. To evaluate this belief, draw a scatter plot of the data. Does there appear to be...
Secondhand Rose, an antique dealer, bought the full contents of an estate sale for $25,000 on...
Secondhand Rose, an antique dealer, bought the full contents of an estate sale for $25,000 on September 1, 2020. The purchase was paid for in cash, but Rose needed to pay a mover $575 to transport the items from Chatham, NJ to her warehouse in Flanders. Because some of the items from the sale were fragile, Rose purchased bubble wrap and other packing supplies at Staples for $200 on credit and purchased insurance on the transportation for $75. Rose also...
(a) Sally runs an antique store in Causeway Bay. One night, after closing of the store,...
(a) Sally runs an antique store in Causeway Bay. One night, after closing of the store, she brought all the cash received during the day to deposit into the bank. In a lane not far from her store, a man in black jacket suddenly rushed past Sally, pulled on her handbag to wrench it from her hands. Losing her bag, Sally immediately chased after the man. In desperate attempt to escape, the man kicked Sally vigorously. Sally fell on the...
Maria is the sole proprietor of an antique store that is located in a rented warehouse....
Maria is the sole proprietor of an antique store that is located in a rented warehouse. The business has a          $ 200,000 outstanding loan with the local bank but no other debt obligations. Last week, the loan, which has a monthly payment of $ 1,500, was not paid. There are no specific assets pledged as security for the loan. Due to a sudden and unexpected downturn in the economy, the store is just unable to generate sufficient funds to pay the...
Maria is the sole proprietor of an antique store that is located in a rented warehouse....
Maria is the sole proprietor of an antique store that is located in a rented warehouse. The business has a $ 200,000 outstanding loan with the local bank but no other debt obligations. Last week, the loan, which has a monthly payment of $ 1,500, was not paid. There are no specific assets pledged as security for the loan. Due to a sudden and unexpected downturn in the economy, the store is just unable to generate sufficient funds to pay...
Write a Python function that receives a stack object s, where the items in the stack...
Write a Python function that receives a stack object s, where the items in the stack are only numbers in the set {0,1} and returns the number of 1's in the stack s. The function must satisfy the following restrictions: the state of the stack must be preserved; ie., after calling this function the state of the stack s must be the same it was before the function was called. The function cannot use any additional variables of any of...
Sam's Corner Store has the following purchase and sales information for one of their inventory items:...
Sam's Corner Store has the following purchase and sales information for one of their inventory items: Date Units $/Unit. Total Feb   1 Opening inventory 10 $8 $80 Feb   9 Purchase 25 $9 $225 Feb 15 Sale 15 $15 $225 Feb 17 Purchase 20 $11 $220 Feb 25 Sale 10 $16 $160 Required: For (a) and (b) assume the company uses the periodic inventory system. (a) Calculate the gross profit if the company uses first-in, first-out (FIFO) (b) Calculate the value...
Sam's Corner Store has the following purchase and sales information for one of their inventory items:...
Sam's Corner Store has the following purchase and sales information for one of their inventory items: Date Units $/Unit Total Feb 1 Opening inventory 10 $8 $80 Feb 9 Purchase 25 $9 $225 Feb 15 Sale 15 $15 $225 Feb 17 Purchase 20 $11 $220 Feb 25 Sale 10 $16 $160 Required: For (a) and (b) assume the company uses the periodic inventory system. (a) Calculate the gross profit if the company uses first-in, first-out (FIFO) (b) Calculate the value...
Probability expected value exercises questions: 1. The owner of an antique store estimates that there is...
Probability expected value exercises questions: 1. The owner of an antique store estimates that there is a 50% chance she will make $3000 when she sells an antique cabinet, a 30% chance she will make $1550 when she sells the cabinet and a 20% chance she will break even when she sells it. What is the expected amount she will make when she sells the cabinet? 2. Three different people are selected at random and each given one gift card....
John works for an antique store and sells rare and valuable artifacts. He is a rational...
John works for an antique store and sells rare and valuable artifacts. He is a rational person who maximizes his expected utility and he is only interested on the artifacts monetary value. His utility function is given by u(w) = w½ = √w, where w is his wealth measured in million dollars. John has an initial wealth of w0 = 4 million dollars. While on holiday in Paris he finds in antique shop a small statue of a falcon, which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT