Skip to content

BucketSort #750

@YudhveerCAIN

Description

@YudhveerCAIN
  1. Dynamic Array Declaration: The program uses float arr[n], but this isn’t valid in standard C++ since arrays can't be dynamically sized this way. You should use std::vector instead to handle the dynamic size.
  2. Bucket Index Calculation: The code calculates the bucket index with int(size * array[i]), assuming all values are between 0 and 1. If any values fall outside this range, it could lead to out-of-bounds errors. You need to ensure the input values are within the expected range or scale them appropriately.
  3. Inefficient Element Removal: The program uses bucket[i].erase(bucket[i].begin()) repeatedly in a loop. This is inefficient because it shifts elements each time. A better approach is to iterate through the bucket and directly reassign values.
  4. Lack of Input Validation: The program doesn’t check if the user inputs valid values between 0 and 1. Adding validation helps prevent errors if someone enters an out-of-range number.

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