Algorithms MCQ Quiz in मल्याळम - Objective Question with Answer for Algorithms - സൗജന്യ PDF ഡൗൺലോഡ് ചെയ്യുക
Last updated on Mar 11, 2025
Latest Algorithms MCQ Objective Questions
Top Algorithms MCQ Objective Questions
Algorithms Question 1:
What will be the output of the following code?
def linearSearch(list, key):
for index in range(0,len(list)-1):
if list[index] == key:
return index+1
return None
list1 = [19, 32, 45, 56, 77, 89]
n = 89
pos = linearSearch(list1,n)
if pos is None:
print (n,"is not found in the list")
else:
print( n,"is found at position", pos)
Answer (Detailed Solution Below)
Algorithms Question 1 Detailed Solution
Correct answer: Option 4
Explanation:
- The program contains a logical error in the 2nd line.
- The range of the loop is specified from 0 to len(list)-1.
- The range function goes up to 1 less than the given upper limit.
- As a result, the loop in the given program runs from index values 0 to 4, because len(list) returns a value 6.
- The value 89 is located at index value 5. Since the loop never reaches that location, it terminates the loop and returns None to the calling function. Therefore, the program outputs that the value is not found in the list.
- If the erroneous statement is corrected, the program will output that the value 89 is found at position 6.
Algorithms Question 2:
The given statements are:
Statement 1: The amount of space an algorithm takes to process a given data, can be called its time complexity.
Statement 2: The algorithms whose time complexity is n2 are also known as Quadratic time algorithms.
Answer (Detailed Solution Below)
Algorithms Question 2 Detailed Solution
Statement 1 - The amount of time that an algorithm takes to complete its execution or to process the data is called Time complexity, ( In ques is defined as Space complexity, Not time complexity. )Time complexity is determined mainly by the loop execution time rest of the process takes smaller time than loop execution Space complexity is the stack space taken by the program to run or complete its execution. So, this statement is FALSE.
Statement 2 - Quadratic time algorithms are those algorithms in which The timely execution of an algorithm is directly proportional to the square size of the input size.
Here, n is the number of elements ( input size ). Quadratic time algorithms are much faster than the Linear ones ( For the bigger value of n )
Example of quadratic time complexity - When 2 nested loop runs simultaneously in a program. So, this statement is true.
So, Statement 1 is False and Statement 2 is True, and option 2 turns out to be the correct answer.
Algorithms Question 3:
In python, Fill the following black in the given binary search algorithm?
Consider array is Arr, size of the array is n, and searching element is target
Answer (Detailed Solution Below)
Algorithms Question 3 Detailed Solution
Algorithms Question 4:
In the Optimized bubble sort algorithm, If there are no swaps then the array becomes in sorted order. Fill the below blank to run the Optimized bubble sort algorithm behaviour.
def bubble_sort(array):for i in range(len(array)):
swapped = False
for j in range(0, len(array) - i - 1):
if array[j] > array[j + 1]:
temp = array[j]
array[j] = array[j+1]
array[j+1] = temp
swapped = True
if not swapped:
________________ ?
data = [-2, 45, 0, 11, -9]
bubble_sort(data)
print(data)
Answer (Detailed Solution Below)
Algorithms Question 4 Detailed Solution
The correct answer is option 1.
Concept:
The correct answer is option 1.
Concept:
The code is an optimized bubble sort algorithm. It means if there are no swaps then the array is in sorted order. Hence it can not perform any iterations or passes.
Explanation:
The given python code is an Optimized Bubble sort in Python.
def bubble_sor(array):
Here loop through each element of the array.
for i in range(len(array)):
Here is swapped variable is true it keeps track of swapping
swapped = False
Here is the loop to compare array elements.
for j in range(0, len(array) - i - 1):
Here compare two adjacent elements change > to < to sort in descending order
if array[j] > array[j + 1]:
Here swapping occurs if elements are not in the intended order.
temp = array[j]
array[j] = array[j+1]
array[j+1] = temp
swapped = True
Here no swapping means the array is already sorted so no need for further comparison.
if not swapped:
break
The driver code or the main function call from here:
data = [-2, 45, 0, 11, -9]
bubble_sor(data)
Here is the array Sorted Array in Ascending Order.
print(data)
Note:
go to, continue or return 0 will not work and it can not break the loop when there is no swaps in the previous iterations.
Hence the correct answer is break.
Algorithms Question 5:
What is output for the given python code.
def test(array):
for i in range(len(array)):
swapped = False
for j in range(0, len(array) - i - 1):
if array[j] > array[j + 1]:
temp = array[j]
array[j] = array[j+1]
array[j+1] = temp
swapped = True
if not swapped:
break
data = [-2, 45, 0, 11, -9]
test(data)
print(data)
Answer (Detailed Solution Below)
Algorithms Question 5 Detailed Solution
The correct answer is option 1.
Concept:
The code is an optimized bubble sort algorithm. It means if there are no swaps then the array is in sorted order. Hence it can not perform any iterations or passes.
Explanation:
The given python code is an Optimized Bubble sort in Python
def test(array):
Here loop through each element of the array.
for i in range(len(array)):
Here is swapped variable is true it keeps track of swapping
swapped = False
Here is the loop to compare array elements.
for j in range(0, len(array) - i - 1):
Here compare two adjacent elements change > to < to sort in descending order
if array[j] > array[j + 1]:
Here swapping occurs if elements are not in the intended order.
temp = array[j]
array[j] = array[j+1]
array[j+1] = temp
swapped = True
Here no swapping means the array is already sorted so no need for further comparison.
if not swapped:
break
data = [-2, 45, 0, 11, -9]
test(data)
Here is the array Sorted Array in Ascending Order.
print(data)
Hence the correct answer is [-9, -2, 0, 11, 45]
Algorithms Question 6:
What is the expected output for the given python code ?
def test(array, size):
for step in range(size):
min_idx = step
for i in range(step + 1, size):
if array[i] < array[min_idx]:
min_idx = i
(array[step], array[min_idx]) = (array[min_idx], array[step])
data = [12, 34,-2, 45,1, -25]
size = len(data)
test(data, size)
print(data)
Answer (Detailed Solution Below)
Algorithms Question 6 Detailed Solution
The correct answer is option 2.
Concept:
The given python code is a selection sort technique and prints in ascending sorted order.
Explanation:
def test(array, size):
for step in range(size):
min_idx = step
for i in range(step + 1, size):
Here, It sort in descending order, change > to < in this line select the minimum element in each loop
if array[i] < array[min_idx]:
min_idx = i
Here, It put min at the correct position
(array[step], array[min_idx]) = (array[min_idx], array[step])
data = [12, 34,-2, 45,1, -25]
size = len(data)
test(data, size)
Here, Sorted Array in Ascending Order.
print(data)
The output is,
[-25, -2, 1, 12, 34, 45]
Option 2: It uses the selection sort technique and prints in descending sorted order
False, The above algorithm can not prints [45, 34, 12, 1, -2, -25].
Option 3: It uses the selection sort technique and prints ONLY positive numbers ascending sorted order
False, The above algorithm can not print [1, 12, 34, 45].
Option 4:It uses the selection sort technique and prints ONLY negative numbers ascending sorted order.
False, The above algorithm can not print [-25, -2].
Hence the correct answer is It uses the selection sort technique and prints in ascending sorted order.