Assignment 1
Assignment 1
Assignment – 1:
1)Big O:
Y(x) is a non-negative function defined over non-negative x values. We say Y(x) is Big-Oh
of f(x) if there is a positive constant a where the following inequality holds: Y(x)<=a.f(x).
Big Omega:
Y(x) is a non-negative function defined over non-negative x values. We say Y(x) is Big-
Omega of f(x) if there is a positive constant a where the following inequality holds:
Y(x)>=a.f(x).
Small o:
f(x) = o(g(x)) (small-oh) means that the growth rate of f(x) is asymptotically less than to the
growth rate of g(x).
Small Omega:
f(x) = ω(g(x)) (small-omega) means that the growth rate of f(x) is asymptotically greater than
the growth rate of g(x).
Theeta:
We say a function Y(x) is Theta(f(x)) if it is both Big O(f(x)) and Big Omega(f(x)) i.e Y(x) =
O(f(x)) and proof Y(x) = Ω(f(x)).
2) using MATPLOTLIB:
import numpy as np
x1=np.arange(0,100)
y1=4*(x1**2.8)+25
plt.plot(x1,y1,label="4n^(2.8)+25")
x2=np.arange(0,100)
y2=x2**3
plt.plot(x2,y2,label="n^3")
plt.legend()
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
#include<stdio.h>
int main()
int number;
printf("Number: \n");
scanf("%d", &number);
sqrt = number / 2;
temp = 0;
while(sqrt != temp){
temp = sqrt;
}
4) Program to find GCD of two numbers using C:
#include <stdio.h>
int main()
gcd = i;
return 0;
}
5) Bubble sort: The time complexity is O(n^2). It happens when we have a reverse sorted
array, as in that case, we will have to make all the passes.
Selection sort: The time complexity is O(n^2) as to find the minimum element at every
iteration, we will have to traverse the entire unsorted array.
Insertion sort: The time complexity is O(n^2). It occurs when we have a reverse sorted
array, as in that case, to find the correct position for any element, we will have to fully
traverse the sorted array each time.
Space complexity is O(1) for all three algorithms as we don’t need to take any extra space to
sort them, thus making them in-place algorithms.
#include <stdio.h>
int main()
int n1,n2,n3;
scanf("%d", &a[i]);
scanf("%d",&n2);
scanf("%d", &b[i]);
n3 = n1 + n2;
c[i] = a[i];
int temp;
temp = c[i];
c[i] = c[j];
c[j] = temp;
printf(" %d ",c[i]);
return 0;
}
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
#define N 15
int i = low - 1;
int j = high + 1;
while (1)
do {
i++;
do {
j--;
if (i >= j) {
return j;
}
swap(a[i], a[j]);
return;
int main()
int arr[N];
srand(time(NULL));
quicksort(arr, 0, N - 1);
return 0;
quicksort(arr, l, i - 1);
quicksort(arr, i + 1, r);
}
Time complexity of quick sort is O(n log(n)) and space complexity is O(n).