3 views

Uploaded by some_donkus

aaaaaaa

save

- A Few Improvements for Selection Sort Algorithm
- Practice Problems on List and Dictionary
- MCA questions2011
- sridhar
- Ed Chantler - Practical 2 Format Report
- Chapter7.ans.doc
- Chapter7.ans.doc
- Recursion Trees and Master Method
- SmoothedAnalysis_4
- parallel processing-GTU paper
- Data Structures
- T5-4up
- Performance Tuning in IBM InfoSphere DataStage
- L1 Intro Revised11
- Polymorphism
- What is Data Structure
- ds
- Chapter 6
- Datastage Performance Guide
- Hacking a Google Interview Handout 2
- 00761830
- 4. Improved Histograms for Selectivity Estimation of Range Predicates - Poosala
- Algorithm
- Java Past Paper Answer 2006
- pt
- 2016 CSE 259 LPAA Lec2 a Analysis
- NEW C++ Lab Manual
- Pages From Cloudera_CCD-410
- lattice structure for FIR filter
- Readme
- CDA3101 F13 HW1 Assignment
- CDA3101 L05 Benchmarks MSS
- esssay5
- Gerudo Valley Lead-2
- CDA3101 L04 Performance MSS
- Real Folk Blues

You are on page 1of 20

for (int i = 1; i < n; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j]; a[j + 1] = t; }

Complexity

**Space/Memory Time
**

Count a particular operation Count number of steps Asymptotic complexity

Comparison Count

for (int i = 1; i < n; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j]; a[j + 1] = t; }

Comparison Count

**Pick an instance characteristic … n
**

For insertion sort, pick n = number of elements to be sorted.

Determine count as a function of this instance characteristic.

Comparison Count

for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];

How many comparisons are made?

Comparison Count

for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];

number of compares depends on a[]s and t as well as on i

Comparison Count

Worst-case count = maximum count Best-case count = minimum count Average count

**Worst-Case Comparison Count
**

for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];

a = [1, 2, 3, 4] and t = 0 => 4 compares a = [1,2,3,…,i] and t = 0 => i compares

**Worst-Case Comparison Count
**

for (int i = 1; i < n; i++) for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];

total compares = 1 + 2 + 3 + … + (n-1)

= (n-1)n/2

Step Count

A step is an amount of computing that does not depend on the instance characteristic n

10 adds, 100 subtracts, 1000 multiplies can all be counted as a single step n adds cannot be counted as 1 step

Step Count

for (int i = 1; i < n; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j]; a[j + 1] = t; }

s/e 1 0 1 0 1 1 1 0

Step Count

s/e isn’t always 0 or 1

x = sum(a, n); where n is the instance characteristic has a s/e count of n (sum() is Program 1.30).

Step Count

for (int i = 1; i < n; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j]; a[j + 1] = t; }

s/e steps 1 0 1 0 i+ 1 1 1 i 1 0

Step Count

for (int i = 1; i < n; i++) { 2i + 3} step count for for (int i = 1; i < n; i++) is n step count for body of for loop is 2(1+2+3+…+n-1) + 3(n-1) = (n-1)n + 3(n-1) = (n-1)(n+3)

**Asymptotic Complexity of Insertion Sort
**

O(n2) What does this mean?

**Complexity of Insertion Sort
**

Time or number of operations does not exceed c.n2 on any input of size n (n suitably large). Actually, the worst-case time is Q(n2) and the best-case is Q(n) So, the worst-case time is expected to quadruple each time n is doubled

**Complexity of Insertion Sort
**

Is O(n2) too much time? Is the algorithm practical?

Practical Complexities

109 instructions/second

n

1000

n

1mic

nlogn n

10mic

2

n

3

1milli

1sec

10000

10mic

130mic

100milli

17min

106

1milli

20milli

17min

32years

Impractical Complexities

109 instructions/second

n

1000

n

4

n

10

2

n

17min

3.2 x 1013 years ???

3.2 x 10283 years ???

10000

116 days 3 x 107 years

106

??????

??????

**Faster Computer Vs Better Algorithm
**

Algorithmic improvement more useful than hardware improvement. E.g. 2n to n3

- A Few Improvements for Selection Sort AlgorithmUploaded byATS
- Practice Problems on List and DictionaryUploaded byMotasima Mine
- MCA questions2011Uploaded byAnanya Shwathi
- sridharUploaded bygabig91
- Ed Chantler - Practical 2 Format ReportUploaded byEdChantler
- Chapter7.ans.docUploaded byabdullah badawi
- Chapter7.ans.docUploaded byBlasta45
- Recursion Trees and Master MethodUploaded byHarsh Vardhan Jha
- SmoothedAnalysis_4Uploaded byKathy Es
- parallel processing-GTU paperUploaded bySagar Damani
- Data StructuresUploaded bykarthikavilan
- T5-4upUploaded bytexony
- Performance Tuning in IBM InfoSphere DataStageUploaded bysrimkb
- L1 Intro Revised11Uploaded byWooseok Yang
- PolymorphismUploaded byGauravSharma
- What is Data StructureUploaded bygauravujjawal
- dsUploaded byMohammed Jeelan
- Chapter 6Uploaded byPraveen Kumar
- Datastage Performance GuideUploaded byjoshi
- Hacking a Google Interview Handout 2Uploaded bymachinelearner
- 00761830Uploaded byhakim
- 4. Improved Histograms for Selectivity Estimation of Range Predicates - PoosalaUploaded byPanos Koukios
- AlgorithmUploaded byMohanbkn
- Java Past Paper Answer 2006Uploaded byTum Anusorn Preugpaibul
- ptUploaded bysuganya004
- 2016 CSE 259 LPAA Lec2 a AnalysisUploaded bychyon
- NEW C++ Lab ManualUploaded byvplvpl
- Pages From Cloudera_CCD-410Uploaded bylinkranjit
- lattice structure for FIR filterUploaded byjaishpanjwani
- ReadmeUploaded byKevin Chau