Python Programming - MCQ Practice Questions
Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.
188 questions | 100% Free
Which of the following sorting algorithms has the best average-case time complexity?
What will be the output of the following code that uses recursion to compute the -th Fibonacci number?
```python
def fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)
print(fib(6))
```
What is the space complexity of Merge Sort?
What will be the output of the following Python code implementing linear search?
```python
def linear_search(arr, target):
for i, val in enumerate(arr):
if val == target:
return i
return -1
result = linear_search([10, 30, 20, 50, 40], 50)
print(result)
```
Which of the following correctly describes the working principle of Insertion Sort?
What will be the output of the following code that implements a recursive binary search?
```python
def rec_binary_search(arr, low, high, target):
if low > high:
return -1
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
return rec_binary_search(arr, mid + 1, high, target)
else:
return rec_binary_search(arr, low, mid - 1, target)
arr = [1, 3, 5, 7, 9, 11]
print(rec_binary_search(arr, 0, len(arr) - 1, 7))
```