APT - Question Paper Series Test 2024 Scheme - 2
APT - Question Paper Series Test 2024 Scheme - 2
7a Given an array arr of integers, an inversion is defined as a pair of indices (i, [8] 4 K3
j) such that:
i<j
arr[i] > arr[j]
Example: For arr = [3, 1, 2], the inversion pairs are (3, 1) and (3, 2). The
goal is to count the total number of inversions in the array. For the example
array, the number of inversions is 2.
Design a brute force algorithm to count inversions in a given array of size n.
Count the steps your algorithm takes on the given array in terms of n.
7b For the following problems, specify whether a brute-force or divide-and- [6] 4 K3
conquer approach would be more appropriate and justify your choice:
Cracking a password.
Sorting a large dataset.
OR
8a Draw a diagram showing how the array [8, 4, 3, 7, 6, 5, 2, 1] is sorted using [8] 4 K3
the merge sort algorithm. Write a pseudocode for merge sort and explain
each step briefly.
8b Explain how a divide-and-conquer approach can be used to calculate the [6] 4 K3
power of a positive integer x, i.e, xn, n > 0. Provide pseudocode.
CO3: Utilize effective algorithms to solve the formulated models and translate
algorithms into executable programs.
CO4: Interpret the problem-solving strategies, a systematic approach to solving
computational problems, and essential Python programming skills