lecture15

# lecture15 - CS111 Intro to Computer Science Lecture 15...

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

CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 15 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 15 Sorting

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 15 Review: Asymptotic Review: Asymptotic Complexity Complexity We would like to make general statements about one algorithm being faster than another However, actual time depends on programmer computer size of data which data
CS111: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 15 Abstractions Abstractions Choose one or a few “basic operations” Count operations done, not time Express number of operations as a function of input size Define input size Use the big-O of the function Focus on large input - “asymptotic”

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 15 Example: problem Example: problem Input: int array scores: holds scores. (Scores are 0 thru 100) int n: number of scores Output: boolean: are there any duplicate scores, i.e. are there i and j such that A[i]==A[j]?
CS111: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 15 Example: Solution 1 Example: Solution 1 For each pair of indices i, j (0 i < j n-1), test if scores[i] == scores[j]. If so, return true After all loops are done, return false See FindDups1.java

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 15 Evaluating speed of FindDups1 Evaluating speed of FindDups1 Choose ops to count scores[i] == scores[j] Choose measure of problem size n Ops as function of size - worst case i=0: j= 1. .n-1: n-1 iterations i=1: j = 2. .n-1: n-2 iterations … i=n-2: j= n-1. .n-1: 1 iteration
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 24

lecture15 - CS111 Intro to Computer Science Lecture 15...

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

View Full Document
Ask a homework question - tutors are online