CS 2223 Mar 25 2022
Daily Exercise:
Classical selection: Rachmaninoff: Piano Concerto No. 2 [Kissin] (1901)
Visual Selection: Peasant Woman Binding Sheaves, Vincent Van Gogh (1889)
Live Selection: 25 or 6 to 4, Chicago (1970)
Daily Question: DAY08 (Problem Set DAY08)
1 Review of Linked Lists
Regarding the daily questions, be sure to take advantage of answering these questions daily as a way to verify you know the material. Remember, 5% of your total grade is based on answering these questions. It may very well be the difference between an A and a B for you:
I don’t believe in mathematics. Imagination is more important than knowledge
Albert Einstein
1.1 Manipulating an ordered linked list
Review OrderedLinkedList.
1.2 Instrumenting an algorithm
When I want to generate empirical evidence on the number of times a key operation is invoked in an algorithm, I instrument the code to maintain a class attribute to hold a running accumulated count. Whenever the operation is called, just increment this value, and make it possible to retrieve it later so you can report on it.
Review InstrumentedMerge to see how I did this for MergeSort.
1.3 Main topics in sorting
We have made some major progress in analyzing the sorting problem. From last lecture we were able to assert the Mergesort is an asymptotically optimal compare-based sorting algorithm.
We made this claim because we demonstrated that any comparison-based sorting algorithm requires ~ N log N comparisons to correctly sort an array of N elements.
The logic was based on identifying a recursive formulat that computed the number of comparisons required. We came up with the following formula that demonstrated the most number of comparisons that would be used.
C(n) <= C(n/2) + C(n/2) + N
C(n) <= 2*C(n/2) + N
Be sure you understand the logic as presented in lecture, which is supported by the book; review the class capture if that would be helpful.
1.4 Interview Challenge
Each Friday I will post a sample interview challenge. During most technical interviews, you will likely be asked to solve a logical problem so the company can see how you think on your feet, and how you defend your answer.
A plane with N seats is ready to allow passengers on board, and it is
indeed a full flight; every seat has been purchased. Each person has a
boarding pass that identifies the seat to sit in. When the announcement is
made to board the plane, all passengers get in line, in some random order.
The first person to board the airplane somehow loses his boarding pass as
he enters the plane, so he picks a random seat to sit in.
All other passengers have their boarding passes when they enter the
plane. If no one is sitting in their seat, they sit down in their assigned
seat. However, if someone is sitting in their seat, they choose a
random empty seat to sit in.
My question is this: What is the probability that the last person to
take a seat is sitting in their proper seat as identified by their boarding
pass?
1.5 Daily Question
The assigned daily question is DAY08 (Problem Set DAY08)
If you have any trouble accessing this question, please let me know immediately on Discord.
1.6 Version : 2022/03/28
(c) 2022, George T. Heineman