lecture_18

# lecture_18 - BIOS 735 Statistical Computing Michael Wu...

This preview shows pages 1–6. Sign up to view the full content.

BIOS 735: Statistical Computing Michael Wu Lecture 18: Sorting Algorithms and Linear Algebra (1) October 11, 2011 Michael Wu (Lecture 18) BIOS 735 October 11, 2011 1 / 13

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

View Full Document
Runtime Analysis: Common Sorting Algorithms Last class, we started talking about big Omicron notation and some issues in runtime analysis. In CS, sorting algorithms are commonly used to make the point. Bubble Sort Selection Sort Insertion Sort Shell Sort Merge Sort Quick Sort Radix Sort Heap Sort etc etc etc We cover some of these for the sake of completeness. Michael Wu (Lecture 18) BIOS 735 October 11, 2011 2 / 13
Runtime Analysis: Bubble Sort set.seed(100) a = sample(1:10, 10 , replace = F); a Bubble = function(a, print = F) { n = length(a) for (i in 1:n){ for (i in seq(n-1)) { if (a[i+1]< a[i]) { temp = a[i] a[i] = a[i+1] a[i+1] = temp } } if (print) print(a) } return(a) } Bubble(a) Bubble(a, T) What is the runtime?? Michael Wu (Lecture 18) BIOS 735 October 11, 2011 3 / 13

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

View Full Document
Runtime Analysis: Selection Sort set.seed(100) a = sample(1:10, 10 , replace = F); a Selection = function(a, print = F) { n = length(a) for (i in 1:(n-1)) { k = i for (j in (i+1):n) { if (a[j]<a[k]) k = j; } temp = a[k] a[k] = a[i] a[i] = temp if (print) print(a) } return(a) } Selection(a) Selection(a, T) What is the runtime?? Michael Wu (Lecture 18) BIOS 735 October 11, 2011 4 / 13
Runtime Analysis: Quick Sort set.seed(100) a = sample(1:10, 10 , replace = F); a Quick = function(a, print = F) { if (print) print(a) if (length(a) <= 1) {

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

lecture_18 - BIOS 735 Statistical Computing Michael Wu...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online