Skip to content

Add TagSort (Index Sort) algorithm with tests#7366

Open
saidyanak wants to merge 1 commit intoTheAlgorithms:masterfrom
saidyanak:add-tag-sort
Open

Add TagSort (Index Sort) algorithm with tests#7366
saidyanak wants to merge 1 commit intoTheAlgorithms:masterfrom
saidyanak:add-tag-sort

Conversation

@saidyanak
Copy link
Copy Markdown

Description

Adds Tag Sort (also known as Index Sort or Dictionary Sort) to the sorts package.

Algorithm Overview

Tag Sort creates an array of indices (tags) and sorts those indices based on corresponding values in the original array. This is useful when the original positions of elements need to be preserved after sorting.

Complexity

  • Time Complexity: O(n log n)
  • Space Complexity: O(n)

Features

  • Implements SortAlgorithm interface
  • Additional getSortedTags() method to retrieve sorted indices without modifying the original array
  • Full test coverage (empty, single element, duplicates, negatives, strings, already sorted, reverse sorted)

References

Tag Sort (Index Sort) creates an array of sorted indices without modifying
the original array. Useful when original positions need to be preserved.
Time complexity: O(n log n), Space complexity: O(n).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant