Searching is one of the most fundamental tasks in computer programming. Whenever we work with data — whether it’s numbers, names, or records — we often need to find a specific element efficiently. While Linear Search is simple, it can be slow for large datasets. Jump Search is an interesting alternative that is faster than linear search for sorted arrays, and easier to implement than Binary Search in some cases.

with hands-on learning.
get the skills and confidence to land your next move.
Jump Search works by dividing the array into blocks and “jumping” ahead by a fixed step, then performing a linear search within the block where the element may exist. This reduces the number of comparisons significantly, making it suitable for large datasets with sequential access. For beginners learning C programming, implementing Jump Search is a great way to learn how to combine mathematical logic with simple loops or recursion to make searches more efficient.
Program 1: Iterative Jump Search
The first program demonstrates Jump Search using a simple iterative approach, which is easy to understand for beginners.
#include <stdio.h>
#include <math.h>
int jumpSearch(int arr[], int n, int key) {
int step = sqrt(n); // Optimal step size
int prev = 0;
while (arr[(step < n ? step : n) - 1] < key) {
prev = step;
step += sqrt(n);
if (prev >= n)
return -1; // Element not found
}
for (int i = prev; i < (step < n ? step : n); i++) {
if (arr[i] == key)
return i;
}
return -1; // Element not found
}
int main() {
int arr[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
int n = sizeof(arr) / sizeof(arr[0]);
int key;
printf("Enter the element to search: ");
scanf("%d", &key);
int index = jumpSearch(arr, n, key);
if (index != -1)
printf("Element %d found at index %d\n", key, index);
else
printf("Element %d not found in the array\n", key);
return 0;
}
In this program, we first calculate the optimal step size as the square root of the array size. Then we jump through blocks until the block containing the key is identified. A linear search is performed inside the block to find the key. This approach is easy for beginners to understand because it separates jumping and linear search into clear steps.
Program 2: Recursive Jump Search
Jump Search can also be implemented recursively, which is a good way to practice recursion and understand how algorithms can call themselves to solve a problem.
#include <stdio.h>
#include <math.h>
int jumpSearchRecursive(int arr[], int n, int key, int prev, int step) {
if (prev >= n)
return -1; // Element not found
int nextStep = (step < n ? step : n);
if (key <= arr[nextStep - 1]) { // Key may be in this block
for (int i = prev; i < nextStep; i++) {
if (arr[i] == key)
return i;
}
return -1;
}
return jumpSearchRecursive(arr, n, key, nextStep, step + sqrt(n));
}
int main() {
int arr[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
int n = sizeof(arr) / sizeof(arr[0]);
int key;
printf("Enter the element to search: ");
scanf("%d", &key);
int index = jumpSearchRecursive(arr, n, key, 0, sqrt(n));
if (index != -1)
printf("Element %d found at index %d\n", key, index);
else
printf("Element %d not found in the array\n", key);
return 0;
}
Here, the recursive function works similarly to the iterative version. Instead of using loops to jump through blocks, the function calls itself with the next block until it either finds the key or reaches the end of the array. This approach helps beginners understand how recursion can replace loops in certain scenarios.
Program 3: Jump Search with Floating-Point Numbers
Jump Search also works with floating-point numbers, as long as the array is sorted. This demonstrates the flexibility of the algorithm.
#include <stdio.h>
#include <math.h>
int jumpSearchFloat(float arr[], int n, float key) {
int step = sqrt(n);
int prev = 0;
while (prev < n && arr[(step < n ? step : n) - 1] < key) {
prev = step;
step += sqrt(n);
if (prev >= n)
return -1;
}
for (int i = prev; i < (step < n ? step : n); i++) {
if (arr[i] == key)
return i;
}
return -1;
}
int main() {
float arr[] = {1.2, 2.5, 3.8, 4.0, 5.1, 6.6, 7.9};
int n = sizeof(arr) / sizeof(arr[0]);
float key;
printf("Enter the element to search: ");
scanf("%f", &key);
int index = jumpSearchFloat(arr, n, key);
if (index != -1)
printf("Element %.2f found at index %d\n", key, index);
else
printf("Element %.2f not found in the array\n", key);
return 0;
}
This floating-point version works just like the integer version. The step calculation and block search logic remain unchanged, showing that Jump Search can handle different numeric types without modification.
Frequently Asked Questions (FAQ)
Here are some common questions about Jump Search in C programming.
When should I use Jump Search instead of Binary Search?
Jump Search is useful when data is sequentially accessible and linear traversal is cheap. Binary Search is usually better for random access arrays, but Jump Search reduces the number of comparisons when block jumps are efficient.
What is the time complexity of Jump Search?
The worst-case time complexity is O(√n), which happens when the key is in the last block or not present. It usually performs fewer comparisons than linear search.
Does Jump Search require sorted arrays?
Yes, the array must be sorted because the algorithm relies on ordering to jump correctly.
Can Jump Search handle floating-point numbers?
Yes, it works with integers, floating-point numbers, and any numeric data type, as long as the array is sorted.
Is recursion recommended for Jump Search?
Recursion works fine, but iterative Jump Search is usually more practical because recursion adds function call overhead. Recursion is useful for learning purposes and understanding algorithmic thinking.
Conclusion
Jump Search is a simple yet efficient searching algorithm for sorted arrays. By jumping ahead in blocks and then performing a linear search within a block, it reduces the total number of comparisons and speeds up the search process.
The examples above — iterative, recursive, and floating-point versions — show how Jump Search can be applied in different scenarios. Beginners can benefit by experimenting with arrays of different sizes and data types to see how the algorithm performs. By practicing both iterative and recursive approaches, you’ll gain a solid understanding of algorithm design, recursion, and efficient searching in C programming.