Types of Algorithm and Its Complexity Analysis
In this post, we will learn types of Algorithm and its time complexity analysis with examples An algorithm is divided into two forms called iterative and recursive, as shown above. Firstly, we analyze the time complexity of the iterative algorithm and then recursive. Example 1: A() { int i; for(i=1 to n) % loop run n times pf("deepa"); } First, the above function is fall into the independent category. Hence, the running time of the loop will be n and it print the particular name n times. Therefore, the worst case time complexity of this algorithm will be O(n). Example 2: A() { int i; for(i=1, i^2<=n, i++) printf("deepa"); } Similarly
Comments
Post a Comment