Assume we have two arrays X[ ] and Y[ ] of n characters each, where X[ ]
Question:
Assume we have two arrays X[ ] and Y[ ] of n characters each, where X[ ] has n randomly ordered characters, while Y[ ] has exactly the same n characters but in different order. Your task is to find a way to group the cells of the array X[ ] and Y[ ]into pairs that hold the same character.
For example:
Input:
X[O, L, M, S, N, J, P, T, I, R, H, G]
Y[S, N, H, P, T, I, O, R, L, M, G, J]
Output:
X[0] with Y[6]
X[1] with Y[8]
X[2] with Y[9]
X[3] with Y[0]
… and so on
a) Using a brute-force approach, design an algorithm to solve this problem, and
analyze its complexity. (3+2 marks)
b) Design a more efficient algorithm to solve this problem (6 marks),
and analyze its complexity (3 marks) [Important instruction: Create an arbitrary
list of 7 characters in array X and their corresponding ones in array Y to provide
full explanation of how your proposed algorithm should work step by step] (6
marks)
c) Implement your efficient algorithm using Python (10 marks)
d) Prepare a brief report (250 words) comparing the two algorithms
Social Statistics for a Diverse Society
ISBN: 978-1483333540
7th edition
Authors: Chava Frankfort-Nachmias, Anna Leon-Guerrero