CS350
Lecture Notes - 1
Are there two people in this room with the same birthday?
How might we go about answering this question?
for each person in the room:
find each's birthday on the calendar
if the calendar day is marked
return that day
else
mark that day
return false
for each person in the room:
write each's birthday on the whiteboard
for other people in the room:
if other's birthday is on the whiteboard
return birthday
return false
Are there other algorithms that solve this problem?
Scalability
On Syllabus:
David Lu
Office: TBA (Feng Liu's old office 120-09)
email: dlu@pdx.edu
Course webpage: https://davidjlu.github.io/CS350/
Will use D2L as a grade book, so you can access and keep track of your grades through the quarter.
TA: Neil Babson
Office Hours: Tues/Thurs 2-3PM in fishbowl
email: nbabson@pdx.edu
Go over syllabus
Look at schedule.
Schedule is tentative.
Textbook is grouped by design strategy
Pros
Cons
Group by problem type - CLRS (Algorithms Bible)
Pros
Cons
Levitin is supposed to be much more readable than CLRS
Homeworks
* 4 problem sets
* 2 will feature implementing some algorithms and testing
Midterm
Final - Date?
"An algorithm is a sequence of unambiguous instructions for solving a problem, i.e. for obtaining a required output for any legitimate input in a finite amount of time." (Levitin 1.1)
Find Duplicates
Input: a length n array, A, of integers.
Output: true if the array contains a duplicate and false otherwise
for i <- 1 ... n
for j <- 1 ... n
if i !=j and A[i] = A[j] then
return true
return false
How do we know whether this algorithm correctly solves the problem for any legitimate input?
Idea: Count basic operations -- the operation contributing most to the running time
Analysis - Find Duplicates
(why 2?)
Units for measuring running time
Let be the execution time of an algorithm's basic operation, and let be the number of times this operation needs to be executed for the algorithm. Then we can estimate the running time of a program implementing this algorithm by the formula
Less Stupid Find Duplicates
Input: a length n array, A, of integers.
Output: true if the array contains a duplicate and false otherwise
for i <- 1...n-1
for j <- i+1...n
if A[i] = A[j] then
return true
Is this a correct algorithm to solve the problem?
Analysis - Less Stupid Find Duplicates
What happens if we double the input size?
About 4 times longer!
Also factorial
Exponential and above is HARD!
For Wed read sections 2.1 and 2.2.
I will prepare HW1 and place it in the assignments tab on the course website.