1 / 10

Lecture 3: Analysis of Algorithms

Lecture 3: Analysis of Algorithms. Review Insertion Sort Analyzing Algorithms Big-O Notation Your CUNIX Account Reading. Review.

grayt
Download Presentation

Lecture 3: Analysis of Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3: Analysis of Algorithms • Review • Insertion Sort • Analyzing Algorithms • Big-O Notation • Your CUNIX Account • Reading

  2. Review • Definition of an algorithm: A well-ordered collection of unambiguous and effectively computable operations that, when executed, produces a result and halts in a finite amount of time. • There are three components to an algorithm: • A set of inputs, where each input is a finite sequence of items. • A set of outputs, where each output is a finite sequence of items. • A method consisting of a finite sequence of instructions, each one of which can be mechanically executed in a fixed length of time with a fixed amount of resources. The method must produce an output for each input in the set of possible inputs in a finite amount of time.

  3. Review • Input size: associated with each input is a measure of its size. How we measure the size can vary from problem to problem. Examples: • Number of digits as in the number of digits in a number (Often we use binary digits). • Number of characters in a string. • Number of items as in the number of items to be searched or sorted.

  4. Review: Selection Sort Algorithm to sort the items on a list into nondecreasing order Input: A list of n ≥1 elements A[1], A[2], ... , A[n]. Output: The list sorted in nondecreasing order. Method: for (i = 1; i < n; i++) { locmin=i; for (j=i+1;j <= n; j++) { if (A[locmin] > A[j]) locmin=j; } exchange(A[locmin], A[i]); }

  5. InsertionSort Input: A list of n ≥1 elements A[1], A[2], ... , A[n]. Output: The list sorted in nondecreasing order. Method: for (j=2; j <= n; j ++) { temp = A[j] i=j-1 while (i > 0 and A[i] > temp) { A[i+1]=A[i] i=i-1 } A[i+1]=temp }

  6. Analyzing Algorithms • We would like to measure the quality or efficiency of an algorithm so that we may compare algorithms that perform similar tasks. • We want this measure to be machine (and implementation) independent. • We will consider the number of instructions that need to be executed. • This will be a function of the input size, n. • This may vary depending on “chance”. • We will consider worst-case running time and also average-case running times.

  7. Analyzing Algorithms • Instead of all instructions being counted equal we will count mathematical and/or logical operations involving variables that are unknown ahead of time. • At the end of the day our “measure” will be a function of n. Therefore we need a way of comparing these functions.

  8. Big-O Notation • Given a function of n,we will consider only the most dominant term. What we really care about is the order of magnitude of growth. • Example: T(n)=25n3+log(n)+2n = O(2n) • Example: T(n)=3n2+100n = O(n2) • We’ll save the technical definition for COMS W3203 Discrete Math. The point is we care about growth because we care about really really big n!

  9. Your CUNIX Account • Go to CUIT website at: http://www.columbia.edu/cuit/ • Mac and Windows users download Cyberduck • Windows users also need Putty

  10. Your Codio account • You will receive an email from me with a link to sign up for your Codio account! • These cost the university money so you must be enrolled in the course for this.

More Related