UNIT 4C Itera,on: Correctness and Efficiency. General Idea: Any one Itera,on. i L SORTED SORTED

Similar documents
Safety Shock Absorbers SDP63 to SDP160

Data Structures Week #9. Sorting

Frequently asked questions about battery chargers

0580 MATHEMATICS 0580/42 Paper 42 (Extended), maximum raw mark 130

Roll No. :... Invigilator's Signature :. CS/B.Tech(EE-OLD)/SEM-4/ME(EE)-411/ THERMAL POWER ENGINEERING

Marquette University MATH 1700 Class 9 Copyright 2017 by D.B. Rowe

Steel or Chrome Plated Cylindrical Plug n Inch and Metric Sizes GO 1629 Double End 1659 NO GO

Application of Ranked Positional Weight Method for Assembly Line Balancing A Case Study

Workspace and storage furnishings

charge Positive Electrode: Ni(OH) 2 + OH - NiOOH + H 2 O + e - discharge charge Negative Electrode: M + H 2 O + e - MH + OH - discharge

Series. Cleaner, greener, award-winning performance

A New Mechanical Oil Sensor Technology

SSG Donaclone Air Cleaner

EU focuses on green fans

Lecture 6. Case Study: Design of a Brake Assembly

1200 Series. Cleaner, greener, award-winning performance

Safety Shock Absorbers SCS33 to SCS64

FUEL-BURNING EQUIPMENT - OXIDES OF NITROGEN (Effective 7/1/71: Rev. Effective 9/20/94)

INTRODUCTION TO THE ORDERED FAMILIES OF CONSTRUCTIONS

AUTOMATIC BATTERY CHARGER

R70. Technical Data. LPG Forklift Trucks Models R T/R T/R T.

Machine Screw and Fractional Sizes GO 1520 Double End w/handle 1551 NO GO. Nominal Size Length Handle

Quantifying the delay in receiving biologics and conventional DMARDs

TEKIN DIS-350 BATTERY DISCHARGER TABLE OF CONTENTS OWNER S MANUAL ELECTRONICS, INC.

Reliability Analysis of a Diesel Engine Driven Electric Power Unit E.C. NASIOULAS 1, G.J. TSEKOURAS 1, F.D. KANELLOS 2

Definitions and reference values for battery systems in electrical power grids

MAN HydroDrive. More traction. More flexibility. More safety. MAN kann.

Rotary Screw Compressors R-Series 5-11 kw (5-15 hp) Fixed and Variable Speed Drives

trailertrak Telematics Solution Manage your underutilized or misplaced trailers and keep your profits moving forward.

Ground Rules for SET Index Series

Technical Information

Belt Conveyors 8912, 8916, & For economical conveying of light-to-medium-density bulk materials.

MAN Lion s Intercity.

Which BedRug Rear Kit Fits my Jeep CJ-7 & YJ?

RTG Electrification. The numbers really add up.

Assessing Article 2(6a) in light of the Biodiesel rulings

Prediction of Bias-Ply Tire Rolling Resistance Based on Section Width, Inflation Pressure and Vertical Load

Power Semiconductor Devices

Onecharge Electric Vehicle Charging Unit

DLRO100H, DLRO100HB Megger Digital Low Resistance Ohmmeters

MZT PUMPI. Horizontal three screw pumps series KHVP-A. Technical catalog. Document No. 4HK.KHVPA.R001.EN

HYDRAULIC MOTORS EPMSY

7th Grade Math. Determining if a Triangle is Possible. Slide 2 / 180. Slide 1 / 180. Slide 4 / 180. Slide 3 / 180. Slide 5 / 180.

Built with. Donaldson. Technology.

Oil cooled motor starters MOTORSTARTERS. High torque low current

l * i Install new gasket.

The battery as power source

DuraLite ECB, ECC, ECD Air Cleaner

CHAPTER I: OVERALL REQUIREMENTS

Air Quality Solutions

Prediction of Radial-Ply Tire Deflection Based on Section Width, Overall Unloaded Diameter, Inflation Pressure and Vertical Load

3333 Multi-Use Vertical Pump

PowerCore. Filtration Technology. Why was it developed? What is it about? How does it work? PowerCore

Operational Status Evaluation for Electric Vehicle Chargers based on Layered Radar Map Method

Integra SURGICAL TECHNIQUE. MemoFix Super Elastic Nitinol Staple System. Super Elastic Nitinol Staple System

Number 26 page 630 The production of Reliable Manufacturing company for 2007 and part of 2008 follows Production (thousands

1.0 HP PSI PSI

Prediction of Bias-Ply Tire Contact Area Based on Contact Area Index, Inflation Pressure and Vertical Load

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

The Analysis and Research Based on DEA Model and Super Efficiency DEA Model for Assessment of Classified Protection of Information Systems Security

PINCH VALVES AND PRESSURE SENSOR S

A SOLUTION FOR MAKING ALL PREMISES ACCESSIBLE

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

An empirical correlation for oil FVF prediction

SERIES 35-60J. 24 VAC Microprocessor Based Direct Spark Ignition Control Johnson Controls G76x Series Replacement FEATURES

1 Copyright 2017 by Turbomachinery Laboratory, Texas A&M Engineering Experiment Station

Air Quality Solutions

Smaller, Lightweight Alternative Two-Stage Air Cleaner Designed for horizontal installation

CONTENTS. Introd uction...

Number 26 page 630 The production of Reliable Manufacturing company for 2007 and part of 2008 follows Production (thousands

4) TO BE ELIGIBLE FOR THE COURTESY TRANSPORTATION ALLOWANCE, ALL VEHICLES MUST SATISFY ONE OF THE FOLLOWING REQUIRED RETENTION PERIODS:

A Generalization of the Rate-Distortion Function for Wyner-Ziv Coding of Noisy Sources in the Quadratic-Gaussian Case

TOOLS NEWS Update B179G. Diamond Coated End Mills for Graphite. DFendmillseries. Item Expansion. High performance graphite milling.

Evaluation and Analysis of Innovation Capability of High and New Technology Park

Cost-Effective and Idle Reducing Technology. Engine-Off Heating, Air Conditioning and Comfort Solutions for the Off-Highway Operator

Access Floor Boxes One Piece (20 Series) One piece box base Individual (20A Series) Individual box bases for each compartment Screed/Stainless

powerswitch Industrial Switches & Motor Controls

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

Taking Great Measures for More than 40 years. PCB Load & Torque Division

Integra Jarit Video Assisted Thoracoscopic Surgery

MAN AUTOMOTIVE IMPORTS Service Contracts. Evolve to MAN

including technical specifications and seating variants

Jeep Wrangler TJ/ LJ Bedrug/BedTred Interior Installation Instructions

Tracking Ability of an MCV on a Rural Road

CD AUTOMATION SOFT STARTERS FAMILY

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

Single Shaft Shredder G X V P. Harness The Power of Nature. l l l

* * MEASURE TORQUE HUB

Learning Multi-class Theories in ILP

STG Donaclone Air Cleaner

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

Traveling Comfortably and Economically. DIWA.3E

OPERATOR S MANUAL MODEL SE-3.5BS

ScienceDirect. Direct Drive of 25 MN Mechanical Forging Press

Temperature Sensors. How to Order Consult factory for pricing and lead time. Normally Open (Closed on temperature rise)

Seated valve (PN 16 & PN 25) VFM 2 Two way valve, flange

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

Heavy vehicle path stability control for collision avoidance applications

Genco Shipping & Trading Limited. Genco s Comprehensive IMO 2020 Plan October 2018

US Sales Operations - Incentives GM Dealer Business Center Phone: Fax:

Transcription:

UNIT 4C Itera,o: Correctess ad Efficiecy 1 L Geeral Idea: Ay oe Itera,o SORTED i i L SORTED 2 1

Look Closer at Iser,o Sort Give a list L of legth, > 0. 1. Set i = 1. 2. While i is ot equal to, do the followig: L[0..i) meas: List L from idex 0 up to but ot icludig i Precodi)o for each itera)o: L[0..i) is sorted a. Isert L[i] ito its correct posi,o i L betwee idex 0 ad idex i iclusive. b. Add 1 to i. Postcodi)o for each itera)o: L[0..i) is sorted 3. Retur the list L which will ow be sorted. 3 Look Closer at Iser,o Sort Give a list L of legth, > 0. 1. Set i = 1. 2. While i is ot equal to, do the followig: Loop ivariat: L[0..i) is sorted a. Isert L[i] ito its correct posi,o i L betwee idex 0 ad idex i iclusive. b. Add 1 to i. 3. Retur the list L which will ow be sorted. A loop ivariat is a codi)o that is true at the start ad ed of each itera)o of a loop. 4 2

Reasoig with the Loop Ivariat The loop ivariat is true at the ed of each itera,o, icludig the last itera,o. AWer the last itera,o, whe we go to step 3: L[0..i) is sorted (from the last itera,o) AND i is equal to (due to the while loop termia,g) These 2 codi,os imply that L[0..) is sorted, but this rage is the e,re list, so the list must always be sorted whe we retur our fial aswer! 5 Cou,g Opera,os We measure,me efficiecy by cou,g the umber of opera,os performed by the algorithm. But what is a opera,o? assigmet statemets comparisos retur statemets... 6 3

Liear Search: Worst Case # let = the legth of datalist. def search(datalist, key): idex = 0 1 while idex < le(datalist): +1 if datalist[idex] == key: retur idex idex = idex + 1 retur Noe 1 Total: 3+3 7 Cou,g Opera,os How do we kow that each opera,o we cout takes the same amout of,me? (We do t.) So geerally, we look at the process more abstractly ad cout whatever opera,o depeds o the amout or size of the data we re processig. We do't cosider what machie we're usig, what compiler we use, what laguage we use, etc. For liear search, we would cout the umber of,mes we compare elemets i the list to the key. 8 4

Liear Search: Worst Case Simplified # let = the legth of datalist. def search(datalist, key): idex = 0 while idex < le(datalist): if datalist[idex] == key: retur idex idex = idex + 1 retur Noe Total: 9 Order of Complexity For very large, we express the umber of opera,os as the (,me) order of complexity. Order of complexity is owe expressed usig Big-O ota,o: Number of opera,os Order of Complexity O() 3+3 O() 2+8 O() Usually does't matter what the costats are... we are oly cocered about the highest power of. 10 5

O() ( Liear ) 2 + 8 3+3 Number of Operatios (amout of data) 11 O() Number of Operatios 40 20 10 For a liear algorithm, if you double the amout of data, the amout of work you do doubles (approximately). Put aother way: The amout of work doe is liearly proportioal to the amout of data. 10 20 40 (amout of data) 12 6

Liear Search: Best Case # let = the legth of datalist. def search(datalist, key): idex = 0 1 while idex < le(datalist): 1 if datalist[idex] == key: 1 retur idex 1 idex = idex + 1 retur Noe Total: 4 13 Liear Search: Best Case Simplified # let = the legth of datalist. def search(datalist, key): idex = 0 while idex < le(datalist): if datalist[idex] == key: 1 retur idex idex = idex + 1 retur Noe Total: 1 14 7

O(1) ( Costat-Time ) Number of Operatios For a costat-time algorithm, if you double the amout of data, the amout of work you do stays the same. 4 1 4 = O(1) 1 = O(1) (amout of data) 15 Liear Search Worst Case: O() Best Case: O(1) Average Case: 16 8

Iser,o Sort: Worst Case j i SORTED O itera,o i, we eed to examie j elemets ad the shiw i-j elemets to the right, so we have to do j + (i-j) = i uits of work. 17 Iser,o Sort: Worst Case Whe i = 1, we have 1 uit of work. Whe i = 2, we have 2 uits of work.... Whe i = -1, we have -1 uits of work. The total amout of work doe is: 1 + 2 +... + (-1) = (-1)/2 = ( 2 - )/2 (a quadra,c fuc,o) = O( 2 ) 18 9

Order of Complexity Number of opera,os Order of Complexity 2 O( 2 ) 2 /2 + 3/2-1 O( 2 ) 2 2 + 7 O( 2 ) Usually does't matter what the costats are... we are oly cocered about the highest power of. 19 O( 2 ) ( Quadra,c ) 2 2 + 7 2 2 /2 + 3/2 1 Number of Operatios (amout of data) 20 10

Number of Operatios O( 2 ) 1600 N 2 400 100 10 20 40 For a quadratic algorithm, if you double the amout of data, the amout of work you do quadruples (approximately). Put aother way: The amout of work you do is proportioal to the square of the amout of data. N (amout of data) 21 Our Iser,o Sort Worst Case: O( 2 ) Best Case: I our iser,o sort implemeta,o, the worst case ad best case are the same! It does't maier where we do the iserts. If we isert ear the frot, we have fewer elemets to compare, but more shiws. If we isert ear the ed, we have more elemets to compare, but fewer shiws. But we ca get the best case to be O(). (See PS4!) 22 11