AsympNotn Pointers Strings
AsympNotn Pointers Strings
3) For the functions nk and cn, what is the asymptotic relationship between
these functions? Assume that k > 1 and c > 1 are constants.
4) Given an integer array of size N, we want to check if the array is sorted (in
either ascending or descending order). An algorithm solves this problem by
making a single pass through the array and comparing each array element only
with its adjacent elements. Analysis of the worst-case time complexity of this
algorithm.
int a = 0;
for (i = 0; i < N; i++) {
for (j = N; j > i; j--) {
a = a + i + j;
}
}
8) What is the time complexity of the following code:
int i, j, k = 0;
for (i = n / 2; i <= n; i++) {
for (j = 2; j <= n; j = j * 2) {
k = k + n / 2;
}
}
9) Analysis of the time and space complexity of the following code.
int a = 0, b = 0;
for (i = 0; i < N; i++) {
a = a + rand();
}
for (j = 0; j < M; j++) {
b = b + rand();
}
f(n) = 2^n
g(n) = n!
h(n) = n^logn
Which of the following statements about the asymptotic behavior of f(n), g(n),
and h(n) is true?
(a) f(n) = O(g(n)); g(n) = O(h(n))
(b) f(n) = omega (g(n)); g(n) = O(h(n))
(c) g(n) = O(f(n)); h(n) = O(f(n))
(d )h(n) = O(f(n)); g(n) = omega (f(n))
15) Consider the following function: f(n)=3n2+2n log n+10. Determine the Big-
O complexity of f(n).
17)Explain why the function g(n)=2n grows asymptotically faster than any
polynomial function of n.
20)If the time taken by two programs is T(n) = a*n + b, and V(n) = c*n2 + d*n + e.
Then, which program will be more efficient?
21) Find the upper bound of the running time of a linear function f(n) = 6n + 3
22)Find the upper bound of the running time of quadratic function f(n) = 3n2 +
2n + 4.
23)Find the lower and tight bound of the running time of the following function
i) f(n) = 6n + 3.
ii) f(n) = 3n2 + 2n + 4
iii) f(n) = 2n3 + 4n + 5
Pointers
24) How do you declare a pointer to a function that takes two integers and
returns an integer in C?
a) int(*ptr)(int,int);
b) ptr(int,int) int;
c) function int (*ptr)(int,int);
d) ptr function(int,int) int;
a) 30
b) value of x
c) address of x
d) Error
29) If X, Y and Z are pointer variables of type char, int and float,
respectively in ‘C’ language, then which of the following statements is true?
a) Size of X, Y and Z are same
b) Size of Z is greater than the size of X
c) Size of Y is greater than the size of X
d) Size of Z is greater than the size of Y
a) 910
b) 920
c) 870
d) 900
a) Pointer to a pointer
b) Pointer to an array of chars
c) Pointer to function taking char* argument and returns an int
d) Throws an error
33) What would be the equivalent pointer expression for referring the array
element a[i][j][k][l]
a) ((((a+i)+j)+k)+l)
b) *(*(*(*(a+i)+j)+k)+l)
c) (((a+i)+j)+k+l)
d) ((a+i)+j+k+l)
int main()
{
int x = 5, y = 10;
swap(&x, &y);
printf("x = %d, y = %d", x, y);
return 0;
}
a) 2
b) 3
c) 4
d) Undefined behavior
37) If ptr is a pointer to int, having value ptr = 100. After ptr++, what is the
value of ptr?
a) 100
b) 101
c) 102
d) 103
a) ho
b) he
c) h l
d) Undefined behavior
a) 1
b) 2
c) 3
d) Error
42) What is the output of the following program:
main()
{
char c[2] = "A" ;
printf ( "\n%c", c[0] ) ;
printf ( "\n%s", c ) ;
}
a) n1 = 10, n2 = 9
b) n1 = 10, n2 = 10
c) n1 = 9 , n2 = 9
d) n1 = 9 , n2 = 10