But this is due to the creation of a new set n times. Is there a way to do this and only create a new set once?
, . , , O (lg n) - :) O (lg n) min , , .
, , , , . , AVL RB , , .
treap , , , . AVL RB, treap node, , . , :
http://pastebin.com/j0aV3DJQ
split, , , , . split O (lg n), , - , , .
n ... n , ?
Treap:
open Treap
let nthLargest n t = Seq.nth n (Treap.toSeqBack t)
let removeTopN n t =
let largest = nthLargest n t
let smallerValues, wasFound, largerValues = t.Split(largest)
smallerValues
let e = Treap.empty(fun (x : int) (y : int) -> x.CompareTo(y))
let t = [1 .. 100] |> Seq.fold (fun (acc : Treap<_>) x -> acc.Insert(x)) e
let t' = removeTopN 10 t
removeTopN O (n + lg m) , n - , m - .
, ;)