iGET

Python Programming - MCQ Practice Questions

Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.

189 questions | 100% Free

Q.1Medium

What is the time complexity of the binary search algorithm implemented on a sorted list in Python?

Q.2Medium

What will be the output of the following code implementing bubble sort? ```python def bubble_sort(arr): n = len(arr) for i in range(n): for j in range(0, n - i - 1): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] return arr print(bubble_sort([64, 34, 25, 12, 22])) ```

Q.3Medium

What is the worst-case time complexity of Quick Sort?

Q.4Medium

What will be the output of the following code? ```python def binary_search(arr, target): low, high = 0, len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == target: return mid elif arr[mid] < target: low = mid + 1 else: high = mid - 1 return -1 print(binary_search([2, 5, 8, 12, 16, 23], 12)) ```

Q.5Medium

Which of the following sorting algorithms has the best average-case time complexity?

Q.6Medium

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)) ```

Q.7Medium

What is the space complexity of Merge Sort?

Q.8Medium

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) ```

Q.9Medium

Which of the following correctly describes the working principle of Insertion Sort?

Q.10Medium

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)) ```