Question
Consider the following Python-like pseudo-code for a
modified Merge Sort algorithm that sorts an array `arr` and also counts the number of "reverse pairs" (i.e., pairs `(i, j)` such that `i < j` and `arr[i] > 2 arr[j]`). ```python def merge_sort_and_count_reverse_pairs(arr): n = len(arr) if n 2 right_half[j]: cross_pairs += (len(left_half) - i) # All remaining elements in left_half form a reverse pair with right_half[j] j += 1 else: i += 1 # Standard merge step (omitted for brevity, assume it correctly merges left_half and right_half) merged_arr = merge(left_half, right_half) return merged_arr, left_pairs + right_pairs + cross_pairs # Assume a standard merge function exists: # def merge(left, right): # ... returns sorted merged array ... input_array = [2, 4, 3, 5, 1] ``` If `merge_sort_and_count_reverse_pairs(input_array)` is called, what will be the total number of reverse pairs returned?Solution
The pairs are: (2,1), (4,1), (3,1), (5,1).
The diameter of the base of a right circular cone is 4.2 cm and its height is 10 cm. calculate the volume of the cone.
Monthly income of Amit and Bhola is Rs. (x + 120) and Rs. x, respectively. If monthly income of Amit is increased by 16% while that of Bhola is decrease...
A shopkeeper sets the selling price of an item higher than its cost price. After offering a 4% discount, the shopkeeper earns a 20% profit. What percent...
Three bells ring at intervals of 28 seconds, 60 seconds, and 84 seconds, respectively. How many times will all three bells ring together in a span of 10...
How many pairs of letters are there in the word “HELICOPTER” each of which have as many letters between them in the word as they have between them i...
- The ratio between the downstream speed and upstream speed of boat is 3:2 respectively. If boat can cover 180 km upstream in 15 hours, then find the speed o...
A boat has a speed of 30 km/h in still water. In a particular stream, the boat's downstream speed is 50% faster than its speed upstream. What is the spe...
In a village with a population of 8,500 people, 80% of them are adults. Among these adults, only 75% possess a ration card. Furthermore, 60% of the rati...
At present, the combined age of Ravi and Rajeev is 42 years, with their ages in the ratio of 4:3. What will be the ratio of their ages six years from now?
Ujwal took a loan at 18% per annum simple interest for 2 years and repaid a total of Rs. 40,800. If he had instead taken the same loan at r % per annum ...