English, asked by debabratagayen48, 4 months ago

Design a way to sort a list of positive integers in descending order based on the frequency of elements.​

Answers

Answered by Jasleen0599
0

Design a way to sort a list of positive integers in descending order based on the frequency of elements.​

  • The specified array must be sorted in this programme in descending order such that the elements are displayed from largest to smallest. Two loops can be used to accomplish this. An element will be chosen by the outer loop, and the inner loop will allow us to compare that element to the other elements.
  • An array's elements are output using the frequency sort method in decreasing order of their frequencies. The element that appears first in the input is printed first if two elements have the same frequency.

Algorithm

  1. Create and set up an array.
  2. The array is iterated over to choose an element.
  3. To compare a selected element from the outer loop with the remaining array items, an inner loop will be needed.
  4. Swap the values if any element's value exceeds the specified element.
  5. Keep going until the entire list is arranged in descending order.

#SPJ2

Answered by sourasghotekar123
1

Answer:

  • Create a method for descending sorting a list of positive integers based on the frequency of the entries. ​
  • This program needs to sort the provided array in descending order so that the elements are shown from largest to smallest. This can be done by combining two loops.
  • The inner loop will enable us to contrast the selected element with the other elements after the outer loop selects an element.
  • The frequency sort technique outputs an array's elements in decreasing order of their frequencies. If two elements have the same frequency, the element that appears first in the input is written first.

Algorithm:

  • Make and configure an array.
  • An element is selected by iterating through the array.
  • An inner loop will be required to compare a selected element from the outer loop with the other array members.
  • If any element's value is greater than the designated element, swap the values.
  • Continue until all of the items are listed in decreasing order.
  • #SPJ5
Similar questions