wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

ADS_SDA

Total questions: 85

Worksheet time: 43mins

Name
Class
Date
1.

Array elements ____ before a binary search can be perfomed

a)

summed

b)

sorted

c)

set to zero

d)

positive of the mentioned

e)

none of the mentioned

2.

When two identifiers are hashed into the same bucket, it is known as

a)

Collision

b)

Synonyms

c)

Overflow

3.

When you run recursive methods, the computer creates for you:

a)

Stack

b)

Queue

c)

Heap

d)

LinkedList

4.

Hashing gives each item

a)

A sequential address

b)

No address

c)

A logarithmic address

d)

A unique address

5.

What is the time complexity of finding the maximum element in a max-heap?

a)

O(1)

b)

O(Log n)

c)

O(n)

d)

O(n^2)

6.

Specity ArrayList advantages over LinkedList

a)

arrayList is better for string and accessing the data

b)

arrayList is better for manipulating the data

c)

cadding and removing an element

d)

none of the mentioned

7.

What does the Hash table look like?

a)

An array of multi-linked lists

b)

Table of arrays

c)

An array of singly-linked lists

d)

Graph

8.

What is the maximum number of elements that can be stored in a stack of size N?

a)

N

b)

N-1

c)

2N-1

d)

42500

9.

A binary tree is a data structure where each node has at most two children.

a)

True

b)

False

10.

Suppose we have an O(n) time algorithm that finds the median of an unsorted array. Now consider a QuickSort implementation where we first find the median using the above algorithm, then use the median as a pivot. What will be the worst-case time complexity of this modified QuickSort?

a)

O (logn)

b)

O (n^2)

c)

O (nlogn)

d)

O (n^2 logn)

11.

_ is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity..

a)

Big O notation

b)

Counting operations

c)

Linear complexity

d)

None of the listed

12.

Select time complexity of heap sort.

a)

O (nlogn)

b)

O (logn)

c)

O(n)

d)

O(n-1)

13.

Given an unsorted array. The array has this property that every element in the array is at most k distance from its position in a sorted array where k is a positive integer smaller than the size of an array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time complexity?

a)

None of the mentioned

b)

Heap Sort with time complexity O(nlogk)

c)

Quick Sort with time complexity O(kLogk)

d)

Merge Sort with time complexity O(kLogk)

14.

What is Breadth First Search (BFS)? An algorithm used to traverse a tree or graph data structure

a)

An algorithm used to traverse a tree or graph data structure

b)

An algorithm used to sort an array in ascending order

c)

An algorithm used to search for a specific element in a linked list

d)

An algorithm used to find the maximum sum of a subarray in an array

15.

The hashCode is used to get an index of chain by hash0) method

a)

True

b)

False

16.

Which of the following are types of LinkedList

a)

singly-linked, doubly linked, multi-linked

b)

singly-linked, circular-linked, multi-linked

c)

singly-linked, doubly-linked, circular-linked

d)

circular-linked, doubly-linked, multi-linked

17.

Which data structure can be used to implement a queue?

a)

Array

b)

LinkedList

c)

Stack

d)

Tree

18.

Recursion can be implemented with just using loops

a)

True

b)

False

19.

Which of the following set 1 related to set 2?

Set 1

a. Linear search

b. Binary search

c. Hash table

Set 2

i. Collision

ii. Both sorted and unsorted array

iii. Only sorted array

a)

. a-iii, b-ii, c-i. a-iii, b-ii, c-i

b)

a- ii, b - iii, c-i

c)

a-i, b-iii, c-ii. a-i, b-ii, c-iii

d)

. a-i, b-ii, c-iii

20.

Choose worst case of quick sort when the selected pivot point is always the smallest or largest

a)

O(logn)

b)

O(n)

c)

O(n-1)

d)

O(n^2)

21.

Recursion is implemented by the queue, and each time you invoke a method, the method is placed on top of the queue.

a)

True

b)

False

22.

In recursion the value of control variable moves towards the value in condition

a)

True

b)

False

23.

Specify ArrayList advantages over LinkedList

a)

less memory usage

b)

arrayList is better for manipulating the data

c)

adding and removing an element

d)

none of the mentioned

24.

When 2 elements map to the same slot in the hash table, it is called

a)

collision

b)

searching

c)

sorting

d)

none of the mentioned

25.

What is a cycle in a graph?

a)

A path that starts and ends at the same vertex

b)

A path that connects all vertices in the graph

c)

A path that contains at least one repeated vertex

d)

A path that contains at least one repeated edge

26.

Which of the following is true about add() method ofArrayList?

a)

method inserts the specified element at the specified position in this list

b)

method has a return value

c)

method inserts value to the next node of the specified element

d)

all of the above

27.

The worst case running times of Bubble sort, Merge sort and Quick sort, respectively, are:

a)

O(n log n), O(n log n) and O(n²)

b)

O(n), O(n²) and O(n Log n)

c)

O(n²), O(n log n) and O(n log n)

d)

O(n), O(n log n) and O(n)

28.

Following code finds a specific number in the sorted array (or return -1 if the value isn't in the array).

static int searchSorted(int arr[], int 1, int r. int x)

if (r == 1) {

int mid 1 (r-1)/2;

if (arr[mid] == x) return mid;

if (arr[mid]> x)

return searchSorted(arr, 1, mid - 1, x);

return searchSorted(arr, mid 1, r, x);

return -1;

What is the time complexity of this algorithm?

a)

O (logn)

b)

O(n^2)

c)

O (nlogn)

d)

O (n)

29.

What will be print when the following code executes?

ArrayList<Integer> arrayList = new ArrayList<Integer>();

arrayList.add(7);

arcaylist.add(8);

arrayList.add(9);

System.out.println(arraylist.remove(0));

a)

7

b)

8

c)

9

d)

0

30.

What is the minimum number of elements in a heap with height 3?

a)

7

b)

8

c)

15

d)

16

31.

What is a Stack data structure?

a)

A data structure that follows LIFO (Last-In-First-Out) order

b)

A data structure that follows FIFO (First-In-First-Out) order

c)

A data structure that allows random access to elements

d)

A data structure that stores elements in a sorted manner

32.

Which operation adds an element to the top of the stack?

a)

push()

b)

pop()

c)

peek()

d)

size()

33.

What is double-linked list?

a)

each node points to the next node

b)

each node points to the next and previous nodes

c)

. last node points to the first

d)

each node points to all previous nodes

34.

What happens when DFS encounters a node that has already been visited?

a)

. The algorithm continues without visiting the node again

b)

The algorithm restarts from the beginning of the graph

c)

The algorithm backtracks to the previous node and continues from there

d)

The algorithm marks the node as visited again

35.

Consider a hash table with 7 slots. The hash function is h(x) = x % 7. The collision are resolved by chaining. The following 7 keys are inserted in the order: 12, 66, 45, 86, 49, 8, 20. Find the maximum and minimum chain lengths (the max, min linked list sizes) in the hash table.

a)

3 and 0, respectively

b)

2 and 0, respectively

c)

1 and 0, respectively

d)

2 and 1, respectively

36.

Which data structure can be used to implement a heap?

a)

Array

b)

LinkedList

c)

Queue

d)

Tree

37.

What is the focus of determining the order of growth?

a)

Leading coefficients

b)

Lower-order terms

c)

Dominant terms

d)

All terms

38.

How Horner's method is used to hash string of length L?

a)

Ladds/divides

b)

. L multiples/subtract

c)

L multiplies/adds

d)

L subtract/divide

39.

For the Binary Search Tree is the following statement True or False: All nodes of left subtree are more than the root node.

a)

True

b)

False

40.

What is a min-heap?

a)

A heap in which the smallest element is at the root.

b)

A heap in which the largest element is at the root

c)

A heap that is empty.

d)

A heap that contains only one element.

41.

Data structure that has the same size throughout the program on

a)

Array

b)

ArrayList

c)

LinkedList

d)

HashTable

42.

Which of the following operations can be performed on a binary search tree in O (logN) time?

a)

Insertion

b)

Deletion

c)

Search

d)

All of the above

43.

This method will return true only in case if;

public static boolean check (String s){

return s.length() >= 2 && (s.charAt(0) == s.charAt(1) || check(s.substring(1))); }

a)

. The string s contains two or more of the same character that are next to each other

b)

The string s contains two or more of the same characters

c)

The string s starts with two or more of the same characters.

d)

The string s ends with two or more of the same characters

44.

In a graph with multiple connected components, how many times will BFS be called?

a)

Once

b)

Twice

c)

The number of connected components

d)

The number of edges in the graph

45.

What is the time complexity for adding an element at the beginning of LinkedList?

a)

O(o)

b)

O(1)

c)

O(n^2)

d)

O(logn)

46.

Recursive code tends to be bigger in size compared to code based on iteration

a)

True

b)

False

47.

What is the time complexity of searching for a value in a binary search tree of N nodes in the worst case?

a)

O(n^2)

b)

O(logn)

c)

O(n)

d)

O(nlogn)

48.

What is a binary tree?

a)

Aibar

b)

A tree with at Most Two children per node

c)

Elfbar

d)

KTL

49.

The load Factor is a current capacity of the hash table

a)

True

b)

False

50.

Big-O notation of the following expression is equal to linear complexity. O(n)+O(n*n) O(n)

a)

true

b)

false

51.

What is the maximum number of nodes in a binary tree of height h?

a)

2^h-1

b)

h^2

c)

2*h

d)

hl

52.

Array elements must be ____ before a binary search can be performed

a)

summed

b)

sorted

c)

set to zero

d)

positive numbers

53.

Which sorting algorithm is best suited for sorting linked lists?

a)

Merge Sort

b)

Quick Sort

c)

Bubble Sort

d)

None of the mentioned

54.

Let us consider a list of numbers (12, 40, 96, 33, 57, 81, 8) and has table size is 10.

What is the order elements (from index 0 to size - 1) in the hash table by using the hash function h(x) = x % size of hash table?40, 81, 12, 33, null, null, 96, 57, 8, null

a)

40, 81, 12, 33, null, null, 96, 57, 8, null

b)

8, 12, 33, 40, 57, 81, 96, null, null, null

c)

null, null, 57, 96, 12, null, 40, 33, 8, 81

d)

null, null, null, 8, 12, 33, 40, 57, 81, 96

55.

Consider a 13 element hash table for which h(key) = key % 13 is used with integer keys. Assuming linear probing is used for collision resolution, at which location would the key 102 be inserted, if the keys 99, 15, 63 and 102 are inserted in that order?

a)

12

b)

11

c)

0

d)

None of the mentioned

56.

Can a constant time algorithm have loops or recursive calls?

a)

No, it is not possible

b)

Yes, but only if the number of iterations or calls is independent of the input size

c)

Yes, but only if the number of iterations or calls is proportional to the input size

d)

Yes, but only if the number of iterations or calls is greater than the input size

57.

Which statement is the correct declaration and initialization of an ArrayList of String values?

a)

ArrayList<String> name

name = ArrayList<String>();

b)

ArrayList<String> name;

name = new ArrayList<String>();

c)

ArrayList name;

name = new ArrayList<String>();

d)

String<ArrayList> name;

name = new String<ArrayList>();

e)

None of the mentioned

58.

LinkedList can NOT be of generic type <T>

a)

True

b)

False

59.

What advantage does a linked list have over an array?a. Size of the list doesn't need to be mentioned at the beginning of the program

a)

Size of the list doesn't need to be mentioned at the beginning of the program

b)

You can add or remove elements from the middle of the list.

c)

The linked list doesn't have a size limit

d)

all of the above

60.

Which data structure can be used to implement a stack?

a)

Array

b)

Linked List

c)

Queue

d)

Tree

61.

We can use the following function below to determine the sum of an array of numbers. What is the Big O notation for this algorithm?

static int[] array={36,14,1,7,21};

public static int sumOfSequentialArray(int[] array) { int sum=0;

for (int i=0; i<array.length; i++){

}

}

sum+=array[i];

return sum;

a)

O(n)

b)

O(logn)

c)

O(1)

d)

O(n*n)

62.

The time complexity of the given example is:

public static int fib(int n) { if(n<=1) return n;

return fib(n-2)+ fib(n-1);

}exponential

a)

exponential

b)

logarithmic

c)

linearithmic

d)

quadratic

63.

Our algorithm needs to find every index where the item exists. The algorithm is below. What is the Big O runtime for this algorithm?

public static void main(String[] args) {

List<String> values = List.of("A", "B", "C", "B"); String item = "B";

List<Integer> indices = new ArrayList<>();

for (int i = 0; i < values.size(); i++) {

if (Objects.equals (values.get(i), item)) { indices.add(i); }

}

System.out.println(indices);

a)

O(log n)

b)

O(nlogn)

c)

O(n)

d)

O(1)

64.

Look at square numbers: square(1) = 1; square(N) = square(N-1) + 2N -1

Which method below successfully implements this definition?

a)

int square( int N ){

if ( N==1 ) {

return 1;

}

else

{

return square(N-1) + 2*N - 1;

}

}

b)

int square( int N ){

if ( N&1 ) {

return 1;

}

else

{

return N*N;

}

c)

int square( int N ){

if ( N=1 ) {

return 1;

}

else

{

return square(N-1) + 2*N - 1;

}

}

d)

int square( int N ){

if ( N==1 )

{

return 1;

}

else {

return square(N);

}

}

65.

Which traversal visits the left subtree first, then the root node, and finally the right subtree?

a)

Preorder traversal

b)

Inorder traversal

c)

Postorder traversal

d)

Lvl-order traversal

66.

Specify ArrayList advantages over LinkedList

a)

increasing the size

b)

arrayList is better for manipulating the data

c)

more memory usage

d)

arrayList is better for storing and accessing the data

67.

What will be the output of the following code:

int factorial(int n) {

if(n == 0)

return 1;

else

return n * factorial(n-1);

}

int main() {

int number = 5;

cout<<factorial(number);

return 0;

}

a)

0

b)

1

c)

5

d)

120

68.

What data structure is commonoly used to implement BFS?

a)

Stack

b)

Queue

c)

Heap

d)

Binary tree

69.

Data structure that can increase by itself

a)

Array

b)

ArrayList

c)

LinkedList

d)

HashTable

70.

Binary Search can be categorized into which of the following?

a)

Brute Force technique

b)

Divide and conquer

c)

Greedy algorithm

d)

Dynamic programming

e)

All of the mentioned

71.

Choose a worst case time complexity of insertion sort algorithm.

a)

O(n)

b)

O(n^2)

c)

O(n-1)

d)

O(1)

72.

Which of the following is not a typical application of queues?

a)

Process scheduling

b)

Message passing between processes

c)

Breadth-first search algorithm

d)

Depth-first search algorithm

73.

What will be print when the following code executes?

ArrayList<Integer> arrayList = new ArrayList<Integer>();

arrayList.add(7);

arcaylist.add(8);

arrayList.add(9);

System.out.println(arraylist.remove(0));

a)

7

b)

8

c)

9

d)

0

74.

When 2 elements map to the same slot in the hash table, it is called

a)

collision

b)

searching

c)

sorting

d)

none of the mentioned

75.

What does the Hash table look like?

a)

An array of multi-linked lists

b)

Table of arrays

c)

. An array of singly-linked lists

d)

Graph

76.

Unlike that of selection sort, the running time of insertion sort depends on the initial order of the items in the input.

a)

True

b)

False

77.

In Hashing so-called hash code can be used as a way to narrow down our search when looking for the item in the set

a)

True

b)

false

78.

____ is a data structure that can efficiently support the basic priority-queue operations

a)

String objects

b)

Binary heap

c)

Node

d)

Linked lists

79.

What index value is used to locate the last element in the numbers ArrayList?

a)

numbers.size()

b)

numbers.length() - 1

c)

numbers.size()-1

d)

numbers.length()

80.

Which of the following operations can be perfomed on a binary search tree in O(log N) time?

a)

insertion

b)

delection

c)

search

d)

all the mentions

81.

Data structure that has same size throughput the program

a)

array

b)

arrayList

c)

LinkedList

d)

HashTable

82.

Big O-notation of the following expression is equal to linear complexity

a)

True

b)

False

83.

Consider a hash table with 7 slots.The hash function is (не видно) array will look like:

a)

49,8,86,66,45,12,20

b)

12,66,45,86,49,8,20

c)

20,12,45,66,86,8,49

d)

8,12,20,45,49,66,86

84.

The worst case running times of Insertion sort,merge sort and quick sort ,respectively ,are:

a)

O(n log n),O(n log n) and O(n^2)

b)

O(n^2),O(n^2) and O(n log n)

c)

O(n^2),O(n log n) and O(n log n)

d)

O(n^2),O(n log n) and O(n^2)

85.

What is the maximum number of nodes in a binary tree of height h?

a)

2^h-1

b)

h^2

c)

2*h

d)

hl