0% found this document useful (0 votes)
199 views76 pages

C++ and Data Structures MCQs

The document contains 30 multiple choice questions related to data structures and algorithms. Some key topics covered include: 1) Operator precedence, data types, logical and relational operators, and evaluating expressions. 2) Linked lists, time complexity of operations, and data structures used to evaluate postfix expressions and sort lists. 3) Representation of data in memory, bounds of arrays, recursion, and algorithms. 4) File I/O operations, file opening modes, and using function pointers to pass parameters. The questions assess a variety of foundational concepts in programming and data structures.

Uploaded by

Rushi Ghonse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views76 pages

C++ and Data Structures MCQs

The document contains 30 multiple choice questions related to data structures and algorithms. Some key topics covered include: 1) Operator precedence, data types, logical and relational operators, and evaluating expressions. 2) Linked lists, time complexity of operations, and data structures used to evaluate postfix expressions and sort lists. 3) Representation of data in memory, bounds of arrays, recursion, and algorithms. 4) File I/O operations, file opening modes, and using function pointers to pass parameters. The questions assess a variety of foundational concepts in programming and data structures.

Uploaded by

Rushi Ghonse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

1)Which of the following type of operators have higher precedence_____

a)Relational operators b)equality operators


c)Logical operators d)Arithmatic operators
ans-Arithmatic operators

2)Which of the following operators takes only integer operands?


a)+ b)/ c)% d)*
ans-%

3)Which of the operators associate from left?


a)+ b)> c)% d)all of these
ans-all of these

4)If a,b,c are integer variables with values 1,2,3 respectively, then what is the value of the
expression
!((a+5)<(b+c))
a)0 b)6 c)5 d)1
ans-1

5) Give the value of x after execution of given code.


x=5
x=x++ +++x-x;
a)5 b)7 c)6 d)0
ans-7

6)Construct a logical expression to check whether x is largest among three numbers x,y,z
a)x>y&&x>z b)!(x<=y||x<=z) c)x>y,z d)both a and b
ans-d

Q.7 In a circular linked list……….


(A) components are all linked together in some sequential manner.
(B) there is no beginning and no end.
(C) components are arranged hierarchically.
(D) forward and backward traversal within the list is permitted.
Ans:B
Q.8 In a linked list with n nodes, the time taken to insert an element after an element pointed
by some pointer is……..
(A) 0 (1) (B) 0 (log n) (C) 0 (n) (D) 0 (n 1og n)
Ans:A
Q.9 The data structure required to evaluate a postfix expression is …….
(A) queue (B) stack (C) array (D) linked-list
Ans:B
Q.10 Which of the following sorting methods would be most suitable for sorting a list which
is almost sorted …………
(A) Bubble Sort (B) Insertion Sort
(C) Selection Sort (D) Quick Sort
Ans:A
Q.11 Representation of data structure in memory is known as………….
(A) recursive (B) abstract data type
(C) storage structure (D) file structure
Ans:B
Q.12 The largest element of an array index is called its………..
(A) lower bound. (B) range.
(C) upper bound. (D) All of these.
Ans. (C)
Q.13 Which data structure is used for implementing recursion?
(A) Queue. (B) Stack.
(C) Arrays. (D) List.
Ans. (B)

Q.14 Null character needs a space of……………


A. zero bytes B. one byte
C. three bytes D. four bytes
Ans. (B)
Q.15 …………gives the step-by-step procedure for solving the problem which gives correct
solution.
A.Algorithm B.Array
C.Link List D.None of the above
Ans.(A)
Q.16 Which of the followings are derived data types?
A.Array B.String
C.Float D.Both ‘a’ &’b’
Ans.(D)
Q.17 Which of the followings are application of data structure?
A.Facebook B.Searching
C.Sorting D.All of the above
Ans.(D)
Q.18 Which of the following data structure is not linear data structure?
A.Array B.Linked List
C.Both of above D.None of above
Ans.(A)
Q.19 Which of the following steps are correct for solving the problem?
A.Identify the problem B.Explore information & create ideas
C.Select the best ideas D.All of these
Ans.(D)
Q20) In how many blocks Problem Analysis Chartis divided?
A) 2 B)3 C)4 D)5
Ans.(C)
Q21) Interactivity Chart is divided into subtasks called _____.
A) Function
B) Module
C) Sub program
D) None
Ans. (B)
Q 22) what is full form of IPO?
A) Input-Program-Output B) Input-Parallel-Output
C)Input-Processing-Output D) Inbuilt- Processing-Output
Ans.(C)
Q23) Algorithms are similar to____
A) Flowchart
B) Pseudo code
C) Interactivity chart
D) Problem Analysis Chart
Ans. (B)

Q24) Flowcharts can show errors in ____ which is not readily visible in the other charts.
A) Arithmetic operations
B) Logic
C) Code
D) All of these
Ans. (B)

Q25) Which equation is to be satisfied to find the BIG-O?


A) F(n)=c*g(n)
B) F(n)>=c*g(n)
C) F(n)<=c*g(n)
D) None
ANS:C

Q26) Time Complexity is


A) Time required for the machine to compile the program.
B) Time required for the machine to execute the program.
C) Time required for the machine to debug the program.
D) None
ANS:B

Q27) Step count for the following loop is


For(int i=5; i>0; i++)
A) 5 times
B) N+1 times
C) Infinite
D) No execution
ANS:C

Q28) which of the following is not an asymptotic notation?


A) BIG-O
B) Omega
C) Phi
D) Theta
ANS:C
Q29) What is the step count of 5th line?
1. For(int i=0, i<4, i++)
2. {
3. For(int j=5; j>0; j--)
4. {
5. Cout<<A[i][j];
6. }
7. }
A) 16
B) 25
C) 20
D) 5
ANS:C

Q.30 Which of the following character used for null….?


a) /0 b)\0 c)/n d)\n

Q.31 which of the following is not datatype…?


a)float b)long int c)long float d)long string

Q.32 Variable is…………..


a) used to store a data value
b) used to store address
c) it has fixed value
d) none of these
Q.33 In c++ float datatype allocate……..memory.
a) 4byte b) 8byte c)16byte d)1byte
Q.34 In c float datatype allocate……..memory.
a) 8byte b) 4byte c)16byte d)1byte
Q.35 For function which is sequence of syntax…?
a) define-calling-declaration
b) declaration-define-calling
c) calling-define-declaration
d) none of these

Q.36. The function written by the user according to requirement known


As…………..
a) mathematical function b) string function
c) user define function d) none of above
Q.37. Which of the following is syntax for declaration of array…?
a) datatype array_name[size]
b) datatype string name[size]
c) datatype [size] array_name
d) none of these
Q38. Which of the following is type of function…?
a) mathematical function b) statistical function
c) utility function d) all of above
Q39. Array is……….datatype
a) homogenous datatype b) heterogenous datatype
c) both a & b d) none of above
Q40. The smallest element of an array index called……
a) lower bound b) upper bound c) range d) none of above

JSPM's
Jayawantrao Sawant College Of Engineering, Hadapsar,Pune-28
Department of Information Technology

Multiple Choice Questions


UNIT-II
Class: SE IT Subject: FDS

1) The value of eof is


a) -1
b) 1
c) 0
d) 10
ans:a

2) What is FILE in following declaration?


a) Keyword
b) File
c) Structure
d) Array

2) Which is file opening mode?


a) r
b) w
c) wb
d) all of the above
3) choose correct declaration
a) int main(intargc,char *argv)

{}
b) int main(intargc,char *argv[])
{}
c) int main(int *argc,char *argv)
{}
d) int main()
{int *argc,char *argv}

Ans D

4) what is output of the following program?


Void main()
{
File *fp;
Fp=fopen(“d:\\input,dat”,”w”);
Printf(“%d\n”,ferror(fp));0
}
a) 0
b) -1
c) 1
d) None of these

5) Which of the following file type can’t be opened using fopen()?


a) .txt
b) .dat
c) .bin
d) None of these

6) How to call a function without using the function name to send parameters?
a) typedefs
b) Function pointer
c) Both (a) and (b)
d) None of the mentioned
Answer:b

7) Correct syntax to pass a Function Pointer as an argument


a) void pass(int (*fptr)(int, float, char)){}
b) void pass(*fptr(int, float, char)){}
c) void pass(int (*fptr)){}
d) void pass(*fptr){}
Answer:a
8. Which of the following is not possible in C?
a) Array of function pointer
b) Returning a function pointer
c) Comparison of function pointer
d) None of the mentioned

Answer:d

9. What is the output of this C code?

#include <stdio.h>
void first()
{
printf("Hello World");
}
void main()
{
void *ptr() = first;
ptr++
ptr();
}

a) Illegal application of ++ to void data type


b) pointer function initialized like a variable
c) Both (a) and (b)
d) None of the mentioned

Answer:c

10) What will be output of the following?


void main()
{
Inta[]={1,2,3,4,5},j;
For(j=0;j<5;j++)
{
Printf(“%d”,*a);
a++;
}
}
a) Syntax error
b) Run time error
c) 12345
d) Garbage 1234

11) what will be output of following?


#include<stdio.h>
Void main()
{
Int a=10;
Int*b=&a;
Int**c=&b;
**c=20;
Printf(“%d”,a);
}
a) 10
b) 20
c) Garbage value
d) Syntax error

12) what will be o/p of following code?


Void main()
{
Intarr[]={10,20,30};
Int *p=arr;
Int *q=&p;
Printf(“%d”,(**q));
}

a) 10
b) 20
c) Sytax error
d) Runtime error

13) Output of following code?


Intmain()
{
Char *str;
Str=”%d\n”;
Str++;
Str++;
Printf(str-2,500);
Return 0;
}
a) 5
b) 50
c) 500
d) No o/p

14) how many no. Of pointer to pointer can be declared in C?


a) 7
b)127
c)255
d)no limit Ans:d

15) what is o/p of code?


Intmain()
{
Int i=10,*a;
Void *b;
a=b=&i;
printf(“%u%u”,a++,b++);
return 0;
}
a) 10 garbage value
b) Add will be display twice
c) Syntax error
d) None of these

16) Pointers are supported in

a. C
b. Fortron
c. Pascal
d. Both b&c ans:d

17)Identify invalid expression


a)&274
b)&(a+b)
c)&(a*b)
d)all of the above ans:d

18)main()
{
Int a=5;
Ptr=&a;
Printf(“%d”,++*ptr);

Output will be:


a)6
b)5
c)0
d)none
ans:a

19)Number of argument use in malloc is

a) 0
b) 1
c) 2
d) 3
ans:1
20) The no. Of argument use in realloc is
a) 0
b) 1
c) 2
d) 3
ans:c
21) the function is use in dynamic deallocation is
a) Destroy()
b) Delet()
c) Free
d) Remove()
ans:c

22) the function call realloc(ptr,0)is


a) Same as free (ptr)

b) Used to set the value of ptr to be 0

c) the value of in the address represented by ptr

d) Invalid

ans:a

23) pointers can be used to achive


a) Call by function
b) Call by refrance
c) Call by name
d) Call y procedure
ans:b

24) the declaration of float *a[5] is


a) An ordinary array
b) A pointer to an array
c) Ann array to an pointer
d) Pointer to an array
ans:c

25) The declaration int (*p)[8];


a) An array of pointer
b) A pointer to an array
c) Pointer to function
d) Function returing pointer
ans:b

26) Given int a[5][5];identify the correct expression ,yielding the starting element.
a) *a[0]
b) **a
c) a[0][0]
d) all of these
ans:d

27) Given int x[5][5][5];find value of the element x[2][3][4]


a) *(x[2][3]+4)
b) *(*(x[2]+3)+4)
c) *(*(*(x+2)+3)+4)
d) All of the above

28)The oprators used in pointr is


a) *and/
b) &and*
c) &and|
d) –and>

ans:b

29) main()
{
Inta[5]={-2,-1,3,4,5}
Int*b;
b=&a[2];
}
Then value of b[-1] is:
a) 4
b) 3
c) -1
d) -2
ans:c
30)identify invalid pointer oprator
a) &
b) >>
c) *
d) None of these
ans:b

31)Identify the wrong declaration statement.


a)int *p,a=10;
b)int a=10,*p=&a;
c)int *p=&a,a=10
d)options a and b
32) Identify the invalid expression given
intnum=15,*p=&num;
a)*num
b)*(&num)
c)*&*&num
d)**&p
33) Identify the invalid expression given float x=2.14,*y=&x;
a)&y
b)*&x
c)**&y
d)(*&)x
34)The operand of the address of operator is
a)a constant
b)an expression
c)a named region of storage
d)a register variable

35)How does compiler differentiate address of operator from bitwise AND operator?
a)by using the number of operands and the position of operands
b)by seeing the declarations
c)both options a and b
d)by using the value of the operand

36)How does compiler differentiate indirection operator from multiplication operator?


a) by using the number of operands
b) by seeing the position of operands
c) both options a and b
d)by using the value of the operand

37)The address of operator returns


a)the address of its operand
b)lvalue
c) both options a and b
d)rvalue

38)The indirection operator returns


a)the data object stored in the address represented by its operand
b)lvalue
c)both options a and b
d)rvalue

39)The operand of indirection operator is


a)pointer variable
b)pointer expression
c)both options a and b
d)ordinary variable

40)The operand of address of operator may be


a)an ordinary variable
b)an array variable
c)a pointer variable
d)Any one of above
41)Identify the invalid lvalue given int x,*p=&x;
a)*(p+1)
b)*(p-3)
c)both options a and b
d)&x

42)After the execution of statement int x; the value of x is


a)0
b)undefined
c)1
d)-1

43)Pointer variable may be initialized using


a)static memory allocation
b)dynamic memory allocation
c)both options a and b
d)a positive integer

44)Given the declaration double prec[5]; the address of element prec[2]is obtained
a)&prec[2]
b)prec+2
c)both options a and b
d)*(prec+2)

45)Identify the correct statement for given expression


floatfnum[10];
a)fnum is pointer variable
b)fnum is fixed address and not a variable.
c)fnum is an array variable
d)fnum is an address that can be modified.

46)Which is the correct function header for function main()?


a)main(intargc, char *argv[])
b)main(intargc, char **argv)
c)main(intargc, char *av[])
d)all the above

47)The invalid address arithmetic is


a)adding two pointers
b)multiplying two pointers
c)dividing two pointers
d)all the above

48)Identify the invalid assignment,for given int *p,x;


a)p=0;
b)p=255864u
c)p=&x
d)*p=10
49)Identify the invalid expression for given syntax:
float fnum[10],*fptr=fnum;
a)fnum+4
b)fnum[4]
c)fnum=++fptr
d)&fnum[4]

50)The operators &,*,++ and – have


a)same procedure level and same associativity
b)same associativity and different precedence level
c)different precedence level and different associativity
d)different precedence level and same associativity

51.What is the output of this C code?

#include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c;
}
void main()
{
int (*function_pointer)(int, int, int);
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}

a) The product of three numbers is:24


b) Run time error
c) Nothing
d) Varies

Answer:a

52. What is the output of this C code?

#include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c;
}
void main()
{
int (function_pointer)(int, int, int);
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}

a) The product of three numbers is:24


b) Compile time error
c) Nothing
d) Varies

Answer:b

53. What is the output of this C code?

#include <stdio.h>
void f(int (*x)(int));
int myfoo(int);
int (*fooptr)(int);
int ((*foo(int)))(int);
int main()
{
fooptr = foo(0);
fooptr(10);
}
int ((*foo(int i)))(int)
{
return myfoo;
}
int myfoo(int i)
{
printf("%d\n", i + 1);
}

a) 10
b) 11
c) Compile time error
d) Undefined behaviour

Answer:b

54. Which is an indirection operator among the following?


a) &
b) *
c) ->
d) .

Answer:b

55. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned

Answer:a

56. What is the output of this C code?

#include <stdio.h>
int x = 0;
void main()
{
int *ptr = &x;
printf("%p\n", ptr);
x++;
printf("%p\n ", ptr);
}

a) Same address
b) Different address
c) Compile time error
d) Varies

Answer:a

57. What is the output of this C code?

#include <stdio.h>
int x = 0;
void main()
{
int *const ptr = &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}

a) 0 1
b) Compile time error
c) 0xbfd605e8 0xbfd605ec
d) 0xbfd605e8 0xbfd605e8

Answer:b

58. What is the output of this C code?

#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}

a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error

Answer:a

59. What is the output of this C code?

#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &5;
printf("%p\n", ptr);
}

a) 5
b) Address of 5
c) Nothing
d) Compile time error

Answer:d

60. What is the output of this C code?

#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}

a) 5
b) Compile time error
c) 6
d) Junk

Answer:c

61. What is the output of this C code?

#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));
}

a) 1
b) Compile time error
c) Address of a
d) Junk value

Answer:b

62. What is the output of this C code?

#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}

a) Different address is printed


b) 1 2
c) Same address is printed.
d) 1 1

Answer:c

63. How many number of pointer (*) does C have against a pointer variable declaration?
a) 7
b) 127
c) 255
d) No limits.

Answer:d

64. What is the output of this C code?

#include <stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
int **sptr = &ptr1; //-Ref
*sptr = ptr2;
}

a) ptr1 points to a
b) ptr1 points to b
c) sptr points to ptr2
d) None of the mentioned

Answer:b

65. What is the output of this C code?

#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}

a) Different address is printed


b) 1 2
c) Same address is printed.
d) 1 1

Answer:c

66. What substitution should be made to //-Ref such that ptr1 points to variable C?

#include <stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a;
int **sptr = &ptr1;
//-Ref
}

a) *sptr = &c;
b) **sptr = &c;
c) *ptr1 = &c;
d) None of the mentioned.

Answer:a

67. Which of the following declaration throw run-time error?


a) int **c = &c;
b) int **c = &*c;
c) int **c = **c;
d) None of the mentioned

Answer:d

68. Comment on the output of this C code?

#include <stdio.h>
int main()
{
int a = 10;
int **c -= &&a;
}

a) You cannot apply any arithmetic operand to a pointer.


b) We don’t have address of an address operator
c) Both (a) and (b)
d) None of the mentioned.

Answer:b

69. What is the output of this C code?

#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));
}

a) 1
b) Compile time error
c) Address of a
d) Junk value

Answer:b

70. Comment on the output of this C code?

#include <stdio.h>
int main()
{
char *str = "This" //Line 1
char *ptr = "Program\n"; //Line 2
str = ptr; //Line 3
printf("%s, %s\n", str, ptr); //Line 4
}
a) Memory holding “this” is cleared at line 3
b) Memory holding “this” loses its reference at line 3
c) You cannot assign pointer like in Line 3
d) Output will be This, Program

Answer:b

71. What type initialization is needed for the segment “ptr[3] = ’3′;” to work?
a) char *ptr = “Hello!”;
b) char ptr[] = “Hello!”;
c) Both (a) and (b)
d) None of the mentioned

Answer:b

73. The syntax for constant pointer to address (i.e., fixed pointer address) is:

a) const <type> * <name>


b) <type> * const <name>
c) <type> const * <name>
d) Both (a) and (c)
Answer:b

74. Comment on the output of this C code?

#include <stdio.h>
int add(int a, int b)
{
return a + b;
}
int main()
{
int (*fn_ptr)(int, int);
fn_ptr = add;
printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3));
}

a) Compile time error, declaration of a function inside main.


b) Compile time error, no definition of function fn_ptr.
c) Compile time error, illegal application of statement fn_ptr = add.
d) No Run time error, output is 5.

Answer:d

75. The correct way to declare and assign a function pointer is done by:
(Assuming the function to be assigned is “int multi(int, int);”)
a) int (*fn_ptr)(int, int) = multi;
b) int *fn_ptr(int, int) = multi;
c) int *fn_ptr(int, int) = &multi;
d) Both (b) & (c)

Answer:a

76. Calling a function f with a an array variable a[3] where a is an array, is equivalent to
a) f(a[3])
b) f(*(a + 3))
c) f(3[a])
d) All of the mentioned

Answer:d

77. What is the output of this C code?

#include <stdio.h>
void f(char *k)
{
k++;
k[2] = 'm';
}
void main()
{
char s[] = "hello";
f(s);
printf("%c\n", *s);
}

a) h
b) e
c) m
d) o;

Answer:a

78.What is the output of this C code?

#include <stdio.h>
void main()
{
char s[] = "hello";
s++;
printf("%c\n", *s);
}

a) Compile time error


b) h
c) e
d) o
Answer:a

81. What is the output of this C code?

#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "hello";
printf("%s", s->c);
}

a) hello
b) Run time error
c) Nothing
d) Depends on compiler

Answer:a

82. What is the output of this C code?

#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student *s;
s->c = "hello";
printf("%s", s->c);
}

a) hello
b) Segmentation fault
c) Run time error
d) Nothing

Answer:b

83. What is the output of this C code?

#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "hello";
printf("%s", m.c);
}

a) Run time error


b) Nothing
c) hello
d) Varies

Answer:c

84. What is the output of this C code?

#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
(*s).c = "hello";
printf("%s", m.c);
}

a) Run time error


b) Nothing
c) Varies
d) hello

Answer:d

85. What is the output of this C code?

#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student n;
struct student *s = &n;
(*s).c = "hello";
printf("%p\n%p\n", s, &n);
}
a) Different address
b) Run time error
c) Nothing
d) Same address

Answer:d

86. What is the output of this C code?

#include <stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}

a) Compile time error


b) Segmentation fault/code crash
c) 2
d) 1

Answer:b

87. What is the output of this C code?

#include <stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1 = (struct q*)&p1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[0]);
}
a) Compile time error
b) Undefined behaviour
c) Segmentation fault/code crash
d) 1

Answer:b

88. What is the output of this C code?

#include <stdio.h>
struct p
{
int x;
int y;
};
int main()
{
struct p p1[] = {1, 2, 3, 4, 5, 6};
struct p *ptr1 = p1;
printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
}

a) 1 5
b) 1 3
c) Compile time error
d) 1 4

Answer:a

89. What is the output of this C code?

#include <stdio.h>
struct p
{
int x;
char y;
};
int main(){
struct p p1[] = {1, 92, 3, 94, 5, 96};
struct p *ptr1 = p1;
int x = (sizeof(p1) / sizeof(struct p));
printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
}

a) Compile time error


b) Undefined behaviour
c) 1 3
d) 1 5

Answer:d
91. What is the output of this C code (considering sizeof char is 1 and pointer is 4)?

#include <stdio.h>
int main()
{
char *a[2] = {"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}

a) 9
b) 4
c) 8
d) 10

Answer:c

92. What is the output of this C code?

#include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}

a) 9
b) 12
c) 8
d) 10

Answer:b

93. What is the output of this C code?

#include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"};
printf("%s", *a + 1);
return 0;
}

a) hello
b) hi
c) ello
d) ello hi

Answer:c
94. What is the output of this C code?

#include <stdio.h>
int main()
{
char *a[2] = {"hello", "hi"};
printf("%s", *(a + 1));
return 0;
}

a) hello
b) ello
c) hi
d) ello hi

Answer:c

95. Advantage of a multi-dimension array over pointer array.


a) Pre-defined size.
b) Input can be taken from user.
c) Faster Access.
d) All of the mentioned

Answer:d

96. Which of the following operation is possible using a pointer char?


(Assuming declaration char *a;)
a) Input via %s
b) Generation of multidimensional array
c) Changing address to point at another location
d) All of the mentioned

Answer:c

97. Comment on the following two operations?


int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2
a) 1 will work, 2 will not
b) 1 and 2, both will work
c) 1 won’t work, 2 will work
d) Neither of them will work

Answer:c

98. Comment on the following two operations?


int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2
a) 1 works, 2 doesn’t
b) 2 works, 1 doesn’t
c) Both of them work
d) Neither of them work

Answer:d

99. What does argv and argc indicate in command-line arguments?


(Assuming: int main(int argc, char *argv[]) )
a) argument count, argument variable
b) argument count, argument vector
c) argument control, argument variable
d) argument control, argument vector

Answer:b

100. Which of the following syntax is correct for command-line arguments?


a) int main(int var, char *varg[])
b) int main(char *argv[], int argc)
c) int main()
{
int argv, char *argc[];
}
d) Both (a) and (b)

Answer:a

101. In linux, argv[0] by command-line argument can be occupied by


a) ./a.out
b) ./test
c) ./fun.out.out
d) All of the mentioned

Answer:d

102. What type of array is generally generated in Command-line argument?


a) Single dimension array
b) 2-Dimensional Square Array
c) Jagged Array
d) 2-Dimensional Rectangular Array

Answer:c
103. What would be the output if we try to execute following segment of code (assuming the following
input “cool brother in city”)?
printf(“%s\n”, argv[argc]);
a) (null)
b) City
c) In
D. Segmentation Fault

Answer:a

104. The first argument in command line arguments is


a) The number of command-line arguments the program was invoked with;
b) A pointer to an array of character strings that contain the arguments
c) Nothing
d) Both a & b

105. The second (argument vector) in command line arguments is


a) The number of command-line arguments the program was invoked with;
b) A pointer to an array of character strings that contain the arguments,one per string.
c) Nothing
d) Both a & b

Answer:b

106. argv[0] in command line arguments, is


a) The name by which the program was invoked
b) The name of the files which are passed to the program
c) Count of the arguments in argv[] vector
d) Both a & b

Answer:a

((MARKS)) (1/2/3...) 1

((QUESTION)) What will be the output of the program ?


#include<stdio.h>

int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}

((OPTION_A)) 2,1,15

((OPTION_B)) 1,2,5

((OPTION_C)) 3,2,15

((OPTION_D)) 2,3,20

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an
(OPTIONAL) integer array with a size of 5 and it is initialized to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
Step 2: int i, j, m; The variable i,j,m are declared as an integer type.
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is
incremented by 1(i++ means 2++ so i=3)
Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the
variables i, j, m
Hence the output of the program is 3, 2, 15

((MARKS)) (1/2/3...) 1
((QUESTION)) In C, if you pass an array as an argument to a function, what actually

passed?
((OPTION_A)) Value of elements in array
((OPTION_B)) First element of the array

((OPTION_C)) Base address of the array

((OPTION_D)) Address of the last element of array

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) The statement 'C' is correct. When we pass an array as a funtion argument,
(OPTIONAL) the base address of the array will be passed.

((MARKS)) (1/2/3...) 1
Which of the following statements are correct about 6 used in the
((QUESTION))
program?
int num[6];
num[6]=21;
((OPTION_A)) In the first statement 6 specifies a particular element, whereas in
the second statement it specifies a type.
((OPTION_B)) In the first statement 6 specifies a array size, whereas in the second
statement it specifies a particular element of array.

((OPTION_C)) In the first statement 6 specifies a particular element, whereas in


the second statement it specifies a array size.
((OPTION_D)) In both the statement 6 specifies array size.

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) The statement 'B' is correct, because int num[6]; specifies the size of
(OPTIONAL) array and num[6]=21; designates the particular element(7thelement) of
the array.

((MARKS)) (1/2/3...) 1

((QUESTION)) What does the following declaration mean?


int (*ptr)[10];

((OPTION_A)) ptr is array of pointers to 10 integers

((OPTION_B)) ptr is a pointer to an array of 10 integers

((OPTION_C)) ptr is an array of 10 integers

((OPTION_D)) ptr is an pointer to array

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following statements are correct about an array?


1. The array int num[26]; can store 26 elements.
2. The expression num[1] designates the very first element in the
array.
3. It is necessary to initialize the array at the time of declaration.
4. The declaration num[SIZE] is allowed if SIZE is a macro.

((OPTION_A)) 1

((OPTION_B)) 1,4

((OPTION_C)) 2,3

((OPTION_D)) 2,4
((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) 1. The array int num[26]; can store 26 elements. This statement is true.
(OPTIONAL) 2. The expression num[1] designates the very first element in the array.
This statement is false, because it designates the second element of the
array.
3. It is necessary to initialize the array at the time of declaration. This
statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This
statement is true, because the MACRO just replaces the symbol SIZE
with given value.
Hence the statements '1' and '4' are correct statements.

((MARKS)) (1/2/3...) 1

((QUESTION)) The smallest element of an array index


called……

((OPTION_A)) Lower bound

((OPTION_B)) Upper bound

((OPTION_C)) Range

((OPTION_D)) None of Above

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following function is used to find the first occurrence of a
given string in another string?

((OPTION_A)) strchr()

((OPTION_B)) strrchr()

((OPTION_C)) strstr()

((OPTION_D)) strnset()
((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) char *strstr(const char *s1, const char *s2);


(OPTIONAL) Return Value:
On success, strstr returns a pointer to the element in s1 where s2 begins
(points to s2 in s1).
On error (if s2 does not occur in s1), strstr returns null.
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str1 = "IndiaBIX", *str2 = "ia", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s\n", ptr);
return 0;
}
Output: The substring is: iaBIX

((MARKS)) (1/2/3...) 1

((QUESTION)) which of the following is not an asymptotic notation?

((OPTION_A)) BIG-O

((OPTION_B)) Omega

((OPTION_C)) Phi

((OPTION_D)) Theta

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Step count for the following loop is


For(int i=5; i>0; i++)

((OPTION_A)) 5 times

((OPTION_B)) N+1 times

((OPTION_C)) Infinite
((OPTION_D)) No execution

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Time Complexity is

((OPTION_A)) Time required for the machine to compile the program.

((OPTION_B)) Time required for the machine to execute the program.

((OPTION_C)) Time required for the machine to debug the program.

((OPTION_D)) None

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following data structure is not linear data


structure?

((OPTION_A)) Array

((OPTION_B)) Linked list

((OPTION_C)) All of above

((OPTION_D)) None of above

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the followings are application of data structure?

((OPTION_A)) Facebook
((OPTION_B)) Searching

((OPTION_C)) Sorting

((OPTION_D)) All of above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which data structure is used for implementing recursion?

((OPTION_A)) Queue

((OPTION_B)) Stack

((OPTION_C)) Array

((OPTION_D)) List

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Representation of data structure in memory is known


as………….
((OPTION_A)) recursive

((OPTION_B)) Abstract Data Type

((OPTION_C)) Storage Structure

((OPTION_D)) File Structure

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1
((QUESTION)) In a linked list with n nodes, the time taken to insert an
element after an element pointed by some pointer is……..
((OPTION_A)) O (1)
((OPTION_B)) O(log n)

((OPTION_C)) O(n)

((OPTION_D)) O(n log n)

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) In a circular linked list……….


((OPTION_A)) components are all linked together in some sequential
manner.

((OPTION_B)) there is no beginning and no end.


((OPTION_C)) components are arranged hierarchically.
((OPTION_D)) forward and backward traversal within the list is permitted.
((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following operators takes only integer


operands?

((OPTION_A)) +

((OPTION_B)) /

((OPTION_C)) %

((OPTION_D)) *

((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) NULL pointer is used to define .....

((OPTION_A)) End of the linked list

((OPTION_B)) Empty list

((OPTION_C)) Empty pointer field of the structure

((OPTION_D)) All of above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The function that return memory to heap is called...........

((OPTION_A)) Allloc()

((OPTION_B)) Malloc()

((OPTION_C)) Calloc()

((OPTION_D)) Free()

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Two main measures for the efficiency of an algorithm are

((OPTION_A)) Processor and memory

((OPTION_B)) Complexity and capacity

((OPTION_C)) Time and space

((OPTION_D)) Data and space


((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following case does not exist in complexity theory
((OPTION_A)) Best case
((OPTION_B)) Worst case

((OPTION_C)) Average case

((OPTION_D)) Null case

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The Worst case occur in linear search algorithm when

((OPTION_A)) Item is somewhere in the middle of the array

((OPTION_B)) Item is not in the array at all

((OPTION_C)) Item is the last element in the array

((OPTION_D)) Item is the last element in the array or is not there at all

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) .
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The complexity of merge sort algorithm is

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n2)

((OPTION_D)) O(n log n)

((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The input to a merge sort is 6,5,4,3,2,1 and the same input is
applied to quick sort then which is the best algorithm in this case

((OPTION_A)) Merge sort

((OPTION_B)) Quick sort

((OPTION_C)) Both have same time complexity in this case as they have same
running time
((OPTION_D)) Cannot be decided

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) If there exists two functions f(n) and g(n). The constant c>0 and
there exists an integer constant n0>=1. If f(n)<=c*g(n) for every
integer n>= n0 then we say that____
((OPTION_A)) f(n)=O(g(n))

((OPTION_B)) f(n)=Θ (g(n))

((OPTION_C)) f(n)=𝛺 (g(n))


f(n)=Θ (g(n)) f(n)=o(g(n))
((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) Basic definition of big oh notation


(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) In practice ______ is used to define tight upper bound on growth of


function f(n)

((OPTION_A)) Big oh

((OPTION_B)) Big omega

((OPTION_C)) Big theta


((OPTION_D)) None of these

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) The definition of big oh notation is f(n)<=c*g(n) which defines the


(OPTIONAL) upper bound on growth of the function f(n)

((MARKS)) (1/2/3...) 1

((QUESTION)) Examples of O(1) are ______

((OPTION_A)) Multiplying two numbers

((OPTION_B)) Assigning some value to a variable

((OPTION_C)) Displaying some integer on console

((OPTION_D)) All of the above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) All these operations are computed by single line expression evaluation
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Examples of O(n2) algorithms are

((OPTION_A)) Adding two matrices

((OPTION_B)) Finding transpose of a matrix

((OPTION_C)) Initializing all elements of the matrix by 0

((OPTION_D)) All of the above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) Within two for loops(nested), all these operations are performed.
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Choose the correct time complexity of following code__


while(n>0)
{
n=n/10
}

((OPTION_A)) O(1)
((OPTION_B)) O(n)

((OPTION_C)) O(log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((QUESTION)) The time complexity of binary search is_____

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) The list is divided at the mid and then the element is searched in either
(OPTIONAL) left half or right half.

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider recurrence relation as


T(0)=c1
T(n)=T(n-1)+c2
This can be expressed as

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) T(n)=T(n-1)+c2
(OPTIONAL) =T(n-2)+2c2
=T(n-3)+3c2
=T(n-k)+kc2
If k=n then T(n)=c1+nc2 Hence, T(n)=O(n)
((MARKS)) (1/2/3...) 1

((QUESTION)) Consider recurrence relation as


T(0)=c1 and T(1)=c2
T(n)=T(n/2)+c3
This can be expressed as

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Following is the method of solving recurrence relation

((OPTION_A)) Greedy method

((OPTION_B)) Backtracking

((OPTION_C)) Forward substitution method

((OPTION_D)) Divide and Conquer method

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The recurrence relation for factorial function is of the form _______

((OPTION_A)) T(n)=T(n-1)+c

((OPTION_B)) T(n)=T(n-1)+T(n-2)+c

((OPTION_C)) T(n/2)+c

((OPTION_D)) None of these

((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION)) The factorial function is as follows-
(OPTIONAL) fact(n)
{
if n=1
return 1
else
return n * fact(n-1)
}

((MARKS)) (1/2/3...) 1

((QUESTION)) The recurrence relation for fibonacci function is of the form

((OPTION_A)) T(n)=T(n-1)+c

((OPTION_B)) T(n)=T(n-1)+T(n-2)+c

((OPTION_C)) T(n/2)+c

((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) The fibonacci function is as follows-


(OPTIONAL) fibb(n)
{
if n = = 0
return 0
if n = = 1
return 1
else
return (fibb(n-1) + fibb(n-2))
}

((MARKS)) (1/2/3...) 1

((QUESTION)) The frequency count of following code is____


for(i=0;i<m;i++)
{
for(j=0;i<n;j++)
{
C[i][j]=a[i][j]+b[i][j];
}
}

((OPTION_A)) m + mn + mn

((OPTION_B)) m + n + mn

((OPTION_C)) m + n2 + mn

((OPTION_D)) (m+1) + m(n+1) + mn


((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider T(n)=15n3 + n2 + 4. Select the correct statement

((OPTION_A)) T(n)=O(n4)

((OPTION_B)) T(n)=𝛺 (n3)

((OPTION_C)) T(n)=𝛺 (n2)

((OPTION_D)) All of the above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Give the frequency count of 3rd Statement


for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
x=x+1;

((OPTION_A)) ½(n2+n)

((OPTION_B)) ½(n2+3n)

((OPTION_C)) n2

((OPTION_D)) (n+1)2

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) There are four algorithms for solving a problem. Their time
complexities
are O(n), O(n2), O(log n) and O(n log n). Which is the best
algorithm?

((OPTION_A)) O(n)
((OPTION_B)) O(n2)

((OPTION_C)) O(log n)

((OPTION_D)) O(n log n)

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The order of the recurrence relation ar-7ar-1+10ar-2=0 is ______.

((OPTION_A)) 3

((OPTION_B)) 2

((OPTION_C)) 1

((OPTION_D)) B

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Characteristic roots of the recurrence relation a r-2ar-1+ar-2=0 are


_______

((OPTION_A)) 1, -1

((OPTION_B)) -1, -1

((OPTION_C)) 1, 1

((OPTION_D)) None of these

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Charactristic polynomial of the recurrence relation b n=-3bn-1-bn-2 is


________.
((OPTION_A)) Z2-3Z-2=0

((OPTION_B)) Z2+3Z-2=0

((OPTION_C)) Z2+3Z+2=0

((OPTION_D)) None of these

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The general solution of the recurrence relation ar-2ar-1=0 is _____.

((OPTION_A)) ar=c1(-2)r

((OPTION_B)) ar=c2(2)r

((OPTION_C)) ar=c1(1)r

((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider the recurrence relation, an=an-1+2an-2 with a9=3 and a10=5.
Find a7.

((OPTION_A)) 1

((OPTION_B)) 3

((OPTION_C)) 5

((OPTION_D)) None

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1
((QUESTION)) Charactristic polynomial of the recurrence relation a r+2-ar-2=0 is
______.

((OPTION_A)) Z-1=0

((OPTION_B)) Z2-1=0

((OPTION_C)) (Z-1)2=0

((OPTION_D)) None

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) Given homogeneous recurrence relation can be written as


(OPTIONAL) ar+2+0ar+1+0ar+0ar-1-ar-2=0
Order of this recurrence relation is 4.
Hence characteristic polynomial is Z4-1=0

((MARKS)) (1/2/3...) 1

((QUESTION)) The postfix equivalent of the prefix *+ab-cd is ______.

((OPTION_A)) ab+cd-*

((OPTION_B)) ab+cd*-

((OPTION_C)) abcd+*-

((OPTION_D)) ab-cd+*

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) What does the following function check for? (all necessary headers to
be included and function is called from main)

#define MAX 10

typedef struct stack


{
int top;
int item[MAX];
}stack;

int function(stack *s)


{
if(s->top == -1)
return 1;
else return 0;
}
((OPTION_A)) full stack

((OPTION_B)) invalid index

((OPTION_C)) empty stack

((OPTION_D)) infinite stack

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) Answer: c
(OPTIONAL) Explanation: An empty stack is represented with the top-of-the-
stack(‘top’ in this case) to be equal to -1.

MCQs

Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After
four iterations of the algorithm’s main loop, the array elements are ordered as shown here:2 4 5 7
8136*
Insertion sort
Selection sort
either of a and b
none of the above

The running time of insertion sort is *


O(n^2)
O(n)
O(log n)
O(n log n)

Which of the following sorting procedure is the slowest ? *


Quick sort
Heap sort
Shell sort
Bubble sort

A sort which compares adjacent elements in a list and switches where necessary is *
insertion sort
heap sort
quick sort
bubble sort

The correct order of the efficiency of the following sorting algorithms according to their overall
running time comparision is *
Insertion>selection>bubble
Insertion>bubble>selection
Selection>bubble>insertion
bubble>selection>insertion
A sort which iteratively passes through a list to exchange the first element with any element less
than it and then repeats with a new first element is called *
insertion sort
selection sort
heap sort
quick sort

The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 19, 5, 13 in ascending order,
using bubble sort is *
10
9
13
14

The way a card game player arranges his cards as he picks them one by one can be compared
to *
Quick sort
Merge sort
Insertion sort
Bubble sort

Which among the following is the best when the list is already sorted *
Insertion sort
Bubble sort
Merge sort
Selection sort

As part of the maintenance work, you are entrusted with the work of rearranging the library books
in a shelf in proper order, at the end of each day. The ideal choice will be *
Bubble sort
Insertion sort
Selection sort
Merge sort

MCQs

1. Which of these best describes an array?


a) A data structure that shows a hierarchical behavior
b) Container of objects of similar types
c) Container of objects of mixed types
d) All of the mentioned
Answer: b
Explanation: Array contains elements only of the same type.

2. How do you initialize an array in C?


a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
Answer: c
Explanation: This is the syntax to initialize an array in C.

3. How do you instantiate an array in Java?


a) int arr[] = new int(3);
b) int arr[];
c) int arr[] = new int[3];
d) int arr() = new int(3);
Answer: c
Explanation: Note that option b is declaration whereas option c is to instantiate an array.

4. Which of the following is a correct way to declare a multidimensional array in Java?


a) int[][] arr;
b) int arr[][];
c) int []arr[];
d) All of the mentioned
Answer: d
Explanation: All the options are syntactically correct.

5. What is the output of the following piece of code?

public class array


{
public static void main(String args[])
{
int []arr = {1,2,3,4,5};
System.out.println(arr[2]);
System.out.println(arr[4]);
}
}

a) 3 and 5
b) 5 and 3
c) 2 and 4
d) 4 and 2
Answer: a
Explanation: Array indexing starts from 0.

6. What is the output of the following piece of code?

public class array


{
public static void main(String args[])
{
int []arr = {1,2,3,4,5};
System.out.println(arr[5]);
}
}

a) 4
b) 5
c) ArrayIndexOutOfBoundsException
d) InavlidInputException
Answer: c
Explanation: Trying to access an element beyond the limits of an array gives
ArrayIndexOutOfBoundsException.

7. When does the ArrayIndexOutOfBoundsException occur?


a) Compile-time
b) Run-time
c) Not an error
d) None of the mentioned
Answer: b
Explanation: ArrayIndexOutOfBoundsException is a run-time exception and the compilation is error-free.

8. Which of the following concepts make extensive use of arrays?


a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality
Answer: d
Explanation: Whenever a particular memory location is referred, it is likely that the locations nearby are also
referred, arrays are stored as contigous blocks in memory, so if you want to access array elements, spatial
locality makes it to access quickly.

9. What are the advantages of arrays?


a) Easier to store elements of same data type
b) Used to implement other data structures like stack and queue
c) Convenient way to represent matrices as a 2D array
d) All of the mentioned
Answer: d
Explanation: Arrays are simple to implement when it comes to matrices of fixed size and type, or to implement
other data structures.

10. What are the disadvantages of arrays?


a) We must know before hand how many elements will be there in the array
b) There are chances of wastage of memory space if elements inserted in an array are lesser than than the
allocated size
c) Insertion and deletion becomes tedious
d) All of the mentioned
Answer: d
Explanation: Arrays are of fixed size, hence during the compile time we should know its size and type, since
arrays are stored in contigous locations, insertion and deletion becomes time consuming.

11. Assuming int is of 4bytes, what is the size of int arr[15];?


a) 15
b) 19
c) 11
d) 60
Answer: d
Explanation: Since there are 15 int elements and each int is of 4bytes, we get 15*4 = 60bytes.

Queues:

1. A linear list of elements in which deletion can be done from one end (front) and insertion can take place
only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
Explanation: Self Explanatory.

3. A queue is a ?
a) FIFO (First In First Out) list
b) LIFO (Last In First Out) list
c) Ordered array
d) Linear tree
View Answer

Answer: a
Explanation: Self Explanatory.

4. In Breadth First Search of Graph, which of the following data structure is used?
a) Stack
b) Queue
c) Linked list
d) None of the mentioned
View Answer

Answer: b
Explanation: Self Explanatory.

5. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order
will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABCD
Answer: a
Explanation: Queue follows FIFO approach.

6. A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle
is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
Answer: c
Explanation: Self Explanatory.

7. A normal queue, if implemented using an array of size MAX_SIZE, gets full when
a) Rear = MAX_SIZE – 1
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front
Answer: a
Explanation: Condition for size of queue.

8. Queues serve major role in


a) Simulation of recursion
b) Simulation of arbitrary linked list
c) Simulation of limited resource allocation
d) All of the mentioned
Answer: c
Explanation: Rest all are implemented using other data structures.

9. Which of the following is not the type of queue?


a) Ordinary queue
b) Single ended queue
c) Circular queue
d) Priority queue
Answer: b
Explanation: Queue always has two ends.

10. In linked list implementation of queue, if only front pointer is maintained, which of the following operation
take worst case linear time?
a) Insertion
b) Deletion
c) To empty a queue
d) Both a and c
Answer: d
Explanation: Since front pointer is used for deletion, so worst time for the other two cases.

11. In linked list implementation of a queue, where does a new element be inserted?
a) At the head of link list
b) At the centre position in the link list
c) At the tail of the link list
d) None of the mentioned
Answer: c
Explanation: Since queue follows FIFO so new element inserted at last.

12. In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers will
change during an insertion into a NONEMPTY queue?
a) Only front pointer
b) Only rear pointer
c) Both front and rear pointer
d) None of the mentioned
Answer: b
Explanation: Since queue follows FIFO so new element inserted at last.

((MARKS)) (1/2/3...) 1

((QUESTION)) What will be the output of the program ?


#include<stdio.h>

int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}

((OPTION_A)) 2,1,15

((OPTION_B)) 1,2,5

((OPTION_C)) 3,2,15
((OPTION_D)) 2,3,20

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an
(OPTIONAL) integer array with a size of 5 and it is initialized to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
Step 2: int i, j, m; The variable i,j,m are declared as an integer type.
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is
incremented by 1(i++ means 2++ so i=3)
Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the
variables i, j, m
Hence the output of the program is 3, 2, 15

((MARKS)) (1/2/3...) 1
((QUESTION)) In C, if you pass an array as an argument to a function, what actually

passed?
((OPTION_A)) Value of elements in array
((OPTION_B)) First element of the array

((OPTION_C)) Base address of the array

((OPTION_D)) Address of the last element of array

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) The statement 'C' is correct. When we pass an array as a funtion argument,
(OPTIONAL) the base address of the array will be passed.

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following statements are correct about 6 used in the
program?
int num[6];
num[6]=21;
((OPTION_A)) In the first statement 6 specifies a particular element, whereas in
the second statement it specifies a type.
((OPTION_B)) In the first statement 6 specifies a array size, whereas in the second
statement it specifies a particular element of array.

((OPTION_C)) In the first statement 6 specifies a particular element, whereas in


the second statement it specifies a array size.
((OPTION_D)) In both the statement 6 specifies array size.
((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) The statement 'B' is correct, because int num[6]; specifies the size of
(OPTIONAL) array and num[6]=21; designates the particular element(7thelement) of
the array.

((MARKS)) (1/2/3...) 1

((QUESTION)) What does the following declaration mean?


int (*ptr)[10];

((OPTION_A)) ptr is array of pointers to 10 integers

((OPTION_B)) ptr is a pointer to an array of 10 integers

((OPTION_C)) ptr is an array of 10 integers

((OPTION_D)) ptr is an pointer to array

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following statements are correct about an array?


5. The array int num[26]; can store 26 elements.
6. The expression num[1] designates the very first element in the
array.
7. It is necessary to initialize the array at the time of declaration.
8. The declaration num[SIZE] is allowed if SIZE is a macro.

((OPTION_A)) 1

((OPTION_B)) 1,4

((OPTION_C)) 2,3

((OPTION_D)) 2,4

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) 1. The array int num[26]; can store 26 elements. This statement is true.
(OPTIONAL) 2. The expression num[1] designates the very first element in the array.
This statement is false, because it designates the second element of the
array.
3. It is necessary to initialize the array at the time of declaration. This
statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This
statement is true, because the MACRO just replaces the symbol SIZE
with given value.
Hence the statements '1' and '4' are correct statements.

((MARKS)) (1/2/3...) 1

((QUESTION)) If the two strings are identical, then strcmp() function returns

((OPTION_A)) -1

((OPTION_B)) 1

((OPTION_C)) 0

((OPTION_D)) Yes

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) strcmp(const char *s1, const char*s2);


(OPTIONAL) The strcmp return an int value that is
if s1 < s2 returns a value < 0
if s1 == s2 returns 0
if s1 > s2 returns a value > 0

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following function is used to find the first occurrence of a
given string in another string?

((OPTION_A)) strchr()

((OPTION_B)) strrchr()

((OPTION_C)) strstr()

((OPTION_D)) strnset()

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) char *strstr(const char *s1, const char *s2);


(OPTIONAL) Return Value:
On success, strstr returns a pointer to the element in s1 where s2 begins
(points to s2 in s1).
On error (if s2 does not occur in s1), strstr returns null.
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str1 = "IndiaBIX", *str2 = "ia", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s\n", ptr);
return 0;
}
Output: The substring is: iaBIX

((MARKS)) (1/2/3...) 1

((QUESTION)) The library function used to find the last occurrence of a character

string is

((OPTION_A)) strnstr()

((OPTION_B)) laststr()

((OPTION_C)) strrchr()

((OPTION_D)) strstr()

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION)) Declaration: char *strrchr(const char *s, int c);


(OPTIONAL) It scans a string s in the reverse direction, looking for a specific
character c.
Example:
#include <string.h>
#include <stdio.h>

int main(void)
{
char text[] = "I learn through IndiaBIX.com";
char *ptr, c = 'i';

ptr = strrchr(text, c);


if (ptr)
printf("The position of '%c' is: %d\n", c, ptr-text);
else
printf("The character was not found\n");
return 0;
}
Output:
The position of 'i' is: 19

((MARKS)) (1/2/3...) 1

((QUESTION)) How will you print \n on the screen?

((OPTION_A)) printf("\n");

((OPTION_B)) echo "\\n";

((OPTION_C)) printf('\n');

((OPTION_D)) printf("\\n");

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) The statement printf("\\n"); prints '\n' on the screen.


(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following data structures cannot store non-


homogeneous elements?

((OPTION_A)) Arrays

((OPTION_B)) Structure

((OPTION_C)) Linked List

((OPTION_D)) File

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1

((QUESTION)) In arrays ____ and _____ are costly but ____ is easy operation

((OPTION_A)) Searching, insertion, deletion

((OPTION_B)) Insertion, deletion, searching

((OPTION_C)) Deletion, searching, insertion

((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) void main()


{
int a[5]={1,2};
printf(“\n%d%d%d”,a[2],a[3],a[4]);
}
What will be the output?

((OPTION_A)) 122

((OPTION_B)) 211

((OPTION_C)) 000

((OPTION_D)) Garbage Value

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Find the output:


void main()
{
int i=0,a[3];
a[i]=i++;
printf(“%d”,a[i]);
}

((OPTION_A)) 0

((OPTION_B)) 1

((OPTION_C)) Garbage value

((OPTION_D)) Syntax error

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) While passing the array as actual argument, the function call must

array name_____

((OPTION_A)) alone

((OPTION_B)) With empty braces

((OPTION_C)) With its size

((OPTION_D)) None of these

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which code will run faster?


1. for(i=0;i<100;i++)
for(j=0;j<10;j++)
a[i][j]=0;
2. for(i=0;i<10;i++)
for(j=0;j<100;j++)
a[i][j]=0;

((OPTION_A)) Code 1

((OPTION_B)) Code 2

((OPTION_C)) Both run equally


((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider an integer array int arr[4][5]. If base address is 1020, find
s of element arr[3][4] with row major representation. Size of int is 2 bytes.

((OPTION_A)) 1020

((OPTION_B)) 1038

((OPTION_C)) 1039

((OPTION_D)) 1058

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider the statement int Val[2][4]={1,2,3,4,5,6,7,8}. The element

be at____

((OPTION_A)) Val[0][3]

((OPTION_B)) Val[0][4]

((OPTION_C)) Val[1][1]

((OPTION_D)) None of these

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) void main()


{
int a[2][3]={2,3};
printf(“\n%d%d%d%d”,a[0][0],a[0][1],a[1][0],a[1][1]);
}
What will be the output?
((OPTION_A)) 0023

((OPTION_B)) 2300

((OPTION_C)) 2030

((OPTION_D)) 2003

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The getchar() library function returns________

((OPTION_A)) Character when any key is pressed

((OPTION_B)) Character when enter key is pressed

((OPTION_C)) Display character on the screen when any key is pressed

((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Find the output:


void main()
{
printf(“%c”,100);
}

((OPTION_A)) Prints 100

((OPTION_B)) Prints ASCII equivalent of 100

((OPTION_C)) Prints garbage value

((OPTION_D)) Syntax error

((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the foolowing is more appropriate for reading a multi-


word string?

((OPTION_A)) printf

((OPTION_B)) scanf

((OPTION_C)) put

((OPTION_D)) gets

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Find the output:


int main()
{
char p[]=”%c\n”;
p[1]=’d’;
printf(p,65);
return 0;
}

((OPTION_A)) a

((OPTION_B)) A

((OPTION_C)) c

((OPTION_D)) 65

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Sparse matrix have______

((OPTION_A)) Many zero entries


((OPTION_B)) Many non zero entries

((OPTION_C)) High dimension

((OPTION_D)) Many negative entries

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The sequential representation of sparse matrix is given by

((OPTION_A)) stack

((OPTION_B)) Queues

((OPTION_C)) Arrays

((OPTION_D)) Linked List

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) If polynomial is 5x^3+3x^2+10x+2, the degree is

((OPTION_A)) 3

((OPTION_B)) 2

((OPTION_C)) 1

((OPTION_D)) 0

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Two main measures for the efficiency of an algorithm are

((OPTION_A)) Processor and memory

((OPTION_B)) Complexity and capacity


((OPTION_C)) Time and space

((OPTION_D)) Data and space

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following case does not exist in complexity theory
((OPTION_A)) Best case
((OPTION_B)) Worst case

((OPTION_C)) Average case

((OPTION_D)) Null case

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The Worst case occur in linear search algorithm when

((OPTION_A)) Item is somewhere in the middle of the array

((OPTION_B)) Item is not in the array at all

((OPTION_C)) Item is the last element in the array

((OPTION_D)) Item is the last element in the array or is not there at all

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) .
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The complexity of merge sort algorithm is

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n2)

((OPTION_D)) O(n log n)


((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The input to a merge sort is 6,5,4,3,2,1 and the same input is
applied to quick sort then which is the best algorithm in this case

((OPTION_A)) Merge sort

((OPTION_B)) Quick sort

((OPTION_C)) Both have same time complexity in this case as they have same
running time
((OPTION_D)) Cannot be decided

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) If there exists two functions f(n) and g(n). The constant c>0 and
there exists an integer constant n0>=1. If f(n)<=c*g(n) for every
integer n>= n0 then we say that____
((OPTION_A)) f(n)=O(g(n))

((OPTION_B)) f(n)=Θ (g(n))

((OPTION_C)) f(n)= (g(n))


f(n)=Θ (g(n)) f(n)=o(g(n))
((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) Basic definition of big oh notation


(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) In practice ______ is used to define tight upper bound on growth of


function f(n)

((OPTION_A)) Big oh

((OPTION_B)) Big omega


((OPTION_C)) Big theta

((OPTION_D)) None of these

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) The definition of big oh notation is f(n)<=c*g(n) which defines the


(OPTIONAL) upper bound on growth of the function f(n)

((MARKS)) (1/2/3...) 1

((QUESTION)) Examples of O(1) are ______

((OPTION_A)) Multiplying two numbers

((OPTION_B)) Assigning some value to a variable

((OPTION_C)) Displaying some integer on console

((OPTION_D)) All of the above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) All these operations are computed by single line expression evaluation
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Examples of O(n2) algorithms are

((OPTION_A)) Adding two matrices

((OPTION_B)) Finding transpose of a matrix

((OPTION_C)) Initializing all elements of the matrix by 0

((OPTION_D)) All of the above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) Within two for loops(nested), all these operations are performed.
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Choose the correct time complexity of following code__


while(n>0)
{
n=n/10
}
((OPTION_A)) O(1)

((OPTION_B)) O(n)

((OPTION_C)) O(log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The time complexity of binary search is_____

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) The list is divided at the mid and then the element is searched in either
(OPTIONAL) left half or right half.

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider recurrence relation as


T(0)=c1
T(n)=T(n-1)+c2
This can be expressed as

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) T(n)=T(n-1)+c2
(OPTIONAL) =T(n-2)+2c2
=T(n-3)+3c2
=T(n-k)+kc2
If k=n then T(n)=c1+nc2 Hence, T(n)=O(n)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider recurrence relation as


T(0)=c1 and T(1)=c2
T(n)=T(n/2)+c3
This can be expressed as

((OPTION_A)) O(n)

((OPTION_B)) O(log n)

((OPTION_C)) O(n log n)

((OPTION_D)) O(n2)

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Following is the method of solving recurrence relation

((OPTION_A)) Greedy method

((OPTION_B)) Backtracking

((OPTION_C)) Forward substitution method

((OPTION_D)) Divide and Conquer method

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The recurrence relation for factorial function is of the form _______

((OPTION_A)) T(n)=T(n-1)+c

((OPTION_B)) T(n)=T(n-1)+T(n-2)+c

((OPTION_C)) T(n/2)+c

((OPTION_D)) None of these


((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION)) The factorial function is as follows-


(OPTIONAL) fact(n)
{
if n=1
return 1
else
return n * fact(n-1)
}

((MARKS)) (1/2/3...) 1

((QUESTION)) The recurrence relation for fibonacci function is of the form

((OPTION_A)) T(n)=T(n-1)+c

((OPTION_B)) T(n)=T(n-1)+T(n-2)+c

((OPTION_C)) T(n/2)+c

((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION)) The fibonacci function is as follows-


(OPTIONAL) fibb(n)
{
if n = = 0
return 0
if n = = 1
return 1
else
return (fibb(n-1) + fibb(n-2))
}

((MARKS)) (1/2/3...) 1

((QUESTION)) The frequency count of following code is____


for(i=0;i<m;i++)
{
for(j=0;i<n;j++)
{
C[i][j]=a[i][j]+b[i][j];
}
}

((OPTION_A)) m + mn + mn

((OPTION_B)) m + n + mn
((OPTION_C)) m + n2 + mn

((OPTION_D)) (m+1) + m(n+1) + mn

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider T(n)=15n3 + n2 + 4. Select the correct statement

((OPTION_A)) T(n)=O(n4)

((OPTION_B)) T(n)= (n3)

((OPTION_C)) T(n)= (n2)

((OPTION_D)) All of the above

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Give the frequency count of 3rd Statement


for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
x=x+1;

((OPTION_A)) ½(n2+n)

((OPTION_B)) ½(n2+3n)

((OPTION_C)) n2

((OPTION_D)) (n+1)2

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) There are four algorithms for solving a problem. Their time
complexities
are O(n), O(n2), O(log n) and O(n log n). Which is the best
algorithm?

((OPTION_A)) O(n)

((OPTION_B)) O(n2)

((OPTION_C)) O(log n)

((OPTION_D)) O(n log n)

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The order of the recurrence relation ar-7ar-1+10ar-2=0 is ______.

((OPTION_A)) 3

((OPTION_B)) 2

((OPTION_C)) 1

((OPTION_D)) B

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Characteristic roots of the recurrence relation a r-2ar-1+ar-2=0 are


_______

((OPTION_A)) 1, -1

((OPTION_B)) -1, -1

((OPTION_C)) 1, 1

((OPTION_D)) None of these

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1

((QUESTION)) Charactristic polynomial of the recurrence relation b n=-3bn-1-bn-2 is


________.

((OPTION_A)) Z2-3Z-2=0

((OPTION_B)) Z2+3Z-2=0

((OPTION_C)) Z2+3Z+2=0

((OPTION_D)) None of these

((CORRECT_CHOICE)) C
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The general solution of the recurrence relation ar-2ar-1=0 is _____.

((OPTION_A)) ar=c1(-2)r

((OPTION_B)) ar=c2(2)r

((OPTION_C)) ar=c1(1)r

((OPTION_D)) None of these

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) Consider the recurrence relation, an=an-1+2an-2 with a9=3 and a10=5.
Find a7.

((OPTION_A)) 1

((OPTION_B)) 3

((OPTION_C)) 5

((OPTION_D)) None

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1

((QUESTION)) Charactristic polynomial of the recurrence relation a r+2-ar-2=0 is


______.

((OPTION_A)) Z-1=0

((OPTION_B)) Z2-1=0

((OPTION_C)) (Z-1)2=0

((OPTION_D)) None

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION)) Given homogeneous recurrence relation can be written as


(OPTIONAL) ar+2+0ar+1+0ar+0ar-1-ar-2=0
Order of this recurrence relation is 4.
Hence characteristic polynomial is Z4-1=0

((MARKS)) (1/2/3...) 1

((QUESTION)) Which of the following is not a homogeneous linear recurrence


relation

((OPTION_A)) ar+2-ar-2=0

((OPTION_B)) ar=ar-1+ar-2

((OPTION_C)) ar-2ar-1=-ar-2

((OPTION_D)) ar+3+6ar+2.ar+1-4ar=0

((CORRECT_CHOICE)) D
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) If 4 and -1 are the characteristic roots of the recurrence relation then
its homogeneous solution becomes _______

((OPTION_A)) ar=c1(-1)r+c2(4)r

((OPTION_B)) ar=c0(-1)r+c2

((OPTION_C)) ar=(c1+c2.r)(-1)r

((OPTION_D)) None
((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) A recurrence relation of degree 1 is called ______.

((OPTION_A)) Linear

((OPTION_B)) Homogeneous

((OPTION_C)) Quadratic

((OPTION_D)) None

((CORRECT_CHOICE)) A
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

((MARKS)) (1/2/3...) 1

((QUESTION)) The generating function for the sequence 1, a, a2, a3, ….. is ______

((OPTION_A)) 1/(1-z)

((OPTION_B)) 1/(1-az)

((OPTION_C)) 1/(1+az)

((OPTION_D)) None

((CORRECT_CHOICE)) B
(A/B/C/D)

((EXPLANATION))
(OPTIONAL)

You might also like