cse 373: analysis of algorithms
DESCRIPTION
CSE 373: Analysis of Algorithms. Course Webpage http://www.ams.sunysb.edu/~piyush/teach/373/. The Course. Instructor: Piyush Kumar email: [email protected] Office Hours: Mon, Wed 11:45 - 12:45 PM; Or by appointment (use email) - PowerPoint PPT PresentationTRANSCRIPT
The Course
Instructor: Piyush Kumar email: [email protected] Office Hours: Mon, Wed 11:45 - 12:45 PM;
Or by appointment (use email)
Teaching Assistants : TBA
The Course
Prerequisites: MAT 211 w/ grade of C- or better AMS 211 w/ grade of C- or better CSE 214 w/ grade of C- or better Programming in [C++/C/Java]
The Course
Format Three lectures/week Homework mostly biweekly
Problem sets Maybe occasional programming
assignments One MidTerm (Oct 20th) + final exam FINAL EXAM is on DEC 15th, 8:00am to 10:30pm. Venue: TBA
Homework
Write problems beginning with a new page.
Only hard-copy (paper) submissions are allowed.
No late assignments Look at the Course Procedure
webpage for more information
Homework Policy If you ask to re-grade your homework
please write out the basis of your request.
If the grader finds no basis for your complaint, then 10% points will be deducted from your original grade unless the grade is changed.
Note: This is not to discourage you from disputing your grade, but rather we encourage you to read and understand the posted solutions on the web before you ask your solutions to be re-graded
Homework Policy
Under no circumstances should you be copying others.
It is fine to discuss problems with others, but all of the writing should be done without any collaboration. Make sure you read the Course Procedure webpage.
Homework Policy
You can work in a pair or alone If you work in a pair, You are both
supposed to write the solutions independently and staple before you submit.
Only one solution from a pair will be graded (The one on top).
Exam Policy
If you say “I don’t know” in any question in the exam, you get 25% marks for that question/sub-question.
In case you don’t know the answer its better to leave it than filling the answer sheet with ‘crap’ because you might even loose that 25%
Algorithm: What is it?
An Algorithm a well-defined computational procedure that transforms inputs into outputs, achieving the desired input-output relationship.
Algorithm Characteristics Finiteness Input Output Rigorous, Unambiguous and
Sufficiently Basic at each step
Correctness
Applications? WWW and the Internet Computational Biology Scientific Simulation VLSI Design Security Automated Vision/Image Processing Compression of Data Databases Mathematical Optimization
Sorting
Input:Input: Array A[1...n], of elements in arbitrary order
Output: Array A[1...n] of the same elements, but in increasing order
Given a teacher find all his/her students. Given a student find all his/her teachers.
The RAM Model Analysis is performed with respect to a
computational model We will usually use a generic
uniprocessor random-access machine (RAM) All memory equally expensive to access No concurrent operations All reasonable instructions take unit time
Except, of course, function calls Constant word size
Unless we are explicitly manipulating bits
Binary Search
Initialize
Get Midpoint
Compare
Adjust High Adjust Low
Failure
Success
High < Low
=
< >
Binary SearchAlgorithm: Low= 1; High = n; while Low < High { m = floor( (Low+High)/2 ); if k <= A[m]
then High = m - 1 else Low = m + 1
} if A[Low] = k then j = Low else j = 0
Time and Space Complexity
Generally a function of the input size E.g., sorting, multiplication
How we characterize input size depends: Sorting: number of input items Multiplication: total number of bits Graph algorithms: number of nodes & edges Etc
Running Time Number of primitive steps that are
executed Except for time of executing a
function call most statements roughly require the same amount of time
y = m * x + b c = 5 / 9 * (t - 32 ) z = f(x) + g(y)
We can be more exact if need be
Analysis Worst case
Provides an upper bound on running time An absolute guarantee
Average case Provides the expected running time Very useful, but treat with care: what is
“average”? Random (equally likely) inputs Real-life inputs
Binary Search Analysis
Order Notation Upper Bounds Search Time = ?? A better way to look at it, Binary Search Trees
Searching A bad king has a cellar of 1000 bottles of delightful
and very expensive wine. a neighbouring queen plots to kill the bad king and sends a servant to poison the wine. (un)fortunately the bad king's guards catch the servant after he has only poisoned one bottle. alas, the guards don't know which bottle but know that the poison is so strong that even if diluted 1,000,000 times it would still kill the king. furthermore, it takes one month to have an effect. the bad king decides he will get some of the prisoners in his vast dungeons to drink the wine. being a clever bad king he knows he needs to murder no more than 10 prisoners - believing he can fob off such a low death rate - and will still be able to drink the rest of the wine at his anniversary party in 5 weeks time. Explain how...
Solution Number each bottle in binary digits Feed each prisoner one column of
the list of the binary digits where 1 means the bottle is tasted and zero means its not
Convert the death of the 10 prisoners into a decimal number, That’s the bottle we are looking for.
Induction Prove 1 + 2 + 3 + … + n = n(n+1) / 2
Basis: If n = 0, then 0 = 0(0+1) / 2
Inductive hypothesis: Assume 1 + 2 + 3 + … + n = n(n+1) / 2
Step (show true for n+1):1 + 2 + … + n + n+1 = (1 + 2 + …+ n) + (n+1)= n(n+1)/2 + n+1 = [n(n+1) + 2(n+1)]/2 = (n+1)(n+2)/2 = (n+1)(n+1 + 1) / 2