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!

9th Dec 2017, 3:05 PM
Abdul Sattar Mapara
6 ответов
+ 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
9th Dec 2017, 6:14 PM
Abdul Sattar Mapara
+ 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?
9th Dec 2017, 3:29 PM
Ipang
+ 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?
9th Dec 2017, 6:13 PM
Ipang
+ 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
9th Dec 2017, 6:37 PM
Ipang
+ 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
9th Dec 2017, 3:32 PM
Abdul Sattar Mapara
+ 1
thanks @Ipang
9th Dec 2017, 6:39 PM
Abdul Sattar Mapara