15 Oct 2013

Find in a Rotated Sorted Array

Problem Statement: 
         Find a number in a sorted rotated array.

Solution:
        We need to find a number in a sorted rotataed array with complexity O (log N).
Here we will utilize the concept of binary search , which would modify in such a way that we achieve our target.

In case of a normal binary search only 2 cases exist, but here with sorted rotated array 4 cases comes up.

Depending on which part of the array is sorted we enter into that condition and see if the numeber is in that sorted array or not if not then it is definetly in the secord part, we continue this process until start is <= end.


Considering the above cases we can write a iterative Binary search search to find the element in a sorted rotated array.
Time Complexity :  O( Log N)
Space Complexity : O(1)

Code :




Please post comments and suggestions for further optimizing the code.

Happy Coding :)

12 comments:

  1. At the delicatessen a serve over is known to display every one of the cakes as well as other sweets and sundries which can be on offer.
    Best custom display - The fabric could be molded to adjust
    to into any design or model of any display, rendering it the ideal choice in making a customized display.
    This includes, brochures, flyers, business cards, order forms,
    price sheets and press kits.

    Also visit my page :: expo displays company

    ReplyDelete
  2. Some birds, for example will engage in singing displays that mirror the motions from the grass
    display just like the Cutthroat finch. But, calling the target audience, instilling interest most notable,
    was difficult because there was no definitive strategy
    for promoting the emblem or business via brochures. Visit your customers' Facebook
    pages and personally invite them to stop by and visit your trade exhibition displays and banner stands.


    Also visit my website; portable pop up display for sale

    ReplyDelete
  3. At the delicatessen a serve over may be used to display each of the cakes along with other
    sweets and sundries which might be on offer. To my mind there is nothing simpler or spontaneous than arranging fresh flowers inside a vase.
    In short, it's crucial for organizations to make certain they deliver enough
    exciting details to pique the crowd's interest without crossing the fishing line
    into the dreaded mass confusion territory.

    My web page ... inexpensive trade show booth printing

    ReplyDelete
  4. We're a bunch of volunteers and opening a brand new scheme in our community.
    Your web site offered us with useful info to work on. You've done an impressive process and our entire neighborhood will probably be
    grateful to you.

    my blog - adsense successful

    ReplyDelete
  5. Very soon this web site will be famous amid all blog users, due to it's good articles

    My website ... best business jets

    ReplyDelete
  6. Have yyou ever considerdd creating ann ebook or guest authoring onn other websites?

    I have a blog centered on the same subjects you discuss and would really like to have you share some stories/information. I know my audience would enjoy your work.
    If yoou are even remotely interested, feel free to send me
    aan e-mail.

    My blog Las Vegas Microwave Parts

    ReplyDelete
  7. This information is worth everyone's attention. How
    can I find out more?

    Feel free to visit my homepage Las Vegas Microwave Parts

    ReplyDelete
  8. Hi there, You've done a great job. I will definitely digg
    it and personally suggest to my friends. I'm confident
    they'll be benefited from this web site.

    Here is my web-site; best possible search

    ReplyDelete
  9. Thank you for any other magnificent article.
    Where else may just anybody get that kind of information in such a perfect method of writing?
    I have a presentation next week, and I'm on the look
    for such info.

    my web blog; legal aid medical negligence

    ReplyDelete
  10. I'm not sure where you're getting your info, but good
    topic. I needs to spend some time learning more or understanding more.
    Thanks for magnificent info I was looking for this information for my
    mission.

    Also visit my web site - seo positioning services

    ReplyDelete
  11. This text is invaluable. How can I find out more?


    Look into my weblog clinical negligence firms london

    ReplyDelete
  12. Its such as you learn my mind! You appear to understand so much about this, like you wrote the ebook
    in it or something. I believe that you just could do with a few percent to power the message home a bit, however instead of that, this is wonderful blog.

    A great read. I'll definitely be back.

    Stop by my blog post - social media playbook

    ReplyDelete