0
[Challenge]ARRAY BASED ALGORITHM
Given a rotated sorted array.Search an element in the array. ROTATED SORTED ARRAY:some starting elements of a sorted array placed at the end of the array by shifting the elements towards left. EXAMPLE: SORTED ARRAY:1 2 7 10 15 35 A ROTATED SORTED ARRAY:10 15 35 1 2 7 Search an element(take from user) in the Rotated Sorted Array and print the index of the element if found else print -1. DO IN AS OPTIMIZED WAY AS POSSIBLE. ALL Languages welcomed.Focus on EFFICIENCY (possible in O(log N)).... BEST OF LUCK!
6 Answers
+ 1
try to modify normal binary search
whenever u need to search in an array and required time complexity is logN....bring in mind to modify binary search
Best of luck
+ 3
But being rotated, the array is no longer sorted is it? so the task is to sort the array, rotate it (how many times?) then search the array for a certain item?
+ 3
Hi, sorry for the delay. Well, I'm not so confident about it, but I may try it maybe tomorrow, somehow I get a feeling that this is more than just a regular array walk to find a certain value, is there any more to it that you can tell me?
+ 3
@Abdul Sattar thank you, I actually kinda figured this was more than a simple array walk, actually algorithm is my weakness point, so the goal is to minimize time spent for searching, by finding best scenario, if I may say so...Anyways, if this is a challenge, I suggest you change the question title, maybe [Challenge] Array based algorithm. I suppose people didn't notice this was a challenge, that's why its rather quiet. Just random suggestion though
+ 1
you need not rotate it
the input will be the one time rotated array.In that array u need to search an entity.Use the property that this array was made from the sorted array...this input array is no longer sorted
+ 1
thanks @Ipang