time complexity basic PDF.pdf - CSE-221 Algorithms Introduction to Algorithms Algorithm Definition \u2022 A finite set of statements that guarantees an

time complexity basic PDF.pdf - CSE-221 Algorithms...

This preview shows page 1 - 10 out of 56 pages.

&6(°±±² $lgorithms ,ntroduction to $lgorithms
Image of page 1
$lgorithm 'efinition • $ finite set of statements that guarantees an optimal solution in finite interval of time • $lgorithmic thinking and problem solving skill are vital in making efficient solutions³ • 7he (nglish word ´$/*25,7+0´ derives from the /atin word $/° $/°.+:$5,=0,’6 name³ +e developed the concept of an algorithm in 0athematicsµ and thus sometimes being called the “*randfather of &omputer 6cience´³ ±
Image of page 2
*lance of $lgorithm • $n algorithm is a finite set of instructions or logicµ written in orderµ to accomplish a certain predefined task³ • $lgorithm is not the complete code or program • &an be expressed either as an informal high level description as pseudocode or using a flowchart³
Image of page 3
$lgorithm 6pecifications • Input ± (very $lgorithm must take zero or more number of input values from external³ • Output ± (very $lgorithm must produce an output as result³ • +**Definiteness ° (very statement·instruction in an algorithm must be clear and unambiguous ¸only one interpretation¹ • ,,Finiteness ± )or all different casesµ the algorithm must produce result within a finite number of steps³ • ,++Effectiveness ± (very ,nstruction must be basic enough to be carried out and it also must be feasible³ º
Image of page 4
*ood $lgorithms " • 5un in less time • &onsume less memory %ut computational resources ¸time complexity¹ usually important »
Image of page 5
¼ $nalyzing $lgorithms 3redict the amount of resources required½ memory ½ how much space is needed% computational time ½ how fast the algorithm runs% )$&7½ running time grows with the size of the input ,nput size ¸number of elements in the input¹ 6ize of an arrayµ polynomial degreeµ ¾ of elements in a matrixµ ¾ of bits in the binary representation of the inputµ vertices and edges in a graph +**Def%! 5unning time (4 the number of primitive operations ±steps° executed before termination $rithmetic operations ¸¿µ °µ À¹µ data movementµ controlµ decision making ¸ NOK± \]\MNOQRJ ¹µ comparison
Image of page 6
Á $lgorithm $nalysis½ (xample • (''lg°%! 0,1 ¸a>²@µ …µ a>[email protected]¹ m ← a>²@ ! for i ← ± to n if a>[email protected] !" m then m ← a>[email protected] ! • EZuaSaS\NaSZL Yt\N`RX ½ – the number of primitive operations ¸steps¹ executed before termination T±n² ($##³ >first [email protected] ¿ ±n² >for [email protected] ¿ ±n´³² >if [email protected] ¿ ±n´³² >the assignment in [email protected] "# µn ´ ³ • 2rder ¸rate¹ of growth½ – 7he leading term of the formula – (xpresses the asymptotic behavior of the algorithm
Image of page 7
 7ypical 5unning 7ime )unctions • ² ¸constant running time¹½ – ,nstructions are executed once or a few times • log1 ¸logarithmic¹ – $ big problem is solved by cutting the original problem in smaller sizesµ by a constant fraction at each step • 1 ¸linear¹ – $ small amount of processing is done on each input element • 1 log1 – $ problem is solved by dividing it into smaller problemsµ solving them independently and combining the solution
Image of page 8
à 7ypical 5unning 7ime )unctions • 1 ± ¸quadratic¹ – 7ypical for algorithms that process all pairs of data items ¸double nested loops¹ • 1 ¸cubic¹ – 3rocessing of triples of data ¸triple nested loops¹ • 1 .
Image of page 9
Image of page 10

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture