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

  • Home
  • SEARCH
  • 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 6874495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:12:09+00:00 2026-05-27T04:12:09+00:00

how can we reverse a subarray ( say from i-th index to j-th index

  • 0

how can we reverse a subarray ( say from i-th index to j-th index ) of an array ( or any other data structure , like linked-list ( not doubly )), in less than O(n) time ? the O(n) time consumption is trivial.( I want to do this reversion many times on the array , like starting from the beginning and reversing it for n times (each time , going forward for one index and then reversing it again), so there should be a way ,which its amortized analysis would give us a time consumption less than O(n) , any idea ?
thanks In advance 🙂

  • 1 1 Answer
  • 0 Views
  • 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-27T04:12:09+00:00Added an answer on May 27, 2026 at 4:12 am

    I think you want to solve this with a wrong approach. I guess you want to improve the algorithm as a whole, and not the O(n) reversing stuff. Because that’s not possible. You always have O(n) if you have to consider each of the n elements.

    As I said, what you can do is improve the O(n^2) algorithm. You can solve that in O(n):
    Let’s say we have this list:

    a b c d e
    

    You then modify this list using your algorithm:

    e d c b a
    e a b c d
    

    and so on.. in the end you have this:

    e a d b c
    

    You can get this list if you have two pointers coming from both ends of the array and alternate between the pointers (increment/decrement/get value). Which gives you O(n) for the whole procedure.

    More detailed explanation of this algorithm:

    Using the previous list, we want the elements in the follow order:

    a b c d e
    2 4 5 3 1
    

    So you create two pointers. One pointing at the beginning of the list, the other one at the end:

    a b c d e
    ^       ^
    p1      p2
    

    Then the algorithms works as follows:

    1. Take the value of p2
    2. Take the value of p1
    3. Move the pointer p2 one index back
    4. Move the pointer p1 one index further
    5. If they point to the same location, take the value of p1 and stop.
       or if p1 has passed p2 then stop.
       or else go to 1.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to reverse an array (or any other data structure) but because this
Can a compiler be written, from which you can not reverse engineer the grammar
Are there any command line scripts and/or online tools that can reverse the effects
As I understand it I can use reverse P/Invoke to call C# from C++.
can you say me if there are good tools for reverse-engineering my C# applications.
One method which I can think of is to reverse the list and then
I know that we can reverse engineers sites definitions and other sharepoint moss entities
How can I reverse an order with jquery? I tried with the suggestion like
I have the following code,how can i reverse the messages Array ,see bellow: #import
Once I've mapped my domain in NHibernate, how can I reverse lookup those mappings

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.