Class LCSState

java.lang.Object
org.ddolib.examples.lcs.LCSState

public class LCSState extends Object
Represents the state of a node in the Longest Common Subsequence (LCS) problem.

In this problem, the state is defined by the current position in each of the strings being compared. Each position indicates how many characters of that string have been processed.

This state is used by search and optimization algorithms to track progress along the strings. It is immutable in the sense that new states are created rather than modifying existing ones.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks equality between this state and another object.
    int
    Returns a hash code for this state, based on the positions in all strings.
    Returns a string representation of the state.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • hashCode

      public int hashCode()
      Returns a hash code for this state, based on the positions in all strings.
      Overrides:
      hashCode in class Object
      Returns:
      hash code of the state.
    • equals

      public boolean equals(Object obj)
      Checks equality between this state and another object. Two states are equal if their position arrays are identical.
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare with.
      Returns:
      true if the other object is an LCSState with the same positions; false otherwise.
    • toString

      public String toString()
      Returns a string representation of the state.

      The positions in each string are shown as an array.

      Overrides:
      toString in class Object
      Returns:
      String representation of the state.