Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* this algorithm takes both arrays and looks for the kth element.
- pre-condition: S and T are arrays with the same size and contain integers.
- post-condition: the kth element is returned. */
- Algorithm input(int S[], int indexS, int T[], int indexT, int k)
- if (k = 2)
- result <- pick the second smallest element between S[indexS], S[indexS + 1], T[indexT] and T[indexT + 1]
- return result;
- end IF
- int medianOfS <- S[indexS + floor(k/2)];
- int medianOfT <- T[indexT + floor(k/2)];
- if (medianOfS < medianOfT)
- return input(S, indexS + floor(k/2), T, indexT, ceil(k/2));
- end IF
- else return input(S, indexS, T, indexT + floor(k/2), ceil(k/2));
- end ELSE
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement