wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Data Structure Quiz 1

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

a)

An array of 50 numbers

b)

An array of 100 numbers

c)

An array of 500 numbers

d)

A dynamically allocated array of 550 numbers

2.

Consider an array consisting of –ve and +ve numbers. What would be the worst case time complexity of an algorithm to segregate the numbers having same sign altogether i.e all +ve on one side and then all -ve on the other?

a)

O(N)

b)

O(N Log N)

c)

O(N * N)

d)

O(N Log Log N)

3.

A three dimensional array in ‘C’ is declared as int A[x][y][z]. Consider that array elements are stored in row major order and indexing begins from 0. Here, the address of an item at the location A[p][q][r] can be computed as follows (where w is the word length of an integer):

a)

&A[0][0][0] + w(y * z * q + z * p + r)

b)

&A[0][0][0] + w(y * z * p + z*q + r)

c)

&A[0][0][0] + w(x * y * p + z * q+ r)

d)

&A[0][0][0] + w(x * y * q + z * p + r)

4.

Consider a two dimensional array A[20][10]. Assume 4 words per memory cell, the base address of array A is 100, elements are stored in row-major order and first element is A[0][0]. What is the address of A[11][5] ?

a)

575

b)

460

c)

570

d)

560

5.

Which of the following points is/are true about Linked List data structure when it is compared with array

a)

Arrays have better cache locality that can make them better in terms of performance.

b)

It is easy to insert and delete elements in Linked List

c)

Random access is not allowed in a typical implementation of Linked Lists

d)

All of the above

6.

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

a)

Insertion Sort

b)

Quick Sort

c)

Heap Sort

d)

Merge Sort

7.

In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is

a)

log 2 n

b)

n/2

c)

n

d)

log 2 n – 1

8.

Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among union, intersection, membership, cardinality will be the slowest?

a)

union only

b)

union, intersection

c)

membership, cardinality

d)

intersection, membership

9.

What are the time complexities of finding 8th element from beginning and 8th element from end in a singly linked list? Let n be the number of nodes in linked list, you may assume that n > 8.

a)

O(1) and O(n)

b)

O(1) and O(1)

c)

O(n) and O(1)

d)

O(n) and O(n)