This document analyzes the time complexity of various algorithms. It presents 10 cases of nested loops and discusses how their running time depends on the input size n. It then provides two examples to calculate the time taken to sort a telephone directory of 109 mobile users using both a naive O(n2) sorting algorithm and an efficient O(nlogn) algorithm. Finally, it presents a function containing nested loops and asks to analyze its time complexity.
This document analyzes the time complexity of various algorithms. It presents 10 cases of nested loops and discusses how their running time depends on the input size n. It then provides two examples to calculate the time taken to sort a telephone directory of 109 mobile users using both a naive O(n2) sorting algorithm and an efficient O(nlogn) algorithm. Finally, it presents a function containing nested loops and asks to analyze its time complexity.
This document analyzes the time complexity of various algorithms. It presents 10 cases of nested loops and discusses how their running time depends on the input size n. It then provides two examples to calculate the time taken to sort a telephone directory of 109 mobile users using both a naive O(n2) sorting algorithm and an efficient O(nlogn) algorithm. Finally, it presents a function containing nested loops and asks to analyze its time complexity.
Asst Professor, Dept. of Computer Science Measuring Input Size If input size is longer ,the algorithm runs for longer time. Running time depends on input size Efficiency of an algorithm is computed as a function to which input size is passed as a parameter
7 Ms Sunu Mary Abraham 7/12/2021
Asst Professor, Dept. of Computer Science Problem: Compiling Telephone directory for mobile users(109 Mobile users in India) in some sorted order. Assume typical CPU’s process up to 108 op/sec (approx. calc) • Naive sorting algorithm - Complexity- n2 How much time is taken for sorting the directory ? • nlogn sorting algorithm - Complexity-nlogn How much time is taken for sorting the directory ?
8 Ms Sunu Mary Abraham 7/12/2021
Asst Professor, Dept. of Computer Science Problem: void function(int n) { int count = 0;
for (int i=0; i<n; i++)
for (int j=i; j< i*i; j++)
if (j%i == 0) { for (int k=0; k<j; k++) printf("*"); } }
9 Ms Sunu Mary Abraham 7/12/2021
Asst Professor, Dept. of Computer Science 10 Ms Sunu Mary Abraham 7/12/2021 Asst Professor, Dept. of Computer Science