Add KthElementFinder algorithm (#5836)

This commit is contained in:
Hardik Pawar
2024-10-26 15:00:42 +05:30
committed by GitHub
parent cdf509fc06
commit d572997894
3 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package com.thealgorithms.datastructures.heaps;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class KthElementFinderTest {
@Test
public void testFindKthLargest() {
int[] nums = {3, 2, 1, 5, 6, 4};
assertEquals(5, KthElementFinder.findKthLargest(nums, 2));
}
@Test
public void testFindKthSmallest() {
int[] nums = {7, 10, 4, 3, 20, 15};
assertEquals(7, KthElementFinder.findKthSmallest(nums, 3));
}
}