Jump Search
Jump search is an algorithm for searching for a target value in a sorted array. It's similar to linear search in that it looks at every nth element, but it skips over some elements in a way that makes it more efficient.
Example in TypeScript
This function takes two arguments: an array and a target value. It uses a while loop to jump over some elements in the array by taking sqrt(n)
steps at a time. It starts with the first element and compares it with the target value. If the element is less than the target value, it moves to the next step. It keeps moving to the next step until it finds an element that is greater than or equal to the target value. Then it uses another while loop to check from the previous step until it finds the target value or reaches the end of the array. If it finds the target value, it returns the index. If it doesn't find the target value, it returns null
.
Usage
Last updated