Jump Search - 02 - MATLAB Cody - MATLAB Central

Problem 56070. Jump Search - 02

Difficulty:Rate
Find the number of leaps you need to take to find the 'first occurrence' of an element in an array using the jump search algorithm.
For example,
a=[ 2,5,6,9,12,15,15,16,17,19,31]
To find 16 with a jump step of 3, you follow, 2 -> 9 -> 15 -> 19 -> 17 -> 16
So, total number of jumps = 5
n.b. to go forward, you take n-step jump; to go backwards, you jump only one step back.
  • In this problem, you will have repetition of numbers. you need to find the index of the first occurence.
  • The array is always sorted. But you need to look out and go backward even after finding the element to ensure it is the first occurence.
  • If the jump step is larger than the array size, u directly go to the last element of the array

Solution Stats

18.18% Correct | 81.82% Incorrect
Last Solution submitted on Aug 03, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers4

Suggested Problems

More from this Author165

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!