Practical No. 5 NTH Max - Min Element - Implement Algorithms To Find NTH Max - Min Element in A List.
Practical No. 5 NTH Max - Min Element - Implement Algorithms To Find NTH Max - Min Element in A List.
5
Nth Max/Min Element: Implement algorithms to find Nth Max/Min element in a list.
Steps:
1. Remove Duplicates:
○ Ensure the list contains only unique values to avoid incorrect ranking.
2. Sort the List:
○ Sort the list in ascending order for minimum or descending order for
maximum.
3. Access the Nth Element:
○ Retrieve the element at the desired rank using indexing.
Example:
For the array [3, 1, 4, 1, 5, 9, 2, 6, 5]:
● 3rd Maximum = 5
(Sorted descending: [9, 6, 5, 4, 3, 2, 1])
● 3rd Minimum = 3
(Sorted ascending: [1, 2, 3, 4, 5, 6, 9])
Complexity:
Practical Application: