CS 226 Homework 3 Written : Due Friday February 16 (in class) (NOW DUE FEB. 19th) Programming : Due Monday Febrary 19. Written: Do C-4.2, C-4.11, and C-4.12 The correct version of C-4.2 is: Describe an efficient algorithm for finding the ten largest elements in an array of size n. What is the running time of your algorithm? Programming: In class, I described an application where singly linked lists were used to keep track of the free tables in a restaurant. Implement a restaurant simulation along these lines as follows: 1) Create a class for tables (called Table) that contains three fields: table ID number, server name, and number of seats. Make sure you have methods that create this data structure, set all fields, and project out all fields. Also make sure it has a ToString function. 2) Create a TableNode data structure that is appropriate to create a singly linked list (model it after the Node class on page 116). 3) Create a singly linked list class for tables that supports the following functionality: a. addTable(TableNode e): adds a table to the beginning of the list b. findTable(int numberofSeats): finds the smallest table available that can accomodate the requested number of customers, or returns null if there is no such table. Analyze the worst-case asympototic complexity of this function and include the analysis in the comments to the function. c. removeTable(int tableIDNumber): remove the table with the given ID from the list; generates an "InvalidArgumentException" if the table is not there. 4) Finally, create a class TableSimulator that does the following: a) Creates - a list called FreeTables - a list called TakenTables - an array of three lists called OccupiedTables modeling three servers - an array of three Strings with the server names, 'Larry', 'Moe' and 'Curley' At the start, FreeTables contains 5 tables of size 2, 4 tables of size 4, and 3 tables of size 6. b) Simulates a restaurant as follows: At each iteration, it flips a coin to decide if a new customer has arrived. If so, it randomly picks a party size from 1 to 6. It then looks for a free table. If it finds one, it randomly assigns the table to a server (i.e. randomly chooses a number from 0 to 2) and puts the table into that server's list. It also puts the table on the OccupiedTables list. It then prints out "Table x for a party of y was assigned to server z." where x is the table ID, y is the size of the party, and z is the name of the server. If no free table is found, it prints "A party of x was turned away." where x is the size of the party. Finally, it generates a random number n between 0 and 20. If n is smaller than the size of the occupied list, it puts all tables from entry n and beyond back onto the FreeTables list, including freeing them from their respective Server's lists, too. For each such table it prints "Table x paid and left." c) Run your simulation for 100 time steps. d) Print out each of the final lists when you are done.