Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:29:12+00:00 2026-05-13T05:29:12+00:00

Given a Sorted Array which can be rotated find an Element in it in

  • 0

Given a Sorted Array which can be rotated find an Element in it in minimum Time Complexity.

eg : Array contents can be [8, 1, 2, 3, 4, 5]. Assume you search 8 in it.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:29:12+00:00Added an answer on May 13, 2026 at 5:29 am

    The solution still works out to a binary search in the sense that you’ll need to partition the array into two parts to be examined.

    In a sorted array, you just look at each part and determine whether the element lives in the first part (let’s call this A) or the second part (B). Since, by the definition of a sorted array, partitions A and B will be sorted, this requires no more than some simple comparisons of the partition bounds and your search key.

    In a rotated sorted array, only one of A and B can be guaranteed to be sorted. If the element lies within a part which is sorted, then the solution is simple: just perform the search as if you were doing a normal binary search. If, however, you must search an unsorted part, then just recursively call your search function on the non-sorted part.

    This ends up giving on a time complexity of O(lg n).

    (Realistically, I would think that such a data structure would have a index accompanying it to indicate how many positions the array has been rotated.)

    Edit: A search on Google takes me to this somewhat dated (but correct) topic on CodeGuru discussing the same problem. To add to my answer, I will copy some pseudocode that was given there so that it appears here with my solution (the thinking follows the same lines):

    Search(set):
        if size of set is 1 and set[0] == item 
            return info on set[0]
        divide the set into parts A and B
        if A is sorted and the item is in the A's range
            return Search(A)
        if B is sorted and the item is in the B's range
            return Search(B)
        if A is not sorted
            return Search(A)
        if B is not sorted
            return Search(B)
        return "not found"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We want to search for a given element in a circular sorted array in
Given a sorted array of integers, how can we find a pair of integers
Given two sorted arrays, A and B, find i,j for which |A[i] - B[j]|
Question: Given a sorted array A find all possible difference of elements from A.
Given two sorted arrays: A and B . The size of array A is
Given a package, how can I automatically find all its sub-packages?
Possible Duplicates: Given a 2d array sorted in increasing order from left to right
Problem: Given a matrix in which each row and each column is sorted, write
You are given two sorted integer arrays, which have some common integers. Any common
Possible Duplicate: Given a 2d array sorted in increasing order from left to right

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.