Question 1 - What have You Done? [30%] One day, handsome Jeff finished grading n…
Jump to turn (7)
- 1Question 1 - What have You Done? [30%] One day, handsome Jeff finished grading n
- 2do it in python code
- 3explain the time complexity of this algorithm
- 4but why logn
- 5Question 2 - Linked List [30%] Implement a linked list and solve the following s
- 6Question 4 - Hash Table [20%] Insert the keys {17, 94, 86, 22, 98, 79, 54, 38} i
- 7give me a lesson on hash table data structure and all the collison resolution me
- User
Question 1 - What have You Done? [30%] One day, handsome Jeff finished grading n assignment scripts. He sorted the scripts in ascend- ing order of UID (assume all UIDs are unique). To inspect his work, Ben read k scripts from the top, and put them back at the bottom of the pile without changing the order of the k scripts. Suppose the UID of the n scripts are stored in list A as integers with the current placing order. The first element in A represents UID of the script on the top. To arrange the papers back in order, Jeff needs to find out the value of k. You may assume that n is in power of 2, and 0 ≤ k ≤ n − 1. Example: For input A1 = [43, 60, 71, 3, 14, 23, 26] and n = 7, the output will be k = 4. Ben has read scripts with UID 3, 14, 23, 26. Your Tasks: (a) [10%] Jeff has written the function reOrder1(A, n) to solve the problem. Explain briefly how his code solve the problem and analyze it’s worst case time complexity. Algorithm 1.1 Pseudocode of reOrder1 1: function reOrder1(A, n) 2: 3: k = 0 4: for (i = 0 to n − 2) do 5: if (A[i] > A[i + 1]) then 6: k = n − i − 1 7: end if 8: end for 9: 10: return k 11: 12: end function (b) [15%] If n is large, it would be a nightmare to run Jeff’s algorithm by human efforts. Write the pseudocode of another algorithm reOrder2(A, n) to solve the problem. The algorithm must be asymptotically faster than reOrder1(A, n). Briefly explain what the code does, and analyze the algorithm’s worst case time complex- ity