Adjacency Sort
CodeChefOpen on judge ↗
Problem description. Consider the following sorting algorithm to sort an array having distinct elements from 1 to N: calls = 0; sort (array A) if A is sorted return A Randomly pick i: among all i, such that i comes after i+1 in A Swap the positions of i and i+1 calls++ return sort(A) Given the array A, which is a permutation of 1 to N, what is the expected value of the variable "calls" (
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start