Professional Documents
Culture Documents
Answer: a
Explanation: Array indexing starts from 0
. 2What 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.
3 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.
4What 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.
5 What is a bit array?
a) Data structure for representing arrays of
records
b) Data structure that compactly stores bits
c) An array in which most of the elements have
the same value
d) None of the mentioned
Answer: b
Explanation: It compactly stores bits and exploits
bit-level parallelism.
6What are some of the applications of bit arrays?
a) Used by the Linux kernel
b) For the allocation of memory pages
c) Bloom filter
d) All of the mentioned
Answer: d
Explanation: Used in priority queues data
structure in the Linux kernel, for allocation of
memory pages, a bitmap is used.
7 How will you implement dynamic arrays in
Java?
a) Set
b) Map
c) HashMap
d) List
Answer: d
Explanation: ArrayList is used to implement
dynamic arrays in Java.
8To search for an element in a sorted array,
which searching technique can be used?
a) Linear Search
b) Jump Search
c) Binary Search
d) Fibonacci Search
Answer: c
Explanation: Since the array is sorted, binary
search is preferred as its time complexity is
O(logn).
9What is a sparse array?
a) Data structure for representing arrays of
records
b) Data structure that compactly stores bits
c) An array in which most of the elements have
the same value
d) None of the mentioned
Answer: c
Explanation: They are set to a default value,
usually 0 or null.
10 What is the difference between a
normal(naive) array and a sparse array?
a) Sparse array can hold more elements than a
normal array
b) Sparse array is memory efficient
c) Sparse array is dynamic
d) A naive array is more efficient
Answer: b
Explanation: A naive implementation allocates
space for the entire size of the array, whereas a
sparse array(linked list implementation) allocates
space only for the non-default values.