1. Refer to the array A shown in Figure 1 for subsequent computations. You may replace the letters with the correspondin
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
1. Refer to the array A shown in Figure 1 for subsequent computations. You may replace the letters with the correspondin
please thank you!
1. Refer to the array A shown in Figure 1 for subsequent computations. You may replace the letters with the corresponding numbers, e.g., A=1, Z=26 to solve this question. However, you must present your solutions by drawing the step-by-step computations of the sorting algorithms using the letters. T N Q L M Z Y X Figure 1 Depending on your matriculation number, the sub-questions you need to answer will vary. First, multiply the last five digits (excluding the non-zero digits) in your matriculation number. If this product value ends between 0 and 3, answer (a), (b), (c) and (d); if between 4 and 6, answer (e), (f), (g), and (h); else if between 7 and 9, answer (i), (i), (k), and (1). Please declare the product value first before working out the solution.
(20 marks) (i) Explain and show each step in using the mergesort algorithm to sort array A. (15 marks) (j) Trace the steps of the bubblesort algorithm (as discussed in Tutorial 8) on array A. (15 marks) (k) Write an algorithm using counting sort to sort an array of integers in the range [-k, k]. You may make use of the functions discussed in the lecture to construct your algorithm. (20 marks) (1) Write an algorithm to sort the integer elements of an array B in increasing order. All the elements of the array are assumed to be unique. The main sorting strategy is to swap B and B[i+1] if B > B[i + 1]. The algorithm is able to stop earlier if such a swap is no longer needed. You may assume that the standard function swap() is given.