Type Here to Get Search Results !

# Data Structures MCQs ( Multiple Choice Questions ) - Array

0

Data Structures MCQs ( Multiple Choice Questions ) - Array

Set - I

Q1. What is an array?

a) A data structure that shows a hierarchical behavior

b) Arrays are immutable once initialised

c) A Container of objects of similar types

d) Array is not a data structure

Answer is c) A Container of objects of similar types
Explanation : Array contains elements only of the same type.

Q2. The smallest element of an array's index is called its

a) A lower bound.

b) upper bound.

c) range.

d) extraction

Answer is a) A lower bound.
Explanation : The smallest element of an array's index is called its lower bound.
Lower bound() returns an iterator to the elements in the given range which does no compare less than the given value.
Lower bound() finds the first element not less than the given value. This function accepts element in sorted order. It uses binary function for comparison.

Q3. How do you instantiate an array in Java?

a) int arr[] = new int(3);

b) int arr[];

c) int arr[] = new int;

d) int arr() = new int(3);

Answer is c) int arr[] = new int
Explanation : Note that int arr[]; is declaration whereas int arr[] = new int; is to instantiate an array.

Q4.The extra key inserted at the end of the array is called a

a) End key.

b) Stop key.

c) Sentinel.

d) Transposition

Explanation : Sentinel is a special value in the context of an algorithm in an array which uses its presence as a condition of termination, typically in a loop or recursive algorithm.

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

a) int[] arr;

b) int arr[[]];

c) int[][]arr;

d) int[[]] arr;

Explanation : The syntax to declare multidimensional array in java is either int[][] arr; or int arr[][];

Q6. The largest element of an array index is called its

a) Upper bound

b) range

c) Lower bound

d) All of these

Explanation : Upper bound() is the iterator pointing to the first element in the range [first, last] that is greater than value, or last if no such element is found. The elements in the range shall already be sorted or at least partitioned with respect to val.

Q7. Each array declaration need not give, implicitly or explicitly, the information about

a) the name of array

b) the data type of array

c) the first data from the set to be stored

d) the index set of the array

Answer is c) the first data from the set to be stored
Explanation : In an array declaration the first data from the set is not required

Q8. The elements of an array are stored successively in memory cells because

a) by this way computer can keep track only the address of the first element and the addresses of other elements can be calculated

b) the architecture of computer memory does not allow arrays to store other than serially

c) both of above

d) none of above

Answer is a) by this way computer can keep track only the address of the first element and the addresses of other elements can be calculated
Explanation : The array elements are stored successively because by this way computer can keep track only the address of the first element and the addresses of other elements can be calculated

Q9. Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements are distinct.

a) Find the ith largest element

b) Delete an element

c) Find the ith smallest element

d) All of the above

Answer is b) Delete an element
Explanation : The worst case time complexity for deleting an element from array can become O(n).

Q10. What is the output of the following Java code?

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

a) 3 and 5

b) 5 and 3

c) 2 and 4

d) 4 and 2

Answer is a) 3 and 5
Explanation : Output is such because array indexing starts from 0.

Q11. You want to find the nth element of a set of numbers. If you store the numbers in

a) Finding the nth element is slower if it was stored in an array

b) Finding the nth element is faster if it was stored in an array

c) Finding the nth element takes the same amount of time across all data structures

d) Finding the nth element is slower if it was stored in a hash table

Answer is b) Finding the nth element is faster if it was stored in an array
Explanation : For explanation Join the discussion below

Q12. The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is. GATE CS 2008

a) Θ(n)

b) Θ(logn)

c) Θ(log*n)

d) Θ(1)

Explanation : If you answered Theta(1), then think of examples {1, 2, 2, 2, 4, 4}, {1, 1, 2, 2, 2, 2, 3, 3} The Best way to find out whether an integer appears more than n/2 times in a sorted array(Ascending Order) of n integers, would be binary search approach.
The First occurence of an element can be found out in O(log(n)) time using divide and conquer technique,lets say it is i.
The Last occurrence of an element can be found out in O(log(n)) time using divide and conquer technique,lets say it is j.
Now number of occuerence of that element(count) is (j-i+1). Overall time complexity = log n +log n +1 = O(logn)

Q13. Arrays are best data structures

a) for relatively permanent collections of data

b) for the size of the structure and the data in the structure are constantly changing

c) for both of above situation

d) for none of above situation

Answer is a) for relatively permanent collections of data
Explanation : Array is best datastructure for storing data element of same datatypes

Q14. When does the ArrayIndexOutOfBoundsException occur?

a) Compile-time

b) Run-time

c) Not an error

d) Not an exception at all

Explanation : ArrayIndexOutOfBoundsException is a run-time exception and the compilation is error-free.

Q15. Two dimensional arrays are also called

a) tables arrays

b) matrix arrays

c) both of the above

d) none of the above

Answer is c) both of the above
Explanation : Two dimensional arrays are also called table arrays and matrix arrays

If you have any doubts join the discussion below ,our Moderator will reply to your Queries