HackerNoon Mobile

Better reading experience on the app
Kth Largest Element in an Array - Quickselect Using Lomuto Partitioning Scheme.by@kliukovkin
1,261 reads

Kth Largest Element in an Array - Quickselect Using Lomuto Partitioning Scheme.

tldt arrow
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

The algorithm is to use a partitioning algorithm from quickselect. We need to find the N-k smallest element in the array. We use a heap to sort an array and keep the top Kth largest element. The algorithm uses the fact that the work done keeps decreasing on each iteration, gives the O(n) runtime. The toughest thing in the algorithm is understanding how the partitioning works is to imagine an array in a sorted array in linear time using the Lomuto algorithm.

Company Mentioned

Mention Thumbnail
featured image - Kth Largest Element in an Array - Quickselect Using Lomuto Partitioning Scheme.
Georgii Kliukovkin HackerNoon profile picture

@kliukovkin

Georgii Kliukovkin


Receive Stories from @kliukovkin

react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!