Class DirectSelection

java.lang.Object
topics.sorting.selection.DirectSelection
All Implemented Interfaces:
SortingAlgorithm

public class DirectSelection extends Object implements SortingAlgorithm

Direct Selection Sort

An educational sorting implementation that divides the input list into two parts: a sorted sublist built up from left to right, and a sublist of the remaining unsorted items. The algorithm proceeds by finding the smallest element in the unsorted sublist and swapping it with the leftmost unsorted element.

Complexity Analysis

  • Time Complexity: O(N²) strictly in all cases (Best, Average, Worst). It must always scan the entire remaining array to guarantee it has found the absolute minimum.
  • Space Complexity: O(1) - Sorts entirely in-place.
  • Stability: No - Swapping non-adjacent elements across the array can change the relative order of equal elements.
Author:
vicegd
See Also:
  • invalid reference
    topics.sorting.SortingAlgorithm
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    sort(int[] elements)
    Sorts the elements in-place silently.
    void
    sort(int[] elements, boolean trace)
    Sorts the elements in-place, optionally emitting step-by-step traces to visualize the algorithmic progression.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DirectSelection

      public DirectSelection()
  • Method Details

    • sort

      public void sort(int[] elements)
      Description copied from interface: SortingAlgorithm
      Sorts the elements in-place silently.
      Specified by:
      sort in interface SortingAlgorithm
      Parameters:
      elements - The array of integers to be sorted.
    • sort

      public void sort(int[] elements, boolean trace)
      Description copied from interface: SortingAlgorithm
      Sorts the elements in-place, optionally emitting step-by-step traces to visualize the algorithmic progression.
      Specified by:
      sort in interface SortingAlgorithm
      Parameters:
      elements - The array of integers to be sorted.
      trace - If true, logs the internal state during execution.