/
big-O notation Big-O Notation is the most widely used method which describes algorithm big-O notation Big-O Notation is the most widely used method which describes algorithm

big-O notation Big-O Notation is the most widely used method which describes algorithm - PowerPoint Presentation

isla
isla . @isla
Follow
74 views
Uploaded On 2023-09-19

big-O notation Big-O Notation is the most widely used method which describes algorithm - PPT Presentation

the execution time required or the space used in memory or in disk by an algorithm Big O notation is used describe the rough estimate of the number of steps to complete the algorithm Definition ID: 1018183

part big time complexity big part complexity time notation dosomething int space parameter takes algorithm large number examplebigo rule

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "big-O notation Big-O Notation is the mos..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. big-O notation

2. Big-O Notation is the most widely used method which describes algorithm complexity:the execution time required orthe space used in memory or in disk by an algorithm Big O notation is used describe the rough estimate of the number of “steps” to complete the algorithmDefinition

3. Assume that doSomething() takes C steps to completePart 1:It does doSomething()So it takes constant C stepsC is independent to the parameter n When the time complexity is independent to the parameter, big-O notation is O(1)Part 2:It does doSomething() n timesEach time it takes C stepsSo in total it takes n*C steps to complete Then big-O is n*O(1) due to Part1Important rule, a*O(n) = O(an)So the time complexity is n*O(1) is O(n)Part 3:It has two loops. Inner one is same as Part2. Outer loop does Part2 n times So the time complexity is n*O(n)=O(n2)Part 4:It takes exactly 1 step to returnSo time complexity O(1)void exampleBigO(int n){ // part 1 doSomething(); // part 2 for(int i=0; i<n; i++) doSomething(); // part 3 for(int i=0; i<n; i++) for(int j=0; j<n; j++) doSomething(); // part 4 return;}

4. So total time complexity for exampleBigO(int n) function is equal to sum of time complexities of all parts:O(1)+ O(n)+O(n2)+O(1)If the parameter n becomes a very large numberThen Part 1 and Part 4 can be ignored because they are not dependent to the parameter n and spend very less time comparing to Part 2 and Part 3When the parameter n becomes extremely large number, then Part 2 also can be ignoredSo when add up big-O notations, the notation with slower increase speed could be ignored by the notation with faster increase speed. So result big-O notation for exampleBigO() isO(n2)Big-O for time complexity

5. O(1) * O(n) = O(n)O(n) * O(n) = O(n2)O(1) + O(n) = O(n)O(n) + O(n2) = O(n2)O(1) + O(n) + O(n2) = O(n2)Comparison of increase speed:O(1) < O(log(n)) < O(n) < O(nlog(n)) < O(n2)Rules summary for big-O

6. Comparison of AlgorithmsOften algorithm with smaller big-O notation is more efficientBut it may not be correct for small scale of dataBut this rule will be efficient for very large number of dataBecause computer science is always dealing with large scale of data this rule is applicable

7. It is easier to understand using big-O to estimate space complexity as it is more concreteWhen number of elements of an array is constant C and which is independent to n, then the space complexity for using the array is Cn which isO(n)*O(C) = O(n)*O(1) =O(n)When comparing different algorithms, often compare how much ‘extra’ space complexity is needed to solve the problemThe algorithm that needs an extra array of size n is not as good as the one which only needs two variablesO(1) is more efficient then O(n) big-O space complexity