Skip to content

npm package for finding the kth smallest element in an array in average case linear time

License

Notifications You must be signed in to change notification settings

griffinmichl/kth-smallest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kth-smallest

Find kth smallest element in an arary of numbers

Uses a randomized quickselect to achieve O(n) average case time complexity

Build Status

Install

$ npm install kth-smallest

Usage

import kthSmallest from 'kth-smallest'

kthSmallest([10, 20, 30, 40], 0)
// 10

kthSmallest([10, 20, 30, 40], 2)
// 30

kthSmallest([10, 20, 30, 40], -1)
// 40

API

kthSmallest :: number a => [a] -> integer -> a

kthSmallest(numbers, k)

Arguments

  • numbers - An array of numbers
  • k - 0-indexed target (pass negative numbers for largest)

About

npm package for finding the kth smallest element in an array in average case linear time

Resources

License

Stars

Watchers

Forks

Packages

No packages published