Skip to content

Commit 6f24f5e

Browse files
committed
Try making variable names self descriptive
1 parent 9a952bd commit 6f24f5e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

algorithms/Searching/jump_search.m

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
function found_at = jump_search(arr, value)
1+
function found_at = jump_search(input_array, search_key)
22
% Contributed by - Harshit Pant, harshitpant83@gmail.com
33

4-
% arr - The input array, should be sorted in ascending order.
5-
% 'arr' can contain -ve numbers as well as non-integers.
6-
% value - The value to be searched in the array.
7-
% found_at - The index at which 'value' is found in 'arr'.
8-
% -1 is returned if 'value' is not found in 'arr'.
4+
% input_array - The input array, should be sorted in ascending order.
5+
% 'input_array' can contain -ve numbers as well as non-integers.
6+
% search_key - The value to be searched in the 'input_array'.
7+
% found_at - The index at which 'search_key' is found in 'input_array'.
8+
% -1 is returned if 'search_key' is not found in 'input_array'.
99

10-
n = length(arr);
10+
array_length = length(input_array);
1111
found_at = -1;
1212

13-
% 'm' holds the block size
14-
m = sqrt(n);
15-
m = round(m);
13+
block_size = sqrt(array_length);
14+
block_size = round(block_size);
15+
1616
low = 1;
17-
high = 1 + m;
17+
high = 1 + block_size;
1818

19-
while arr(min(high, n)) < value
19+
while input_array(min(high, array_length)) < search_key
2020
low = high;
21-
high = high + m;
22-
if low >= n
21+
high = high + block_size;
22+
if low >= array_length
2323
return;
2424
endif;
2525
endwhile;
2626

27-
while arr(low) < value
27+
while input_array(low) < search_key
2828
low = low + 1;
29-
if low > min(high, n)
29+
if low > min(high, array_length)
3030
return;
3131
endif;
3232
endwhile;
3333

34-
if arr(low) == value
34+
if input_array(low) == search_key
3535
found_at = low;
3636
endif;
3737

0 commit comments

Comments
 (0)