{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE 310-Lecture3

CSE 310-Lecture3 - CSE 310 A lgor ithms and D ata Click to...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
C M L Click to edit Master subtitle style 10/22/10 CSE 310 Algorithms and Data Aviral Shrivastava Assistant Professor Computer Science and Engineering Arizona State University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C M L 10/22/10 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 programs
Background image of page 2
C M L 10/22/10 CSE 310 Roadmap Induction Recursion Running Time Analysis
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C M L 10/22/10 Algorithm An ' algorithm' is a method for solving a problem expressed as a finite sequence of instructions. Proof of correctness: always give the right answer and never give a wrong answer Proof of termination: always be completed in a finite number of steps, rather than in an infinite number
Background image of page 4
C M L 10/22/10 55 Insertion Sort Algorithm --It 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
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C M L 10/22/10 66 /*Pseudocode of Insertion Sort*/ INSERTION-SORT(A) for j = 2 to length(A) do n key = A[j] /* insert A[j] into sorted sequence A[1 … j-1] */ 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…j-1] that are > A[j] I nsertion Sort
Background image of page 6
C M L 10/22/10 77 INSERTION-SORT(A) for j = 2 to length(A) do n key = A[j] /* insert A[j] into sorted sequence A[1 … j-1]*/ 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 n-1 c2 0 c3=0 n-1 c4 y nj=2 tj c5 W nj= 2 (tj-1) c6 y nj=2(tj-1) c7 n-1 c8 tj= the number of times the while loop test is executed for that value of j.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}