Skip to content

Calculation of the number of elements in bucket sorting #11

@PachVerb

Description

@PachVerb

Hello, I am learning bucket sorting. I don't understand the logic of a piece of code very well; or it is about the principle of calculating the number of elements in the bucket sorting bucket. code show as below:

....
const buketCount: number =
    Math.floor((maxValue - minxValue) / bucketsSize) + 1;   // --> Why is it necessary to add 1 when calculating the number of elements in the bucket?  I do not really understand.
  const bukets: number[][] = [];
  for (let i: number = 0; i < buketCount; i++) {
    bukets[i] = [];
  }
....

If you see, I hope to help me explain, thank you very much

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions