This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: C M L Click to edit Master subtitle style 10/22/10 C M L CSE 310 Algor ithms and Data Aviral Shrivastava Assistant Professor Computer Science and Engineering Arizona State University C M L 10/22/10 C M L Announcements • Class schedule – Monday, Wednesday, 7:00 pm – 10:00 pm • Assignment 1 is online – Due Monday, June 14, 2010 • Assignment 2 will be online today – Due by Monday, June 21, 2010 • Cheating policy on homeworks – Can discuss with your friends, but write independently – Learn from web, but write your own C M L 10/22/10 C M L CSE 310 Roadmap • Induction • Recursion • Running Time Analysis C M L 10/22/10 C M L Algor ithm • An ' algor ithm' is a method for solving a problem expressed as a finite sequence of instructions. – Pr oof of cor r ectness: always give the right answer and never give a wrong answer – Pr oof of ter mination: always be completed in a finite number of steps, rather than in an infinite number C M L 10/22/10 55 Insertion Sort AlgorithmIt sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted. Example: 3 9 6 1 2 9 should be inserted after 3 – no change 3 9 6 1 2 6 should be inserted between 3 and 9 3 6 9 1 2 1 should be inserted before 3 1 3 6 9 2 2 should be inserted between 1 and 3 1 2 3 6 9 Running Time Analysis C M L 10/22/10 C M L 66 /*Pseudocode of Insertion Sort*/ INSERTIONSORT(A) for j = 2 to length(A) do n key = A[j] /* insert A[j] into sorted sequence A[1 … j1] */ i = j – 1 while (i > 0 and A[i] > key) do A[i+1] = A[i] i = i – 1 A[i+1] = key tj= the number of times the while loop test is executed for a value of j. tj 1= # of elements in A[1…j1] that are > A[j] I nser tion Sor t C M L 10/22/10 C M L 77 INSERTIONSORT(A) for j = 2 to length(A) do n key = A[j] /* insert A[j] into sorted sequence A[1 … j1]*/ i = j – 1 while i > 0 and A[i] > key do A[i+1] = A[i] i = i – 1 A[i+1] = key times cost n c1 n1 c2 c3=0 n1 c4 y nj=2 tj c5 W nj= 2 (tj1) c6 y nj=2(tj1) c7 n1 c8 tj= the number of times the while loop test is executed for that value of j....
View
Full
Document
This note was uploaded on 10/21/2010 for the course CSE 310 taught by Professor Davulcu,h during the Spring '08 term at ASU.
 Spring '08
 Davulcu,H
 Computer Science, Algorithms, Data Structures

Click to edit the document details