1-intr[2]

1-intr[2] - ADVANCED DATA-STRUCTURES & ALGORITHM...

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

View Full Document Right Arrow Icon
ADVANCED DAT A-STRUCTURES &ALGORITHM ANALYSIS Dr .Sukhamay Kundu Computer Science Dept, Louisiana state University Baton Rouge, LA 70803 kundu@csc.lsu.edu Spring, 2010 (copyright@2010)
Background image of page 1

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

View Full DocumentRight Arrow Icon
1.2 ROLE OF DAT A-STRUCTURES IN COMPUTATION Makes Computations Faster: •F aster is better. •T he speed of an Algorithm depends on both the method and the data-structure . Basic Operations in a Computation: Computation •L ocate/Access data-values •C ompute a value •S tore the newvalue Input Output Basic Characteristics of A program: Algorithm - The method used in computing various values. - The order in which theyare computed (and hence the order of read/write data-access operations). Data structures - Supports efficient computations of data-items in the method. Total computation time=Time to access/store data-values + Time to compute data-values Efficient Algorithm = Good method + Good data-structures
Background image of page 2
1.3 METHOD vs. DAT A STRUCTURE Problem: Compute the average of three numbers. Tw o Methods: (1) aver=( x + y + z )/3. (2) x /3) + ( y /3) + ( z /3). •M ethod (1) superior (fewer operations and faster) to Method (2). •T heyaccess data in the same order: x , y , z ,aver . •A ny improvement due to data-structure applies equally well to both the methods. Data structures: (a) Three variables x , y , z . (b) An array nums[0. .2]. This is an inferior choice to (a) because accessing an array- item takes more time than accessing a simple variable.
Background image of page 3

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

View Full DocumentRight Arrow Icon
1.4 LIMITS OF EFFICIENCY Hardwarelimit: Physical limits of time (speed of electrons) and space (layout of circuits). This limit is computation problem independent . From 5 mips (millions of instructions per sec) to 10 mips is an improvement by the factor of 2. One nano-second = 10 - 9 (one billionth of a second); 10 mips = 100 ns/instruction. Softwarelimit: Limitless in a way ,except for the inherent nature of the problem. That is, the limit is problem dependent . Sorting Algorithm A1: O ( n .log n )time Sorting Algorithm A2: O ( n 2 ( n =number of items sorted) A1 is an improvement overA2bythe factor n 2 n n = n log n = →∞ as n . O ( n n )isthe efficiency-limit for sorting Algorithms.
Background image of page 4
1.5 METHODS FOR MEASURING PERFORMANCE Analytic Method: •T heoretical analysis of the Algorithm’stime complexity. Empirical Methods: •C ount the number of times specific operations are performed by executing an instrumented version of the program. •M easure directly the actual program-execution time in a run. Example of Instrumentation: Original code: if (x < y) small = x; else small = y; Instrumentd code: countComparisons++; //initialized elsewhere if (x < y) small = x; else small = y; Question: •? What is wrong with the following instrumentation: if (x < y) { countComparisons++; small = x; } else small = y; •? Instrument the code belowfor readCount and writeCount of x : if (x < 3) y = x + 5; •? Showthe newcode after moving updates to loopCount outside the loop: for (i=j; i<max; i++) { loopCount++; if (x[i] < 0) break; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
1.6 EXERCISE 1. Instrument the code belowtocount the number of Exchanges (numExchanges) and number of comparisons (numCompar- isons) of the array data-items.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 145

1-intr[2] - ADVANCED DATA-STRUCTURES &amp; ALGORITHM...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online