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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:05:56+00:00 2026-05-29T11:05:56+00:00

Given two sequences of identifier, how to find the smallest operation sequence that will

  • 0

Given two sequences of identifier, how to find the smallest operation sequence that will transform the first sequence of identifier to the second one.

Operation can be :

  • Insert an identifier at a given position
  • Remove the identifier from a given position
  • Move an identifier from a position to another

Note: identifiers are unique and can’t appear twice in a sequence

Example:

Sequence1 [1, 2, 3, 4, 5]
Sequence2 [5, 1, 2, 9, 3, 7]

Result (index are 0 based) :
- Remove at 3
- Move from 3 to 0
- Insert '9' at 3
- Insert '7' at 5

Thanks !

  • 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-29T11:05:57+00:00Added an answer on May 29, 2026 at 11:05 am

    Start by finding the longest common subsequence. This will identify the elements that will not move:

    [(1), (2), (3), 4, 5]
    

    Elements of the LCS are enclosed in parentheses.

    Go through both sequences from index 0, recording the operations required to make the sequences identical. If the current item of the first sequence is not part of the LCS, remove it, and mark the place where it has been before, in case you need to insert it at a later time. If the current element is part of the LCS, insert the element from the second sequence in front of it. This could be either a simple insertion, or a move. If the item that you are inserting is in the original list, make it a move; otherwise, make it an insert.

    Here is a demo using your example. Curly braces show the current element

    [{(1)}, (2), (3), 4, 5] vs [{5}, 1, 2, 9, 3, 7]
    

    1 is a member of LCS, so we must insert 5. 5 is in the original sequence, so we record a move: MOVE 4 to 0

    [5, {(1)}, (2), (3), 4] vs [5, {1}, 2, 9, 3, 7]
    

    Items are the same, so we move on to the next one:

    [5, (1), {(2)}, (3), 4] vs [5, 1, {2}, 9, 3, 7]
    

    Again the numbers are the same – move to the next one:

    [5, (1), (2), {(3)}, 4] vs [5, 1, 2, {9}, 3, 7]
    

    3 is a member of LCS, so we must insert 9. The original element does not have 9, so it’s a simple insertion: INSERT 9 at 3

    [5, (1), (2), 9, {(3)}, 4] vs [5, 1, 2, 9, {3}, 7]
    

    Yet again the numbers are the same – move to the next one:

    [5, (1), (2), 9, (3), {4}] vs [5, 1, 2, 9, 3, {7}]
    

    ‘4’ is not a member of LCS, so it gets deleted: DEL at 5

    [5, (1), (2), 9, (3)] vs [5, 1, 2, 9, 3, {7}]
    

    We reached the end of the first sequence – we simply add the remaining items of the second sequence to the first one, paying attention to the list of prior deletions. For example, if 7 had been removed earlier, we would transform that deletion into a move at this time. But since the original list did not have 7, we record our final operation: INS 7 at 5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for two given sequences say A and B how can one find the length
I'm looking for an algorithm that given two permutations of a sequence (e.g. [2,
Given two colors and n steps, how can one calculate n colors including the
I'm attempting to write a basic dna sequencer. In that, given two sequences of
Given two sets A and B, what is the common algorithm used to find
Given two tables, one for workers and one for tasks completed by workers, CREATE
An interview question: Given two non-ordered integer sequences a and b , their size
I have an interesting programming puzzle for you: You will be given two things:
given two sequences, how to get all the elements belonging to both the sequences
Let's say I have two sequences returning integers 1 to 5. The first returns

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.