Intro
Intro
Text: 9 Algorithms That Changed The Future: The Ingenious Ideas That Drive
Today’s Computers
Final Grade Determination. Your grade for the course is determined by class par-
ticipation, homework and group projects. The distribution of grading for the course
is:
• Class Participation - 5%
• Quizzes - 15%
• Homework - 50%
• Midterm Project - 15%
• Final Exam - 15%
The in-class quizzes will be taken using the app Socrative which you will access
through your smart phone. Quizzes will be given almost daily and are typically given
at the end of each lecture. No make-up quizzes are given. For the in-class quiz
grade we average your top 20 quizzes so you are allowed to drop some scores. The
class participation portion of your final grade is determined by the percent of ALL
daily quizzes that you attempt. Your score on the quiz does not affect the class
participation grade; essentially we are using the quiz for attendance.
Assigned homework must be done individually and submitted by the due date unless
you are using your late homework days. You will have a total of 7 late homework
days throughout the semester unless extenuating circumstances arise. Weekly
homework assignments are typically available on Tuesdays and due on Thursday of
the next week. Homework assignments consist of problems similar to the examples
discussed in the lecture and assist you in understanding the material. You will be able
to drop one homework assignment during the semester.
The midterm project is much more involved than homework assignments and serves
to enhance or expand on the material covered in class. Consequently, students will be
expected to work on the project over a longer span of time. For each project, several
choices of topics will be suggested to accommodate the varied interests of students.
Students may work alone or in pairs on the project.
This course is approved to satisfy FSU’s Liberal Studies Quantitative/Logical Thinking
requirement.
Liberal Studies Rule: In order to fulfill this requirement the student must
earn a “C” or better in the course.
Some quotes about Computational Thinking
“Computational Thinking is the new literacy of the 21st century. The goal is for it
to be a fundamental skill used by everyone in the world by the middle of the 21st
century. Just like reading, writing and arithmetic.”
“Even people who aren’t going into computer science or engineering programs, should
be exposed to computer science. Programming teaches you how to take problems,
break them down into smaller problems, and solve them. Any kind of job that involves
problem solving can benefit from computing. ”
“I think everyone should get a little exposure to computer science because it really
forces you to think in a slightly different way, and it’s a skill that you can apply in life
in general.”
What is computational thinking? Who needs it? Why?
Computational Thinking is a problem-solving process that includes the
following characteristics.
Computational
Thinking
George Pólya
subproblem
subproblem
1. Make chocolate crust
2. Make mousse and chill
3. Wash & slice fresh strawberries
4. Whip cream
5. Make chocolate hearts
6. Assemble
Abstraction
Assume that the computer only has the ability to do addition and we
want to multiply something like
351.6 × 14
If you are looking up, e.g., Mike Shephard in the phone book then the
following would be an algorithm for finding the phone number.
Step 1 Open the phone book to the first page of names, i.e., the ones
beginning with “A”;
Step 2 Check to see if the name Mike Shephard is on the page;
Step 3 If the desired name is not on the page then go to the next page
and go back to Step 2;
If the desired name is on the page then write down the phone
number and stop because you are done.
If you implement this algorithm will you always find the desired phone
number? (Assuming Mike Shephard is listed in the book.)
Note that we also have a repeated loop, i.e., we keep doing steps 2 &
3 until we are done.
Now let’s look at how much work it takes to find the name Mike Shep-
hard using this algorithm.
• Assume that names beginning with “Sh” appear 81% into the book.
This means that if the phone book has 100 pages then “Shepard”
will appear on page 81.
• If the phone book has 200 pages then ‘Shepard” will appear on page
162 = .81 × 200 so we have to look at twice as many pages as when
the phone book had 100 pages.
• If the phone book has 500 pages then ‘Shepard” will appear on page
405 = .81 × 500 so we have to look at five times as many pages as
when the phone book had 100 pages.
• For obvious reasons, this is called a Brute-Force algorithm or the
Exhaustive search algorithm.
• If the phone book doubles in size the next year to 1000 pages and
“Sh” still appears 81% into the book, we have to look at 810 pages
before we find the phone number. If the book doubles again to 2000
pages then we have to look at 1,620 pages.
• This means that our work (i.e., the number of pages we must scru-
tinize) doubles as the size of the book doubles. This means that if
we represent the work in a graph, we will have a straight line. For
example, if x is the number of pages in the phone book and y rep-
resents the number of pages we have to look at then we write the
line which passes through any of the two points, say (500, 405) and
(1000, 810) so we have
810 − 405 405
y − 810 = (x − 1000) =⇒ y = 810 + (x − 1000)
1000 − 500 500
or
y = 810 + .81(x − 1000)
If there are only 100 pages in the book then y = 810+.81(100−1000) =
810 − .81(900) = 810 − 729 = 81 which agrees with what we said the
amount of work was for a 100 page phone book .
If we are looking for the phone number for Karen Allen then it will take
less work using this algorithm but if we are looking for Eric Yeager then
it will take more work.
amount of work
size of problem
What can we do to reduce the amount of work?
Consider the following algorithm which intuitively seems to cut the work
in half.
Step 1 Open the phone book to the first page of names, i.e., the ones
beginning with “A”;
Step 2 Check to see if the name Mike Shephard is on the page;
Step 3 If the desired name is not on the page then skip next page, go
to next page and then go back to Step 2;
If the desired name is on the page, write down the phone number
and stop because you are done.
Assume again that Shepard appears 81% of the way into a 500 page
book, i.e., Shepard appears on page 405.
pages pages
Step 1 discard
1-250 251-500
keep
pages pages
Step 2 discard
251-375 376-500
keep
pages pages
Step 3 keep
376-438 439-500
discard
pages pages
Step 4 keep
376-407 408-438
discard
Continuing in this manner, we narrow the search to the following num-
ber of pages
Step 5 376-391 392-407
Now what happens if the phone book doubles in size to 1000 pages and
the phone number is on page 810? Remember before that the work
doubled with the brute-force approach.
Step 1 1-500 501-1000
It turns out that the work required depends upon log N where N is the
size of the phone book. Now it’s not important whether you remem-
ber what a logarithm is, but it is important that you understand the
following plot where we plot the amount of work as the phone book
size increases for both the Brute-Force approach and the Divide and
Conquer approach. For any N > 1 log N is always smaller than N as
can be seen from the plot.
amount of work
e
rc
Fo
e
ut
Br
uer
Divide & Conq
size of problem
Computer Algorithms are Changing the World
How do you think algorithms & computers will change the the way we
live our lives in the next decades?
Reading Assignment:
Next time we will have a Socrative quiz so be sure and bring your
phones!
Let’s adjourn for some cookies and get to know each other!
1 Former Chairman of Computer Science at Carnegie Mellon University and currently Corporate Vice President of Microsoft Research
Introduction to Computational Thinking - Continued
Example. Suppose you are packing your backpack for a hike but you
have 6 items you are interested in taking but their total weight is 96 lbs.
The maximum weight you are willing to carry is 50 lbs. You assign each
item an importance value between 0 and 25; the higher the number the
more valuable. What items should you take?
Item A B C D E F
weight 30 28 15 10 9 5
value 16 25 24 15 12 2
For the first algorithm we simply pick an item at random and put in the
backpack. We then weigh the backpack and if it weighs < 50 lbs then
we pick another item. If it weighs more than 50 lbs then we remove
the last item and try another item at random.
Algorithm I - Random
Step 0 Compute the ratio of value/weight for each item. Arrange the
items in a selection pile in order of value from largest to smallest
ratios.
Step 1 Pick the next item in order from the selection pile and put into
the backpack. If there are no items left in selection pile you are done.
Step 2 Weigh the backpack.
If it weighs < 50 lbs, go to Step 1.
If it weights 50 lbs, you are done.
If it weighs > 50 lbs, remove item from backpack and selection pile
and return to Step 1.
Let’s try the algorithm to count the number of people (excluding in-
structor) in the class.
This algorithm does not require the room to have an even number of
people in it as the following schematic illustrates with 21 people. Here
it takes 5 loops (or recursive steps) to compute the algorithm.
Step 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Step 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
Step 3 2 2 2 2 2 2 2 2 2 2 1
Step 2 2 2 2 2 2 2 2 2 2 2 1
4 4 4 4 4 4 4 4 4 4 1
Step 3 4 4 4 4 4 1
Step 2 4 4 4 4 4 1
8 8 8 8 5 5
Step 3 8 8 5
Step 2 8 8 5
16 16 5
Step 3 16 5
Step 2 16 5
21 21
Step 3 21
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Step 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Step 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
At the end of the first recursive loop there are 21 people standing which
is the same number as in the previous example which took 5 recursive
steps so when we start with 42 people it takes one more step or 6 total.
The table below compares the number of people remaining after Step
3 is completed (when one member of each pair sits down) for different
size classrooms. Note that as in the Divide & Conquer algorithm the
work increases by one as the number of people is doubled.
Based upon the trend we see from this table we can predict how many
steps it will take for a classroom of size 336, 672, etc. and when we
plot the points we get a curve that looks like the log plot we had before.
amount of work
e
rc
Fo
e
ut
Br
uer
Divide & Conq
size of problem
Class Size Number of loops required
21 5
42 6
84 7
168 8
336 9
672 10
1344 11
2688 12
Many people believe that computers are so powerful that they can solve
any problem by a Brute-Force approach. This is not true! We need to
think in different ways to design more efficient algorithms so results can
be obtained in a reasonable amount of time.
In your homework, you are asked to make a similar plot using the
computer (not by hand).
How can you do this? You can use software such as Microsoft or a free
online program called PLOTLY.
I will show you how to create such a plot now using PLOTLY. Simply
do a search for PLOTLY. You must create your own account but it’s
FREE. To turn in your plot you can either save it in the program or
perform a ScreenShot of the plot.
In these algorithms, as well as the ones from last time, we had a con-
ditional statement, i.e., an if-then statement. Here is Bill Gates (Mi-
crosoft) explaining these.
This class looks at ways in which computers have begun to change the
way we live.
Many recent discoveries and inventions can be attributed to the power
of computer hardware (the machines), the development of computer
programs (the instructions we give the machines), and more impor-
tantly to the ability to think about problems in new ways that make
it possible to solve them with computers, something we call computa-
tional thinking.
Issues in Computational Thinking
• One week
• In 2004, Google announced a plan to systematically scan a copy of
every book ever published, estimated to number 130 million. The
result will be a huge database called Google Books.
• The idea was not to just copy all the publications but to make a
searchable data base. To allow everyone easy access to this data
base, Google developed a viewer which allows the user to compare
the number of occurrences of words or phrases in print through the
years.
• We will be looking at some of the history of digitizing text, the
problems Google encountered with this project, the type of computer
algorithms needed to convert text into a searchable document and
how to glean information from the viewer.
Cryptography, Public Key Encryption & Digital Signatures
• 3.5 weeks
• Algorithm # 4 (Public Key Encryption) and Algorithm # 9 (Digital
Signatures) in text
• We will begin by looking at cryptography from a historical perspec-
tive. We will see how it has been used to send secret messages as
early as Julius Caesar (who has a cipher named for him) up through
World War II. You will learn how to encrypt/decrypt a message given
a key and how to decrypt certain types of ciphers without a key by
looking at letter and word frequency plots.
• Cryptography became critical for everyone, not just military leaders,
when computers became prevalent. Now we enter our credit card
information in a website to make purchases with confidence that the
information is secure. How does this work? Public Key Encryption is
the algorithm that makes this possible. We will strive to understand
this algorithm by looking at simple examples.
• Another application of encryption is when you sign a document elec-
tronically. How can the individual receiving your signed document
know that it was really you who signed it?
G H I H Q G W J H H D VW
D E F E N D T H E E A S T
• 3 weeks
• Algorithm # 6 in text
• Since the advent of computers, people have considered whether com-
puters can become the dominant form of intelligence on Earth; this
has been a theme in many science fiction stories/movies through the
decades. There is actually a test called the Turing test (1950) which
is used to measure a machine’s ability to exhibit intelligent behavior.
• Machine learning algorithms are used in many applications from read-
ing postal codes to autonomous land vehicles. Unlike other algo-
rithms we have considered, in machine learning we typically “train”
the algorithm with a set of data and then, after it has “learned”,
we input new data for it to identify. For example, when reading
hand written postal codes we could train the algorithm with a set of
handwritten numbers and then give it a new code to identify.
• Recognizing patterns is something that humans do better than com-
puters. Typically a human can identify an image of a person after
having seen another picture of the person but this ability is difficult
to incorporate into an algorithm.
• We will look at various types of Machine learning algorithms and
see the types of applications they are best suited for. An underlying
theme is there is not one algorithm which works for all problems.
“1”
“2”
Images of
Machine Learning
Handwritten “3”
Algorithm
Numbers
“4”
etc.
• 1.5 weeks
• Clustering is the process of organizing objects or people into groups.
You could say that your friends on Facebook is a cluster and my
friends are another cluster. Your neighbors form one cluster and
my neighbors form another. Clustering is used in many applications
without us even realizing it. For example, if we compare a photo on
our computer with one that we print, we see that they are not exactly
the same because the monitor has many more colors available than
most printers. How did the printer assign a color to a pixel?
• Of course to develop an algorithm to cluster objects requires having
criteria for forming the clusters such as distance, color, etc. We will
look at various types of clustering and applications.
• We will see how clustering was used to discover that the disease
cholera was transmitted through the water.
How can computers solve word games?
• 1 week
• Lewis Carroll (Alice in Wonderland) developed a word game called
Doublets (also called Word Ladder). For example, can you take the
word MAN and turn it into APE by changing only one letter at a
time. Moreover, we would like to do this in the shortest number of
moves possible.
• We will look at strategies for solving this puzzle and variants and
see how they can be implemented in an algorithm for a computer to
solve the puzzle.
• This will give you an insight into algorithms for game solving such as
chess. In 1997 IBM’s chess computer beat the top-rated chess player
in the world and over the next few years humans and computers
traded blows until eventually by 2005-6, computer chess programs
were in the lead.
Sorting items and Searching the Web
• 2.5 weeks
• Algorithm # 2 (Page Match) and Algorithm # 3 (Page Rank) in
text
• Whenever you have items which you want to search repeatedly (such
as web pages), then it is important to first sort the items. We will
look at several approaches to sorting.
• When you do a search on the Web then not only does the search
engine find information that matches your search words but it also
ranks them, i.e., it puts the most relevant matches on the first page.
Moreover, it does this in seconds not hours.
• Just finding matches seems like an impossible task because it is es-
timated that there are over a billion websites. What we will see is
that when you do a search, the search engine doesn’t really search
the Web but rather a sorted index of the Web which it has created
earlier.
• Ranking the sites which match the search words seems like another
impossible task because a computer doesn’t really understand what
is written on the website. How can it distinguish between spam
websites and ones which have meaningful information? How can it
decide which are the most relevant sites? What can webmasters do
to help their sites appear on the first page of results? These are some
of the questions that we will look at.
Data Compression
• 1 week
• Algorithm # 7 in text
• Big data is the new buzz word for this century. Jobs requiring big
data expertise are predicted to be numerous and carry high salaries.
• Amazon gets 35 orders per second or 1.1 billion per year. That is a
lot of data! In order to handle this much data it must be compressed
in such a way that it can be decompressed at a later date. We want
to look at some of the ideas behind data compression.
Reading Assignment
amount of work
size of problem