Question

Ranking an array is different from sorting an array. Assume an array is {3, 4, 2},...

Ranking an array is different from sorting an array. Assume an array is {3, 4, 2}, the ranks of the elements in ascent order are {2,3,1}. If two elements are the same, they are ranked the same. The next rank after the duplicate elements should be added by 1. Assume an array is {3, 3, 4, 2}, the ranks are {2, 2, 4, 1}. Intensively use array and loop. No need to use any sorting algorithm.

Can you explain the the meaning of the above , I don't see any addition of one on the example can you clarify?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey, I have explained your doubt, If in case you still have any doubt, do ask me in comments and if you find the solution helpful, then do upvote :)

In this question, they are saying that ranking is different from sorting. The examples they have given are-

1) Suppose an array {3,4,2}, then if we sort them, they will give {2,3,4} and they will be ranked as-

2 comes first, so its rank is 1

3 comes second, so its rank is 2

4 comes third, so its rank is 3

Hence, the rank of array {3,4,2} is {2,3,1}

---------------------------------------------------------------------------------------------------------------------------------------

2) Suppose an array {3,3,4,2}, then if we sort them, they will give {2,3,3,4} and they will be ranked as-

Now,

2 comes first, so its rank is 1

Now, since 3 has duplicate, so 3 and its duplicate will get rank 2. But, since these two elements are same, so the next rank that comes after that i.e 3 will get added by 1 and will now become 4.

So, 4 comes third, but it will get rank 4

Hence, the rank of array {3,3,4,2} is {2,2,4,1}.

Add a comment
Know the answer?
Add Answer to:
Ranking an array is different from sorting an array. Assume an array is {3, 4, 2},...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are working as the software developer and need to identify the best sorting algorithm. Please...

    You are working as the software developer and need to identify the best sorting algorithm. Please refer to the following URL: https://www.geeksforgeeks.org/sorting-algorithms/ You can pick any two-sorting algorithm. You need to determine which sorting algorithm is the best to sort the array of 10k elements. Use the following steps to help with your solution: Create C++ functions for any two-sorting algorithm. Write down the random array generation function to generate at least 10k elements. Pass the same array into both...

  • QUESTION 3 Suppose that you have been running an unknown sorting algorithm. Out of curiosity, you...

    QUESTION 3 Suppose that you have been running an unknown sorting algorithm. Out of curiosity, you once stopped the algorithm when it was part-way done and examined the partially sorted array. You discovered that the last K elements of the array were sorted into ascending order, but the remainder of the array was not ordered in any obvious manner. Based on this, you guess that the sorting algorithm was (select all that apply): heapsort insertion sort mergesort quicksort Shell's sort...

  • Consider the following sorting algorithm: How to sort an array A Step 1: copy each element...

    Consider the following sorting algorithm: How to sort an array A Step 1: copy each element from A into an AVL tree Step 2: copy each element from the AVL Tree back into the array The algorithm shown above is known as tree sort (because it is traditionally performed with AVL trees). Complete the following implementation of this algorithm. Note that you have two ways to form a loop. You can use an indexing loop, or an iterator loop. Which...

  • in C++ HeapSort Implement the heapsort algorithm for sorting an array of integers. Input structure Each...

    in C++ HeapSort Implement the heapsort algorithm for sorting an array of integers. Input structure Each case starts with an integer number which indicates the number of elements to be sorted. Then, the elements follow, one per line. You can assume the input is correctly structured (i.e., no data are missing Output structure Output the sorted sequence separeted by";" (in non-decreasing order). Do not insert spaces or a new line at the beginning or at the end of any element.

  • 2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is...

    2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Gi pseudocode for an algorithm that will solve the following...

  • Assume that you are sorting an array of 8 elements with quick sort. You just finished...

    Assume that you are sorting an array of 8 elements with quick sort. You just finished the first pass and the array looks like below. Which statement is true for the pivot value? 4 8 12 16 18 20 22 24 QUICKSORT ALGORITHM Quicksort selects a specific value called a pivot and rearranges the array into two parts (called partioning). If the array is randomly ordered, it does not matter which element is the pivot. For simplicity, the first element...

  • 2. Assume you have an input array A with entries numbered 1 through n. One intuitive...

    2. Assume you have an input array A with entries numbered 1 through n. One intuitive way to randomize A is to generate a set of n random values and then sort the array based on these arbitrary mumbers. (a) (10 pts) Write pseudocode for this PERMUTE-BY-SorTInG method (b) (10 pts) Do best-, average, and worst-case analyses for this method. (c) Extra credit (15 pts): The algorithm RANDOMIZE-In-PLACE(A) A. length for i 1 to n 1 n= 2 swap Ali...

  • Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8...

    Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...

  • The zigzag sorting problem takes an array data of size n and outputs a per- mutation...

    The zigzag sorting problem takes an array data of size n and outputs a per- mutation where data[1] <data[2] > data[3] = data[4] > data[5] S..., all the way to the end of the array. (In general data[i] = data[i+1] if i is odd and data[i] > data[i+1] if i is even.) Answer the following questions about developing algorithms for the zigzag sorting problem. 1. Give pseudocode for a brute force algorithm for zigzag sorting. Your pseudocode just needs to...

  • Java We did in lecture, and explain your answer briefly. Problem 4: Sorting practice 14 points;...

    Java We did in lecture, and explain your answer briefly. Problem 4: Sorting practice 14 points; 2 points for each part individual-only Important: When answering these questions, make sure to apply the versions of these algorithms that were discussed in lecture. The Java code for each algorithm can be found in our Sort class. Given the following array: {14, 7, 27, 13, 24, 20, 10, 33 1. If the array were sorted using selection sort, what would the array look...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT