A Pizzeria offers M different kinds of pizzas (let’s assume that the pizza kind is a number between 0 and M-1). In order to serve its clients quickly, the pizzeria cooks pizzas in advance. Let’s say that at a given moment, the pizzeria has N pizzas ready of different kinds, with N>>M. When a client orders a pizza of a given kind, it receives the pizza of that kind that has been cooked since the longest time (to avoid wasting pizzas). A client has also the possibility of ordering a surprise pizza, that is the client does not choose the kind of pizza but gets the pizza at a lower price. In that case, the pizzeria gives to the client the oldest pizza of all pizzas prepared.
Please Write an algorithm, for each of the following operations:
addPizza(kind)
getPizza(kind)
getSurprisePizza()
Determine the Big Oh running time for each implementation of these operations.
Notes:
For full marks the time of each operation should not depend on the total number of pizzas N; otherwise, the maximum will be 4 marks. You may use other data structures seen in class to implement your data structure. You can write your algorithms in pseudocode or Java-like code. You may call system.currentTime() when you create a pizza. You may assume the existence of a class Pizza with the following methods: getKind() getTime().