A positive integer which is only divisible by 1 and itself is a prime number. Write a program to determine whether a positive integer, n, is prime and the worst-case running time of your program should be O(y/n). Please determine the running time of merge sort (a) sorted input (b) reverse-ordered input (c) random input
int number, i, flag = 0;
printf(“Enter a positive integer: “);
for(i=2; i<=number/2; ++i)
printf(“%d is a prime number.”,number);
printf(“%d is not a prime number.”,number);
For given scenarios running time depends on implementation. When they are naively implemented, merge sort indeed uses O(n * log n) time.
Ans: O(n * log n) for all three scenarios.