wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DSA mid-term revision (FIT HANU) pt.1

Total questions: 80

Worksheet time: 40mins

Name
Class
Date
1.

- Which is not a property of a algorithm?

a)

It must terminate for all inputs.

b)

The order of the algorithm’s steps must be precisely defined.

c)

The execution time and the memory needed for a algorithm must be percisely defined.

d)

It must be correct and composed of precisely defined steps.

2.

– Which statement below is wrong?

Select one:

a)

For the same data, some data structures may require more or less space.

b)

A data structure is a way of organizing data for processing within a computer program.

c)

A data structure is a piece of information (a physical instantiation of a data type)

d)

For the same operations on the data, some data structures lead to more or less efficient algorithms.

3.

– Which statement is correct concerning to the complexity of algorithm?

Select one:

a)

The complexity of an algorithm is determined by the total lines of code of the program that implements

the algorithm using a given programming language.

b)

The complexity of an algorithm is a measure of the amount of time and cost needed to implement this

algorithm.

c)

The complexity of an algorithm is a measure of the amount of time and space required by the algorithm

for an input of a given size n.

d)

The complexity of an algorithm is determined by the maximum value of the input size n that does not

affect the correctness of the algorithm.

4.

– When evaluating algorithm’s complexity, which approach makes possible an evaluation that is

independent of the hardware and software environments?

Select one:

a)

Using input data sets of varying size.

b)

Theoretical approach.

c)

Measuring the running time and memory space using the same hardware and software environment.

d)

Experimental approach.

5.

– What is time complexity of an algorithm?

Select one:

a)

The amount of time needed to implement the algorithm.

b)

The amount of time that the algorithm needs to run for an input of a given size n.

c)

The upper limits for excution time of the algorithm.

d)

The response time of the algorithm.

6.

– Which statement is wrong concerning to the best-case time complexity of an algorithm?

Select one:

a)

The best case of an algorithm A is estimated as the minimum number of primitive operations performed

by A on an input size n.

b)

Many algorithms perform exactly the same in the best case.

c)

The best-case is used frequently to analyze the time complexity of algorithms.

d)

The best-case gives us an lower bound on the time complexity of algorithms.

7.

– Which statement is wrong concerning to the average-case time complexity of an algorithm?

Select one:

a)

The average-case is places somewhere between the best-case and the worse-case.

b)

The average-case of an algorithm A is estimated as the average number of primitive operations

performed by A on an input size n.

c)

The average-case of an algorithm A is depended on the characteristic of the input data.

d)

The average-case is easy to determine.

8.

– Which statement is wrong concerning to the worst-case time complexity of an algorithm?

Select one:

a)

The worst case gives us an upper bound on time complexity of an algorithm.

b)

The worst-case of an algorithm A is estimated as the maximize number of primitive operations performed

by A on an input size n.

c)

At the worst-case the algorithm takes more time to finish than it does at the average-case and best-case.

d)

The worst-case is not very informative because many algorithms rarely perform at their worst-case.

9.

– Which one determines the asymptotic behavior of the function T(n)?

a)

The leading term.

b)

The term has the biggest coefficient.

c)

The first term.

d)

The last term.

10.

– Which notation represents the upper-bound of the grow rate of a function?

a)

Big-Theta notation

b)

Big-Omega notation

c)

Big-Oh notation

d)

Big-Alpha notation

11.

– Suppose that the estimated time complexity of algorithm A and algorithm B is TA(N) and

TB(N) respectively. How can we compare the time complexity of A and B?

a)

We compare the value of TA and TB corresponding to some special value of n.

b)

We compare the value of TA and TB corresponding to a very large, pre-defined value of n.

c)

We compare the value of TA and TB corresponding to every value of n.

d)

We compare the grow rate of the leading terms of TA(N) and TB(N).

12.

- Which statement below is wrong in the context of list data structure?

Select one:

a)

In the list, items are referenced by their value.

b)

Every item in the list, except for the head and tail, has an unique predecessor and an

unique successor.

c)

List can be implemented using an array or a collection of linked nodes.

d)

A list is a sequence of zero or more items of the same type.

13.

– In the ADT of the list data structure, getLength() method returns a/an ______ value?

Select one:

a)

Real number.

b)

Boolean.

c)

String.

d)

Integer.

14.

– In the ADT of the list data structure, isEmpty() method returns a/an _______ value?

Select one:

a)

String.

b)

Real number.

c)

Boolean.

d)

Integer.

15.

– Which statement is correct about array-based list?

Select one:

a)

Array-based is faster than linked-list in case of accessing list’s items.

b)

They can be implemented by Java language only.

c)

Array-based is faster than linked-list in case of inserting new item into the list.

d)

Elements of array-based list can be located dinamically and discontinuously.

16.

– Which statement is correct about linked-list?

a)

Linked-list cost more than array-based list in term of deleting and inserting operations.

b)

Elements of linked-list can be located dinamically and discontinuously.

c)

Elements of linked-list must be stored in consecutive memory blocks.

d)

Array-based list is more flexible in list’s size than linked-list.

17.

– In the ADT of the list data structure, remove(int post) method will?

Select one:

a)

Remove an item at the pos position form the list.

b)

Remove the last item form the list.

c)

Remove the first item from the list.

d)

Remove all items from the list.

18.

– In a single linked-list, if a NodeX(data,next) is a tail which is the value of the X’s

next?

a)

undefined

b)

null

c)

head

d)

0

19.

– In a Singly Linked List that have only one node X, which value does X.getNext()

return?

Select one:

a)

null

b)

The tail node

c)

The head it self

d)

undefined

20.

– Suppose that X is a node in the middle of the Singly Linked List. Complete the code

below to delete all nodes after X from the list?X.setNext( _____ );

Select one:

a)

null.

b)

X.getNext().

c)

X.getNext().getNext().

d)

tail.

21.

– Suppose that X is a node in the middle of the Singly Linked List. Complete the code

below to delete one node after X from the list?X.setNext( _____ );

a)

null.

b)

X.getNext().

c)

X.getNext().getNext().

d)

tail.

22.

– Complete the code below to insert a new node X at the POS position of a Singly

Linked List?

SLNode Y = traversing(POS); //travel to POS position

X.setNext(__________);

Y.setNext(X);

a)

Y.setNext(tail).

b)

Y.getNext().

c)

X.getNext().

d)

X.setNext(Y).

23.

– Complete the code below to travel from the head node to the POS position of a Singly

Linked List?

int c = 1;

SLNode node = head;

while(c < POS) {

_______;

node = node.getNext();

}

return node;

a)

node++

b)

node=node.setNext(tail)

c)

c=c+1

d)

c=c.getNext()

24.

– In a Circle linked-list, if a NodeX(data,next) is a tail which is the value of the X’s

next?

Select one:

a)

undefined

b)

null

c)

head

d)

0

25.

– Which is the common form of a node X in a Doubly Linked List?

Select one:

a)

X(data, next)

b)

X(data)

c)

X(data, prev, next)

d)

X(data, prev)

26.

– Which is common form of a node X in a Singly Linked List?

Select one:

a)

X(data, next)

b)

X(data)

c)

X(data, prev, next)

d)

X(data, prev)

27.

– A mathematical-model with a collection of operations defined on that model is called?

Select one:

a)

Primitive data type.

b)

Data structure.

c)

Algorithm.

d)

Abstract Data Type.

28.

- Which statement below is wrong about comparison sorting algorithms?

Select one:

a)

The time complexity of some comparison sorting algorithms can be faster than O(NlogN).

b)

Bubble sort, Merge sort and Heap sort are comparison sorting algorithms.

c)

The time complexity of a comparison sorting algorithm is based on the number of comparisons

and moves during sorting.

d)

The sorted order is determined based only on the comparisons between sort keys.

29.

– Which statement below is wrong in the context of linear sorting algorithm?

Select one:

a)

The time complexity is linear.

b)

The sorted order is determined based on the comparisons between sort keys.

c)

The sort key must be numeric.

d)

Counting sort and Radix sort are linear sorting algorithms.

30.

– In a stable sort algorithm ...?

Select one:

a)

The relative order of elements with equal keys are not maintained.

b)

The order of both key and non-key values are maintained.

c)

The relative order of elements with equal keys are maintained.

d)

The order of key values are maintained.

31.

– Merge sort and Quick sort are ...?

Select one:

a)

Based on Divide and Conquer approach.

b)

O(n^2) sorting algorithms.

c)

Linear sorting algorithm.

d)

The fastest sorting algorithms.

32.

– Which sorting algorithm locates the largest (or smallest) key and its index in each sort pass?

Select one:

a)

Bubble sort.

b)

Selection sort.

c)

Insertion sort.

d)

Heap sort.

33.

– Which statement is wrong about Insertion sort?

Select one:

a)

Scan and exchange any pair of elements that is out-of-order.

b)

It is O(n^2) sorting algorithm.

c)

Unsorted elements are inserted into an already sorted list.

d)

We must shift several elements to make place for the inserted one.

34.

– Which sorting algorithm scans and exchanges any pair of elements that is out-of-order?

Select one:

a)

Insertion sort.

b)

Bubble sort.

c)

Selection sort.

d)

Heap sort.

35.

– Which statement is wrong concerning to the Heap data structure?

Select one:

a)

It is a tree where all nodes have zero, one or two children.

b)

In a min-heap the parent node value is always greater than or equal to its children’s values.

c)

It is used in Heap sort algorithm.

d)

An array can be used to store heap’s nodes.

36.

– In Merge sort algorithm...?

Select one:

a)

.The input array is divided into two parts at the middle of the arra

b)

The input array is divided into two parts based on the pivot values

c)

The merge algorithm combines two sorted array by attaching the second array to the end of the

first one

d)

The worst case is O(N^2)

37.

– Which statement is wrong about Quick sort?

Select one:

a)

A merge algorithm is needed to combine two partitioned arrays

b)

The worst case is O(N^2)

c)

The array is partitioned based on the pivot value

d)

By choosing the pivot carefully, we can reduce the running time of the algorithm.

38.

– Suppose that we are using Radix sort on N elements, each element has P digits in base b (each

digit is in the range [0 .. B-1]), and couting sort algorithm is used to sort the digits. What is the

time complexity of the Radix sort algorithm?

Select one:

a)

O(N.P.B).

b)

O(P+N+B).

c)

O(B+N).

d)

O(P(N+B)).

39.

– What is an operation in which a list of elements is arranged either in ascending order or in

descending order?

Select one:

a)

Searching.

b)

Hashing.

c)

Sorting.

d)

Traversing.

40.

– Which of the following sorting algorithm does not have a worst case time complexity of O(n^2)?

Select one:

a)

Insertion sort.

b)

Quick sort.

c)

Buble sort.

d)

Merge sort.

41.

- Which statement below is wrong concerning to stack data structure?

Select one:

a)

It is a First In First Out (FIFO) list.

b)

A stack contains a sequence of zero or more items of the same type.

c)

push() and pop() are two operations defined in Stack’s ADT.

d)

List-based stack has no limit on total number of items of the stack.

42.

– Which statement below is wrong about queue data structure?

Select one:

a)

Dequeue is a special type of queue.

b)

It is a First In First Out (FIFO) list.

c)

Queue can be implemented using an array or a linked-list.

d)

enqueue() and dequeue() operations must be performmed at one end of the queue.

43.

– In the ADT of the Stack data structure, push() method is used to

Select one:

a)

take an item out of the stack

b)

get the total items in the stack

c)

get an item without deleting it from the stack

d)

add an item to the stack

44.

– Which statement is correct about array-based stack?

Select one:

a)

To add a new item into the stack: firstly, top is increased by 1, then current items will be shifted

one slot to the right to make space for the new item.

b)

To add a new item into the stack: firstly, top is increased by 1, then current items will be shifted

one slot to the left to make space for the new item.

c)

top is the first item of the array.

d)

top is the last item of the array.

45.

– In the ADT of the Queue data structure, dequeue() method will?

Select one:

a)

Remove an item from the queue at the rear position.

b)

Add a new item to the queue at the front position.

c)

Add a new item to the queue at the rear position.

d)

Remove an item from the queue at the front position.

46.

– In ADT of the Queue data structure, enqueue() method will?

Select one:

a)

Add a new item to the queue at the front position.

b)

Remove an item from the queue at the front position.

c)

Remove an item from the queue at the rear position.

d)

Add a new item to the queue at the rear position.

47.

– Which statement is wrong about array-based circular queue?

Select one:

a)

when front=rear the queue is empty.

b)

rear can be wrap around to the beginning of the array.

c)

front can be wrap around to the beginning of the array.

d)

when front=rear the queue is full.

48.

– Complete the code for the enqueue() method in array-based circular queue?

Select one:

a)

rear=rear+1

b)

rear=(rear+1)%maxSize

c)

front=front+1

d)

front=(front+1)%maxSize

49.

– Complete the code for the dequeue() method in array-based circular queue?

public void dequeue() {

if(!isEmpty()) {

int pos = front;

__________;

return items[pos];

}

}

a)

front=front+1

b)

rear=rear+1

c)

front=(front+1)%maxSize

d)

rear=(rear+1)%maxSize

50.

– Which statement is wrong about list-based queue?

Select one:

a)

front is the head and rear is the tail of the linked-list.

b)

A linked-list is used to implement the queue.

c)

Queue is empty when front=rear.

d)

List-based queue ADT does not have isFull() operation

51.

– Which of the following statement is true?

Select one:

a)

In both array-based stack and queue, when removing an item the corresponding index is increase

by 1

b)

The top of a stack corresponds to the front of a queue

c)

The contents of a queue can wrap around , while those of a stack can not

d)

.The pop() operation on a stack is simpler than the dequeue() operation on a queue.

52.

– Suppose you push 10, 20, 30, 40 onto a stack, then you pop three items. Which one is left on the stack?

Select one:

a)

40

b)

30

c)

10

d)

20

53.

– Suppose you enqueue 10, 20, 30, 40 onto a queue, then you dequeue three items. Which one is left on

the queue?

Select one:

a)

40

b)

30

c)

10

d)

20

54.

– The end which a new element gets added to a queue is called

Select one:

a)

Bottom

b)

Top

c)

Rear

d)

Front

55.

– What is the result of the following operation on the stack S: S.peek(S.push(X))?

Select one:

a)

X.

b)

S.push(X).

c)

Null.

d)

S.top.

56.

– What is the worst-case time for linear search finding a single item in an array?

Select one:

a)

Logarithmic time.

b)

Linear time.

c)

Constant time.

d)

Quadratic time.

57.

IDESQAS03

– What is the worst-case time for finding a key in a hash table (assume that there is no

collision)?

Select one:

a)

Constant time.

b)

Linear time.

c)

Quadratic time.

d)

Logarithmic time.

58.

– What additional requirement is placed on an array, so that binary search may be used to search

for a key?

Select one:

a)

The array elements must form a heap.

b)

The array must be sorted.

c)

The array must have at least 2 entries.

d)

The array's size must be a power of two.

59.

– What is the best definition of a collision in a hash table?

Select one:

a)

Two entries with different keys have the same exact hash value.

b)

Two entries are identical except for their keys.

c)

Two entries with the exact same key have different hash values.

d)

Two entries with different data have the exact same key.

60.

– A separate chaining hash table has an array size of 512. What is the maximum number of

entries that can be placed in the table?

Select one:

a)

512.

b)

There is no maximum.

c)

511.

d)

1024.

61.

IDESQAS08

– Which of the following is not an application of the queue data structure?

Select one:

a)

Job scheduling

b)

Evaluating a posfix expression

c)

Stack reversing

d)

Packet queueing

62.

– Consider a hash table of size seven, with starting index zero, and a hash function h(k)=(3k+4)

mod 7. What is the address of the key k=10?

Select one:

a)

3.

b)

0.

c)

7.

d)

6.

63.

– Complete the code below to search for key in an array using linear seach algorithm?

Select one:

a)

-1.

b)

true.

c)

a[i].

d)

i.

64.

– In a hash table of the size N using linear probing, what is the probing hash function hi(k)?

Select one:

a)

hi(k)=(h(k)+i) mod N.

b)

hi(k)=i mod N.

c)

hi(k)=h(k) mod N.

d)

hi(k)=i + k.

65.

– Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash

function: h(k)=k mod 10. Which of the following statements are true?

Select one:

a)

All elements hash to the same value.

b)

1471 and 6171 has to different value.

c)

Each element hashes to a different value.

d)

4199 and 9679 hash to the same value.

66.

– In the context of seach algorithms, which of the following statements are true?

Select one:

a)

Binary search is the fastest search algorithm.

b)

Linear search is faster than binary search.

c)

Hash data structure is used to support sorting.

d)

Binary search is faster than linear search, but it requires a sorted array.

67.

– Which of the following statements is used in binary search algorithm to halve the array?

Select one:

a)

middle=middle/2

b)

middle=(right-left)/2

c)

middle=(left + right)/2

d)

middle=midlle*2

68.

– Suppose that you want to sort a singly linked list, each list’s item is a large object. which of

the following sort algorithms should be used to minimum the time complexity?

Select one:

a)

Quick sort.

b)

Insertion sort.

c)

Heap sort.

d)

Bubble sort.

69.

– Method reverse() below is used to reverse the order of items in a Singly Linked List. Please

complete the code of the method?

int maxSum = 0;

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

for(int j = i; j < a.length; j++) {

int thisSum = 0;

for(int k = i; k<=j; k++)

thisSum += a[k];

if(thisSum>maxSum)

maxSum=thisSum;

}

a)

prev=head

b)

head=current

c)

current=head

d)

head=prev

70.

– Consider a Singly Linked List contains N nodes (N > 8), a method f1() is designed to find the

8th node from beginning, and method f2() is designed to find the 8th node from end. Which is

the time complexity of f1() and f2()?

Select one:

a)

O(N) and O(1)

b)

O(N) and O(N)

c)

O(1) and O(N)

d)

O(1) and O(1)

71.

– Method deleteTail() below is used to delete the last node in a Singly Linked List. Please

complete the code of the method?

public void deleteTail() {

int pos = getLength();

SLNode beforeTail = traversing(pos-1);

____________

}

a)

beforeTail.setNext(null)

b)

beforeTail = tail

c)

beforeTail.setNext(tail)

d)

beforeTail = null

72.

– Method tailToFront() below moves the last node of a Singly Linked List into the front of the

list. Please complete the code of the method?

public void tailToFront() {

int pos = getLength();

SLNode beforeTail = traversing(pos-1);

SLNode tail = beforeTail.getNext();

____________

}

a)

beforeTail.setNext(null); tail.setNext(head); head=tail;

b)

tail.setNext(null); beforeTail.setNext(head); head=beforeTail;

c)

tail.setNext(head); head.setNext(null); beforeTail=head;

d)

head.setNext(null); beforeTail.setNext(tail); tail=beforeTail;

73.

– Selection sort is used to sort an array in the descending order. When does the worst case

occur?

Select one:

a)

The array has several duplicated items.

b)

The array is already sorted in the ascending order.

c)

The array is already sorted in the descending order.

d)

The first and the last items of the array are the same.

74.

– Insertion sort is used to sort an array in the descending order. When does the best case occur?

Select one:

a)

The array contains several zero items.

b)

The array is already sorted in the descending order.

c)

The array is already sorted in the ascending order.

d)

The array has several duplicated items.

75.

–Given an array A that is almost sorted (only one or two elements are misplaced). Which sorting

algorithm gives the best time efficiency when applied on A?

Select one:

a)

Quick sort

b)

Bubble sort

c)

Merge sort

d)

Insertion sort

76.

– Which of the following sorting algorithms has the minimum number of swap operations in general?

Select one:

a)

Heap sort

b)

Insertion sort

c)

Quick sort

d)

Bubble sort

77.

– Consider a modified version of Merge sort where the input array is partitioned at the position one-third

of the length N of the array. What is the recurrence of this algorithm?

Select one:

a)

T(N)=2T(2N/3)+O(N)

b)

T(N)=2T(N/3)+O(N)

c)

T(N)=T(N/3)+T(2N/3)+O(N)

d)

T(N)=T(N/2)+T(3N/2)+O(N)

78.

– Which of the following sorting algorithms has the lowest worst case time complexity?

Select one:

a)

Quick sort

b)

Bubble sort

c)

Merge sort

d)

Insertion sort

79.

– Consider an array A where the items are in the range from 1 to n^3. Which of the following

sorting algorithms gives the best time efficiency when applied on A?

Select one:

a)

Radix sort

b)

Counting sort

c)

Quick sort

d)

Heap sort

80.

– What data structure would you mostly likely see in a non-recursive implementation of a

recursive algorithm?

Select one:

a)

Tree.

b)

Queue.

c)

Stack.

d)

Linked-List.