DATA STRUCTURE AND ALGO SET 7 MCQ


Q.51 What is the output of following statement?

for(i=1; i<4; i++)

printf(“%d”,(i%2) ? i : 2*i);

(A) 1 4 3 (B) 1 2 3

(C) 2 4 6 (D) 2 2 6

Ans: A

for i=1, (i%2) is true so the statement will print 1; for for i=2, (i%2) is false so the

statement will print 2*i=2*2=4; for for i=3, (i%2) is again true so the statement will

print 3; for i=4, the statement is out from the loop.


Q.52 Which of the following statement is true about a function?

(A) An invoking function must pass arguments to the invoked function.

(B) Every function returns a value to the invoker.

(C) A function may contain more than one return statement.

(D) Every function must be defined in its own separate file.

Ans: A

An invoking function must pass arguments to the invoked function.


Q.53 What is the output of the following program?

main( )

{

int i=4, z=12;

if(i=5 || z>50)

printf(“hello”);

else

printf(“hye”);

}

(A) hello (B) hye

(C) syntax error (D) hellohye

Ans: A

i=5 will assign value 5 to i so the if statement (i=5||z>50) is true so “printf” statement will print hello.


Q.54 For implementing recursive function the data structure used is:

(A) Queue (B) Stack

(C) Linked List (D) Tree

Ans: B

For implementing recursive function, stack is used as a data structure.


Q.55 The size of array int a[5]={1,2} is

(A) 4 (B) 12

(C) 10 (D) 6

Ans: C

The size of int array is 2*5=10 bytes as int takes 2 bytes of storage.


Q.56 Which of the following is not an escape sequence?

(A) \n (B) \r

(C) \’ (D) \p

Ans: D

\p is not an escape sequence.


Q.57 The output of the following statements is

char ch[6]={‘e’, ‘n’, ‘d’, ‘\0’, ‘p’};

printf(“%s”, ch);

(A) endp (B) end0p

(C) end (D) error

Ans: C

printf statement will print end because string is terminated at “\0” and in array after d,we have null character.


Q.58 How many times the following code prints the string “hello”.

for(i=1; i<=1000; i++);

printf(“hello”);

(A) 1 (B) 1000

(C) Zero (D) Syntax error

Ans: A

The “for” loop is terminated by a semicolon so the next statement is execute that is

printing hello.


Q.59 Find the invalid identifiers from the following:-

(i) nA (ii) 2nd (iii) ROLL NO (iv) case

(A) (i), (ii) and (iv) (B) (i) and (iii)

(C) (ii), (iii) and (iv) (D) (ii), (i) and (iii)

Ans: C

Identifier cannot start with a digit; it cannot have a space and case is a keyword.


Q.60 The void type is used for

(A) Returning the value (B) creating generic pointers

(C) Creating functions (D) Avoid error

Ans: B

The void type is used to create generic pointers.


Q.61 The valid octal constants from the following

(i) 0245 (ii) 0387 (iii) 04.32 (iv) –0467

(A) (i) and (ii) (B) (iii) and (iv)

(C) (ii) and (iii) (D) (i) and (iv)

Ans: D

(i) and (iv) are valid octal constants.


Q.62 The variable that are declared outside all the functions are called ______.

(A) Local variable (B) Global variable

(C) Auto variable (D) None of the above

Ans: B

The variables that are declared outside all functions are called global variable.


Q.63 Consider the following statements:-

int x = 6, y=8, z, w;

y = x++;

z = ++x;

The value of x,y,z by calculating the above expressions are:-

(A) y=8, z=8, x=6 (B) y=6, x=8, z=8

(C) y=9, z=7, x=8 (D) y=7, x=8, z=7

Ans: B

y is assigned value of x that is 6, then x in incremented that is value of x=7, z is

assigned value of x after incrementing that is z =8 so value of x =8.


Q.64 To declare an array S that holds a 5-character string, you would write

(A) char S[5] (B) String S[5]

(C) char S[6] (D) String S[6]

Ans: A

A string is nothing but a char array.

Q.65 The function used to read a character from a file that has been opened in read mode is

(A) putc (B) getc

(C) getchar (D) putchar

Ans: B

getc is used to read a character from a file that has been opened in read mode.


Q.66 The function that allocates requested size of bytes and returns a pointer to the first

byte of the allocated space is –

(A) realloc (B) malloc

(C) calloc (D) none of the above

Ans: B

malloc allocates requested size of bytes and returns a pointer to the first byte of the

allocated space.


Q.67 The constructed datatype of C is known as

(A) Pointers (B) String

(C) Structure (D) Array

Ans: C

Structure is a constructed datatype of C


Q.68 The postfix form of the following infix notation is : (A + B)* (C*D − E)* F

(A) AB + CD*E − *F* (B) AB+ CDE + − * F*

(C) AB+ CD − EF + − ** (D) ABCDEF* − + * +

Ans: (A)


Q.69 The number of nodes in a complete binary tree of depth d (with root at depth 0) is

(A) 2 1 d−1 +

(B) 2 1 d+1 −

(C) 2 1 d−1 −

(D) 2 1 d+1 +

Ans: (B)


Q.70 The average case of quick sort has order

(A) ( 2 ) O n (B) O(n)

(C) O(n log n) (D) O(log n)

Ans: (C)


Q.71 Inorder to get the information stored in a BST in the descending order, one should

traverse it in which of the following order?

(A) left, root, right (B) root, left, right

(C) right, root, left (D) right, left, root

Ans: (C)


Q.72 Every internal node in a B-tree of minimum degree 2 can have

(A) 2, 3 or 4 children (B) 1, 2 or 3 children

(C) 2, 4 or 6 children (D) 0, 2 or 4 children

Ans: (B)


Q.73 Which sorting algorithm is the best if the list is already in order?

(A) Quick sort (B) Merge sort

(C) Insertion sort (D) Heap sort

Ans: (C)


Q.74 In _________ the difference between the height of the left sub tree and height of right

sub tree, for each node, is not more than one

(A) BST (B) Complete Binary Tree

(C) AVL-tree (D) B-tree

Ans: (C)


Q.75 The number of comparisons required to sort 5 numbers in ascending order using bubble

sort is

(A) 7 (B) 6

(C) 10 (D) 5

Ans: (C)


Q.76 The complexity of adding two matrices of order m*n is

(A) m + n (B) mn

(C) max(m, n) (D) min(m, n)

Ans: (B)


Q.77 The second largest number from a set of n distinct numbers can be found in

(A) O(n) (B) O(2n)

(C) ( 2 ) O n (D) O(log n)

Ans: (A)


Q.78 If the inorder and preorder traversal of a binary tree are D,B,F,E,G,H,A,C and

A,B,D,E,F,G,H,C respectively then the postorder traversal of that tree is

(A) D,F,G,A,B,C,H,E (B) F,H,D,G,E,B,C,A

(C) C,G,H ,F,E,D,B,A (D) D,F,H,G,E,B,C,A

Ans: (D)


Q.79 In a binary tree, the number of terminal or leaf nodes is 10. The number of nodes with

two children is

(A) 9 (B) 11

(C) 15 (D) 20

Ans: (A)


Q.80 Which amongst the following cannot be a balance factor of any node of an AVL tree?

(A) 1 (B) 0

(C) 2 (D) –1

Ans: (C)


Q.81 How many distinct binary search trees can be formed which contains the integers 1, 2,3?

(A) 6 (B) 5

(C) 4 (D) 3

Ans: (B)


Q.82 The sort which inserts each elements A(K) into proper position in the previously sorted

sub array A(1), …, A(K–1)

(A) Insertion sort (B) Radix sort

(C) Merge sort (D) Bubble sort

Ans: (A)


Q.83 Direct or random access of elements is not possible in

(A) Linked list (B) Array

(C) String (D) None of these

Ans: (A)


Q.84 Level of any node of a tree is

(A) Height of its left subtree minus height of its right subtree

(B) Height of its right subtree minus height of its left subtree

(C) Its distance from the root

(D) None of these

Ans: (C)


Q.85 A desirable choice for the partitioning element in quick sort is

(A) First element of the list

(B) Last element of the list

(C) Randomly chosen element of the list

(D) Median of the list

Ans: (A)


Q.86 lg (n!) =____________

(A) O (n) (B) O (lg n)

(C) O (n2) (D) O (n lg n)

Ans: (D)

n!=n(n-1)(n-2)—–3X2X1

(n/2)n/2

log n! n/2logn/2

n/2(logn-log2)

n/2 (log n-1)

n log n

= O(n log n)


Q.87 The result of evaluating the following postfix expression is

5, 7, 9, *, +, 4, 9, 3, /, +, –

(A) 50 (B) 65

(C) 61 (D) 69

Ans: (C)


Q.88 A graph with n vertices will definitely have a parallel edge or self loop if the total

number of edges are

(A) more than n (B) more than n+1

(C) more than (n+1)/2 (D) more than n(n-1)/2

Ans: (D)


Q.89 Out of the following, the slowest sorting procedure is

(A) Quick Sort (B) Heap Sort

(C) Shell Sort (D) Bubble Sort

Ans: (D)


Q.90 In ________, it is possible to traverse a tree without using stacks either implicitly or

explicitly.

(A) Threaded binary trees. (B) AVL Tree

(C) B+ tree (D) Heap

Ans: (C)


Q.91 The order of a B-Tree with 2, 3, 4 or 5 children in every internal node is

(A) 2 (B) 3

(C) 4 (D) 5

Ans: (C)


Q.92 The number of nodes that have no successors in a complete binary tree of depth 4 is

(A) 0 (B) 8

(C) 16 (D) 4

Ans: (B)


Q.93 One can make an exact replica of a Binary Search Tree by traversing it in

(A) Inorder (B) Preorder

(C) Postorder (D) Any order

Ans: (B)


Q.94 A complete Binary Tree with 15 nodes contains________edges

(A) 15 (B) 30

(C) 14 (D) 16

Ans: (C)


Q.95 The minimum number of comparisons required to find the largest number from

different numbers are

(A) 4 (B) 3

(C) 5 (D) 6

Ans: (B)


Q.96 An infix expression can be converted to a postfix expression using a

(A) Stack (B) Queue

(C) Dequeue (D) None of these

Ans: (A)


Q.97 A data structure in which an element is added and removed only from one end, is known

as

(A) Queue (B) Stack

(C) In-built structure (D) None of the above

Ans: (B)


Q.98 A complete binary tree with the property that the value of each node is at least as

large as the values of its children is known as

(A) Binary Search Tree. (B) AVL Tree.

(C) Heap. (D) Threaded Binary Tree.

Ans: (C)


Q.99 A sorting algorithm is stable if

(A) its time complexity is constant irrespective of the nature of input.

(B) preserves the original order of records with equal keys.

(C) its space complexity is constant irrespective of the nature of input.

(D) it sorts any volume of data in a constant time.

Ans: (B)


 

Q.100 A tree in which, for every node, the difference between the height of its left subtree

and right subtree is not more than one is

(A) AVL Tree. (B) Complete Binary Tree.

(C) B – Tree. (D)+B Tree.

Ans: (A)

Leave a comment