0% found this document useful (0 votes)
73 views

1a. Practice Quiz 2

This document contains a practice quiz for an algorithm and data structures course. It includes 24 multiple choice questions, 7 true/false questions, and 7 short answer questions about algorithms, data structures, searching and sorting techniques. Specifically, it covers topics like algorithm complexity, linear search, binary search, selection sort, insertion sort, bubble sort, and their time and space complexities.

Uploaded by

maryam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

1a. Practice Quiz 2

This document contains a practice quiz for an algorithm and data structures course. It includes 24 multiple choice questions, 7 true/false questions, and 7 short answer questions about algorithms, data structures, searching and sorting techniques. Specifically, it covers topics like algorithm complexity, linear search, binary search, selection sort, insertion sort, bubble sort, and their time and space complexities.

Uploaded by

maryam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CIS 2203 Practice Quiz 2 202010

CLO2

Multiple Choice Questions (1 mark each)


1. An algorithm is a _________ set of precise instructions for performing computation.
a. Infinite
b. Finite
c. Constant
d. None of the above
2. Which of the following is not a property of a well-formed algorithm?
a. Finiteness
b. Correctness
c. Generality
d. easy to write
3. What is algorithm effectiveness?
a. Perform each step of an algorithm exactly and in a finite amount of time
b. Produce the correct output.
c. Precisely put values for each set of input values.
d. Produce the desired output after a finite number of steps.
4. Algorithm complexity depends upon:
a. Time only
b. Space only
c. Both Time and Space
d. None of the above
5. What is the output when the following code is run?

linearList = [3,5,9,7,6,12,15,1]
target = 35
for x in linearList:
if x == target :
print("The number is " + str(x))

a. The number is: 35


b. The number is not: 35
c. Will print nothing
d. Target = 35
6. What is the error in the following code?

1. counter = 1
2. for x in range(1,10,1):
3 if x >= 5 :
4 print(counter)
5 else:
6 print(x)

a. Line 2 (syntax error)


b. Line 3 and 5 (syntax error)
c. Line 4 and 6 (indentation error)
d. No error
7. What is the output when the following code is run?

sumVal=0
pg. 1
CIS 2203 Practice Quiz 2 202010
for x in range(1, 5):
     sumVal = sumVal + x
print(sumVal)

a. 6
b. 10
c. 4
d. 3
8. What is the output when the following code is run?

counter = 0
for x in range(0, 20, 4) :
if (x%6 ==0):
counter +=1
print (counter)

a. 4
b. 2
c. 3
d. 0
9. In the ________ search, each element is compared with x till found or not found.
a. Binary
b. Linear / Sequential
c. Merge
d. None of the above
10. Which of the following sorting algorithm repeatedly selects the next smallest item?
a. Selection sort
b. Bubble sort
c. Merge sort
d. Insertion sort
11. On the third iteration of the selection sort for list 3, 5, 4, 1, 2 we get ___________
a. 1, 2, 4, 3, 5
b. 1, 2, 3, 4, 5
c. 1, 5, 4, 3, 2
d. 3, 5, 4, 1, 2
12. To sort a list with n elements, the insertion sort begins with the __________ element.
a. First
b. Second
c. Third
d. Fourth
13. Which of the following sorting algorithm works by repeatedly swapping the adjacent elements if they are in
wrong order.
a. Merge sort
b. Insertion sort
c. Selection sort
d. Bubble sort
14. Which of the following is a worst-case situation when using the linear search algorithm?
a. Item is somewhere in the middle of the array
b. Item is not in the array at all
pg. 2
CIS 2203 Practice Quiz 2 202010
c. Item is the last element in the array
d. Item is the last element in the array or is not there at all
15. The time complexity of the Linear Search algorithm is:
a. O(n)
b. O(log n)
c. O(n2)
d. O(n log n)
16. The time complexity of the Binary Search algorithm is:
a. O(n)
b. log2 (n)
c. 0
d. 1
17. The time complexity of the Bubble sort algorithm is:
a. O(n)
b. O(log n)
c. O(n2)
d. O(n log n)
18. What is the time complexity of the following code?

def NestedLoops(int n):

for i in range(0, n):

for j in range(i, j < n):

k=j*k+i

a. ϴ(log n)
b. ϴ(n)
c. ϴ(n2)
d. ϴ(n3)
19. What is the value of a when n=5 in the code snippet?

20. What is the value of the variable ‘ thesum’ after executing the following code
segment?

pg. 3
CIS 2203 Practice Quiz 2 202010
21. The following code snippet finds the summation of numbers divisible by 3 in the range (1,10). What will be the
output of this code segment execution?

22. The following code segment finds the summation of even numbers in the myNumbers Array. Select the best
answer that completes the “If” statement in the algorithm.

23. Consider the following code below and the list = [1, 4, 5, 7]. What will the output be?

24. Apply the following linear search code, then choose the correct output.

True / False Questions


T/F The Binary Search algorithm is more efficient than the Linear Search algorithm.

T/F The Insertion Sort & Selection Sort algorithms are similar.

T/F Algorithm time complexity means that the amount of extra memory or storage required depends on the size of
the input.

T/F It is not necessary for an algorithm to guarantee terminating and producing a result.

T/F The time complexity of an algorithm is usually more important than its space complexity.

T / F The time complexity of 43n2+24n+17 is O(n2).

pg. 4
CIS 2203 Practice Quiz 2 202010
T/ F Time complexity of binary search algorithm is constant.

Short Answer Questions


1. Define an algorithm. What is the difference between an algorithm and implementation? (3 marks)
2. Describe the Selection sort, the Insertion sort, and the Bubble sort algorithms. (3 marks)
3. Write down the Selection Sort Algorithm. (3 marks)
4. Complete the following linear search code, so the output is (True).

5. The code above is using the Binary search algorithm to search for the integer (4), in the range (3, 12). Write
down the values of i, middle and j. (5 marks)

Iteration No midpoint i j

The index on integer (4) is ______.

6. Consider the Binary search shown below:

pg. 5
CIS 2203 Practice Quiz 2 202010

If the item=25 and the alist= [11, 12, 9, 8, 13, 12, 22, 23, 25] answer the following questions:
a. What will be the value of the variables (first, last, midpoint, index) after each iteration (pass)?

Iteration No midpoint first last index

b. What will be the remaining numbers in the list after each iteration (pass)?

c. How many iterations will be required to find the key?


d. What is the time complexity of this algorithm?
e. What will be returned by this algorithm (the output)?
7. For the list = [12, 1, 4, 15, 3, 10].
a. Write the list order for 3 iterations by using Selection sort. (5 marks)

b. Write the list order for 3 iterations by using Insertion sort. (5 marks)

pg. 6
CIS 2203 Practice Quiz 2 202010

c. Write the list order for 3 iterations by using Bubble sort. (5 marks)

pg. 7

You might also like