Sei sulla pagina 1di 21

Quiz-1

Data Structures and algorithms


1. Which of the following algorithmic
paradigm is used in the merge sort?
• A. Dynamic Programming
• B. Divide and Conquer
• C. Back Tracking
• D. Greedy Method
2.What is the worst case performance of
Selection sort algorithm?
• A. O(n*n)
• B. O(log n)
• C. O(n)
• D. O(n log n)
3.Let P be a quick sort program to sort numbers in
ascending order using the first element as the
pivot. Let t1 and t2 be the number of comparisons
made by P for the input [1 2 3 4 5] and [4 1 5 3 2]
respectively. Which one of the following holds?
• A. t1=t2
• B. t1<t2
• C. t1=5
• D. t1>t2
4. An ADT is defined to be a mathematical model
of a user-defined type along with the collection of
all ____________ operations on that model.
• A. Primitive
• B. Assignment
• C. Cardinality
• D. Structured
5. The following data structure is non-linear
type:
• A. Lists
• B. Stack
• C. Queue
• D. None of these
6._____________ search can start at the
beginning of the list and check every elements in
the list.
• A. Binary Search
• B. Linear Search
• C. Binary Search Tree
• D. Interval search
7.Which of the following data structure can’t
store the nonhomogeneous data elements?
• A. Stacks
• B. Linked Lists
• C. Arrays
• D. None of these
8.The number of comparisons done by
sequential search is___________.
• A. (N*N)/2
• B.(N/2)+1
• C. (N+1)/2
• D. (N-1)/2
9.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 address of the other elements can be calculated
• B. The Architecture of the computer memory does not allow array to
store other than serially
• C. By this way computer can keep track only the memory of the first
element and the address of the other elements can be calculated
• D. None of these
10. What does the following function do if S is an
array used to implement a stack
float peep (float S[], int *t, int i)
{
float val;
if( (*t-i+1) > 0)
{
val = S[*t-i+1];
return val;
}
}

• A. Returns the Value at the top of stack


• B. Returns the ith value from top of the stack
• C. Returns the Value at the ith position of the array
• D. It Gives a Compilation error
11. you wish to store a small amount of data and
make it available for rapid access. You do not have
a need for the data to be sorted, uniqueness is not
an issue and the data will remain fairly static
Which data structure might be most suitable for
this requirement?
• A. Tree Set
• B. an Linked List
• C.an Array
• D. Hash Map
12. Consider the function given below. Assume the array list A
contains (n>0) elements, sorted in ascending order.
int Process array (int * list A, int x, int n)
{
int i, j, k;
Which one of the following statements about the function Process Array is
i =0;j=n-1; CORRECT?
do {
k = (i+j)/2; • A. It will run into an infinite loop when x is not in list A
if (x<=list A[k])
j=k-1; • B. It is an implementation of binary search.
if (list A[k] <=x) • C. It will always find the maximum element in list A.
i =k+1;
} while (i <=j); • D. It will return -1 even when x is present in list A.
if (list A[k] == x)
return (k);
else
return -1;
}
13. What sorting algorithms have their best
and worst case times equal ?
• A. heap and selection sort
• B. insertion sort & merge sort
• C. merge sort and heap sort
• D. None of these
14.The number of interchanges required to sort 5,
1, 6, 2 4 in ascending order using Bubble Sort is
•A6
• B7
• C5
•D8
15.The disadvantage of Binary Search is ?
A. It has the overhead of sorting
B. It may not work for floating point numbers
C. Its performance depends on the position of the search element in
the array
D. It may not work for strings
16.Which of the following is not a limitation of
binary search algorithm ?
A. Binary search algorithm is not efficient when the data elements are
more than 1000.
B. Must use a sorted array
C. Requirement of sorted array is expensive when a lot of insertion and
deletions are needed
D. There must be a mechanism lo access middle element directly
17. A sort which uses the binary tree concept such
that any number is larger than all the numbers in
the subtree below it is called
A. Selection sort
B. Insertion sort
C. Heap sort
D. Quick sort
18.The number of swapping's needed to short the
numbers 8, 22, 7, 9, 31, 19, 5, 13 in ascending
order using bubble sort is
A. 11
B. 14
C. 13
D. 12
19.How will you find the maximum element in a
binary search tree?
A.public void max(Tree root) C.public void max(Tree root)
{ while(root.left() != null) { while(root.right() != null)
{ root = root.left(); } { root = root.right(); }
System.out.println(root.data()); } System.out.println(root.data()); }

B.public void max(Tree root) D.public void max(Tree root)


{ while(root != null) { while(root != null)
{ root = root.left(); } { root = root.right(); }
System.out.println(root.data()); } System.out.println(root.data()); }
20. For an array containing 5 elements as : 42 29
75 11 65 58 60 18 what will be the result of
sorting in ascending order using bubble sort after
2 passes have completed. ?
A. 11 29 42 18 58 60 65 75
B. 29 42 11 65 58 60 18 75
C. 11 29 42 58 18 60 65 75
D. 29 11 42 58 60 18 65 75

Potrebbero piacerti anche