Big O, LL, Stack, Array
Big O, LL, Stack, Array
pyq
HDD(hard disc drive) se data lete hain(retrieve karte hain), update karte hain fir send
legacy data purana data hota hain joki main data se alag rakha jata hain
ya acha algo bade input ke liye kam time me run hota hain
Source: https://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it
pyq
memory/storage
O(n) kyunki n! ke liye n calls hongin too stack me max utni jagah ghiregi jitni
function ko n times call karne me ghirti
URBAN
Time Complexity – Competitive Practice Sheet
1. Fine the time complexity of the func1 function in the program show in program1.c as follows: O(length)
#include <stdio.h>
int main()
{
int arr[] = {3, 5, 66};
func1(arr, 3);
return 0;
}
2. Fine the time complexity of the func function in the program from program2.c as follows: O(n^2)
void func(int n)
{
int sum = 0;
int product = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
printf("%d , %d\n", i, j);
}
}
}
3. Consider the recursive algorithm above, where the random(int n) spends one unit of time to return a
random integer which is evenly distributed within the range [0,n][0,n]. If the average processing time
is T(n), what is the value of T(6)?
6
int function(int n)
{
int i;
if (n <= 0)
{
return 0;
}
else
{
i = random(n - 1);
printf("this\n");
return function(i) + function(n - 1 - i);
}
}
5. The following simple code sums the values of all the nodes in a balanced binary search tree. What is its
runtime? O(n) where n's no. of nodes
return 1;
}
isPrime();
Sequential Search
(worst case)
pyq