It is the jump search algorithm 2.3.
Any hints or anything will be of help thank you.


Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Feb 4, 2015, 6:48 PM
The only awkward point is that Lists are zero based in C# whereas the algorithm seems to be assuming that they're 1-based. I've therefore reduced the index by 1 to allow for this:
Philip HarrisPosted Feb 5, 2015, 2:28 PM
Many thanks Vulpes.... YOU ROCK!
VulpesPosted Feb 5, 2015, 12:29 PM
So, I've simply translated the pseudo-code into C# code. As previously mentioned, the only awkward point is that List
No definition was given for the LINEAR.SEARCH method so I simply assumed that we're supposed to iterate through the list, returning the 1-based index if X is found or 0 otherwise.
The part between the {..} is simply a comment but I used the information in that to check the arguments are acceptable and consistent with each other.
Thinking about it some more, perhaps we ought to add another line to make sure 'upper' isn't more than the number of elements in the list:
if (upper > list.Count) throw new ArgumentException("upper can't be more than the number of elements in the list");
Philip HarrisPosted Feb 4, 2015, 7:41 PM