Skip to content

O(n) insertion time #22

@LilithHafner

Description

@LilithHafner

There are cases where construction is O(n^2) (meaning O(n) amortized insertion time):

This happens when the values span a large number of levels. I suspect that this could be O(1) insertion time by not calling sortperm! every time a new level is added.

julia> function build_coin_flip(n)
           ds = DynamicSampler()
           for i in 1:n
               push!(ds, i, 0.5^i)
           end
           ds
       end
build_coin_flip (generic function with 1 method)

julia> x = 1:100;

julia> y = [(@b xi build_coin_flip seconds=.01).time for xi in x];

julia> plot(x,y)

julia> plot!(x, 1.2e-9x.^2 .+ 8e-8x)

julia> savefig("fig.png")

fig

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions