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 8627345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:15:24+00:00 2026-06-12T08:15:24+00:00

I need a sorting algorithm which operates on a single, pre-populated array, and which

  • 0

I need a sorting algorithm which operates on a single, pre-populated array, and which is limited to perform only one type of write operation:

O=Move an item X to index Y. The elements on subsequent positions are shifted 1 position.

The algorithm must be optimized for the least possible number of operations O. Read operations are infinitely cheaper than write operations. Temporary helper lists are also cheap.

Edit: It might be more correct to call it a linked list, because of its behaviour, although the implementation is hidden for me.

Background:

The thing is I’m working against a Google API which only allows me to perform this operation on their lists. The operation is a web service call. I want to minimize the number of calls. You can assume the sorting program (the client) has a copy of the list in memory before starting, so there is no need to perform read operations against the service – only write. You can of course also do any amount of temporary list actions locally before performing the service calls, including duplicating the list or using existing .NET sort functions.

How do I proceed here? Is there a known algorithm I can use here?

Failed attempt:

I have already implemented a dumb algorithm, but it is not optimal for all cases. It works well when the list is like this:

List A = [2,3,4,5,6,7,8,9,1]

It goes like this:

  1. Is list sorted? No
  2. Find element that belongs at position 0: “1”
  3. Move Element “1” to position 0
  4. (New list state A1: [1,2,3,4,5,6,7,8,9])
  5. Is list sorted? Yes. End

…But when the list is like this, I get into trouble:

List B = [9,1,2,3,4,5,6,7,8]

  1. Is list sorted? No
  2. Find element that belongs at position 0: “1”
  3. Move Element “1” to position 0
  4. (New list state B1: [1,9,2,3,4,5,6,7,8])
  5. Is list sorted? No
  6. Find element that belongs at position 1: “2”
  7. Move Element “2” to position 1
  8. (New list state B2: [1,2,9,3,4,5,6,7,8])
  9. …you can see where I’m going here…
  • 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-06-12T08:15:26+00:00Added an answer on June 12, 2026 at 8:15 am

    Compute the longest increasing subsequence of the array. Perform a write operation for each element that is not present in the sequence.

    EDIT: Adding an example

    Let the numbers in the input array be 1 3 2 7 4 8 6 5 9. A longest increasing sequence is 1 2 4 6 9. When computing this sequence store the indexes of the elements that occur in the sequence. Then it is straightforward to travel through the original array and find the elements not present in the sequence. In this case they are 3 7 8 5. For each of these elements perform a write operation that places them in the appropriate position. So the sequence of modifications of the array would be:

    1 2 3 7 4 8 6 5 9 (after writing 3 to appropriate position)
    1 2 3 4 8 6 7 5 9 (after writing 7 to appropriate position)
    1 2 3 4 6 7 5 8 9 (after writing 8 to appropriate position)
    1 2 3 4 5 6 7 8 9 (after writing 5 to appropriate position)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of data on which I need to perform a topological
I need some help with my CS homework. I need to write a sorting
I need to use a sorting algorithm in a list that has as much
I need some advice when it comes to solving a sorting algorithm. This particular
I have a strong use-case to define my own sorting algorithm, which is faster
I need to write a sorting program in C and it would be nice
I have a huge ammount of photos that need sorting through. I need to
I need to implement a function for moving records up and down (sorting) and
I have a problem with sorting... I need to sort NSArray containing NSDictionaries .
What is the need of Collection framework in Java since all the data operations(sorting/adding/deleting)

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.