CS 2223 Oct 27 2015
Lecture Path: 01
Next
Expected reading: Today is only day that you will have no expected readings
Expected demonstration: None
Daily exercises: None
For the remainder of this course, I expect you to have completed all readings and demonstrations prior to the start of the lecture on which they are listed.
Before presenting this lecture, I will review the course structure.
Diamonds are found only in the dark places of the earth, truths are found only in the depths of thought.
Victor Hugo
Les Miserables
1 A Journey Of A Thousand Miles Begins With A Single Step
A perfect algorithm is like an artistic study in miniature. Consider the amazing portrait of Ginevra de’ Benci by Leonardo da Vinci [1474/1478]
Figure 1: Portrait of Ginevra de’ Benci
Leonardo da Vinci painted this portrait – only 15x15 inches in size – when he was just 21 years old. It signaled a revolution in portraiture, fundamentally changing the way artists approached the subject. There is nothing extra in this artwork. Every brushstroke is meaningful and I encourage you to "zoom in" on the portrait. Click on the link below the image and you will be brought to the National Gallery of Art web site where you can click on the image there to explore. Right-click to see the mouse commands; you can double-click to zoom in and then move around to see the incredible detail of the picture.
Now let’s look at another elegant miniature, this time the BINARY ARRAY SEARCH algorithm which determine whether a sorted collection contains a target item. Here is a description from Jon Bentley’s amazing book, Programming Pearls:
Binary [Array] Search solves the problem [of searching within a pre-sorted array] by keeping track of a range within the array in which T [i.e. the sought value] must be if it is anywhere in the array. Initially, the range is the entire array. The range is shrunk by comparing its middle element to T and discarding half the range. The process continues until T is discovered in the array, or until the range in which it must lie is known to be empty. In an N-element table, the search uses roughly log2(N) comparisons.
This algorithm, so briefly stated, is the foundation of so many efficient algorithms. Easily stated, but not so easily implemented. Bentley reports that given this description, 90% of professional programmers are unable to code this algorithm given several hours. What follows is a Java implementation:
BINARY ARRAY SEARCH
I identify algorithms by name in the margin using ALL CAPS.
Just Like Owen Meany would do.
Given the above program, I have some simple questions to ask:
Important questions are hilighted in orange. Pay attention to these!
Is the while loop guaranteed to terminate?
How many times will the while loop execute?
Can you prove this code is correct?
By the end of this course, I want all students to appreciate the elegance and beauty of this algorithm. Its simplicity is legendary. And just as important, one needs correct implementations that are validated to handle all cases, especially the boundary cases that make it hard to translate algorithms into code.
1.1 Definition
An Algorithm is a finite, deterministic and effective problem-solving method suitable for implementation as a computer program.
This course is the study of algorithms, which are the fundamental building blocks of computer science.
1.2 Science
So says Wikipedia
This course, CS 2223 Algorithms, aims to introduce you to the study of the fundamental concepts that relate to computational structures, otherwise known as computer programs. In this course, we are concerned both with ideas and the functional expression of those ideas as computer programs. In this course, we are glad when a computer program produces the correct answer to a problem, but we are excited when we can prove statements about the problem that help us predict the runtime performance of any implementation in any programming language that attempts to solve the same problem.
In presenting the domain of algorithms I would like to remind everyone of similar efforts made by countless scientists over the centuries. For example, what is so special about the following organism?
Figure 2: Drosophila melanogaster
In this course, we will study a number of fields in computer science that might not seem interesting. Consider the task of sorting in ascending order a collection of arbitrary values. The Sorting domain is one of the most studied fields in all of computer science. Advances in understanding how to write efficient sorting code has led to a deep understanding of Divide and Conquer algorithms.
1.3 Scientific Method
Never forget that this is a computer science class. We approach computational structures with the mind of a scientist. That is:
Make Observations – Instead of reflecting natural phenomena in the world around us which already exist and are waiting to be observed, we must create computational structures or programs.
Form Hypotheses – We will focus our attention on the runtime performance of programs on specific classes of input. Note there are many other kinds of questions one could ask (i.e., how hard will it be to maintain this program?).
Develop Testable Predictions – These hypotheses are used to predict the performance of a program on larger input sizes. The typical scenario is to estimate the cost when doubling the size of the input.
Gather Data to Test Predictions – You create test cases to validate the correctness of the program. Then you create performance test cases to evaluate runtime performance
Develop General Theories – By observing numerous computational structures you can develop theories about different approaches. These theories lead to well-designed solution familes, such as Divide and Conquer or Greedy.
1.4 Skills
The entire course is focused on learning specific skills in algorithms.
Mathematical – Knowledge and ability to use mathematical tools to analyze and prove statements about algorithms.
Data Structures – Knowledge and ability to work with the fundamental data structures in computer science. This work is performed on mutable data structures, which differs from what you may have done in CS 2102.
Algorithm Families – Knowledge of key algorithmic families. Ability to analyze performance and correctess of algorithms. Ability to implement and benchmark performance of algorithms.
1.5 Daily Exercises
Each day I will present you with the opportunity to exercise and further develop your problem solving skills. These daily exercises are intended to give you the chance to spend 20 minutes or so thinking about a problem and trying to solve it. I truly believe that you can improve your problem solving abilities with daily practice. I can’t grade these daily questions, though I will post my own solutions at the start of the next class so you can review your answer.
1.5.1 Word Scramble
You may find yourself stuck trying to work out some tricky bit of logic. Instead of trying to solve the problem "all at once" you need to make smaller progress or try to decompose the problem into a smaller one. Try your skills at this question:
Rearrange the following letters to form a single English Word.
DRY OXTAIL IN REAR
Take notes in your course notebook as you attempt to solve the
problem. Solution will be shown tomorrow.
1.5.2 Closed form formulas
In this course you will become familiar with mathematical tools used to analyze the performance of algorithms. Try your skills at the following question. Later in the course I will conduct similar analyses for algorithmic questions:
You should be familiar with the Fibonacci numbers,
designated as Fn. Start with F1=1 and
F2= 1. The closed formula for the nth Fibonacci
number Fn is: Fn=Fn-1 +
Fn-2.
Your challenge is to compute a formula that represents the sum of the
Fibonacci numbers. That is, Sn = Σ Fi for
i=1 to n.
To get you started, the first few terms of Sn are 1, 2, 4,
7, 12, 20, 33, 54, 88, 143, ...
You should be able to define a formula for Sn that is
recursively defined, much like Fn is defined. Take notes in
your course note book as you attempt to solve this problem.
1.6 Preparing for Oct 29 2015
Be sure to complete the readings for today as well as Oct 29 2015. As mentioned in class, for each of the following lectures, I have designated a list of 14-18 pages that you must read prior to coming to class. In addition, please review the lecture notes which you can find here 24 hours before the lecture itself.
See if you can answer the following questions. You are given an array of N unique integers.
What is the fewest number of comparisons to determine the largest integer in an array of n>1 elements. Can you prove this?
What is the fewest number of comparisons to determine the largest and the 2nd largest integer in an array of n>2 elements. Can you prove this?
1.7 Four Things To Do Today!
Pick up a course notebook that you can/should use for your class notes as well as ideas towards your homework assignments. We will also use these for in-class activities, so be sure to bring to each class.
I need video tape of everyone in the class. I will ask you to face the camera and state your full name (first and last) and then you will spell your last name. This is how I get to know who you are.
Install Eclipse (Luna | Mars) if you don’t already have one installed. The Mars version was released this past June and I usually wait six months before installing the latest version, so I still use Luna.
Make sure you have account on fusion.wpi.edu. Your CCC account credentials will get you in, with no problem.
Within Eclipse, use Git to retrieve the code that I will be using for the course. I will be populating this repository with additional code and examples. Use repository https://fusion.wpi.edu/anonscm/git/cs2223/cs2223.git.
I have posted a video if you have questions
Ok, so that list contains five things. Oh well. See you next class!
1.8 Version : 2015/11/03
(c) 2015, George Heineman