public class SingleMovedElementLocator
extends java.lang.Object
Prerequisites for correct operation:
Constructor and Description |
---|
SingleMovedElementLocator() |
Modifier and Type | Method and Description |
---|---|
static int |
findMovedElement(int[] oldArray,
int[] newArray,
int movedValueKnown,
int originalIndexKnown)
Finds the single moved element between two arrays.
|
public static int findMovedElement(int[] oldArray, int[] newArray, int movedValueKnown, int originalIndexKnown)
Prerequisites:
This algorithm leverages binary search to find the boundaries of the changed section from both ends, achieving an O(log N) time complexity for finding these boundaries, and then O(1) to deduce the moved element's details. The provided "originalIndexKnown" is used for immediate validation and to enable the O(log N) binary searches for the mismatch boundaries.
oldArray
- The original array of integers.newArray
- The modified array of integers.movedValueKnown
- The known value of the element that moved.originalIndexKnown
- The known original index of the moved value in the old array.java.lang.IllegalArgumentException
- If the input prerequisites are violated.Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.