Skip to content

std.sort.pdq is there a wrong limit for the recursion depth? #24399

@oittaa

Description

@oittaa

Zig Version

0.14.1

Steps to Reproduce and Observed Behavior

Is there a reason to use std.math.floorPowerOfTwo() because it basically defeats the whole purpose of the heap sort?

const max_limit = std.math.floorPowerOfTwo(usize, b - a) + 1;

Image

Expected Behavior

Usually sorting functions have used something like floor(log2(n)) + 1, ceil(log2(n + 1)) or 2 * floor(log2(n)) as their limits before switching to heap sort or some other constant time algorithm. This is not a huge issue since even these lower limits are very rarely reached with real world data. Usually you have to put some "adversarial" data to make even relatively simple quick sort algorithms to go quadratic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions