i'm trying to write an algorithm to reconstruct the original array from the sorted one. considering input value is a string of 1s and 2s which 1 means in merging part of merge sort, element from left subarray is chosen and 2 means element from right subarray is chosen. how can i do it? specially i have problem on that part that merge sort appends what ever is left from a subarray to final list. for example: it's given 12212 as input string on an array of numbers [1,2,3,4]. it means that there is a permutation of numbers 1 to 4 that if you give it to merge sort, it will give you 12212. that permutation is 2 4 3 1 .
Restore the original array after merge Sort based on it's steps
71 Views Asked by vhd At
1
There are 1 best solutions below
Related Questions in ALGORITHM
- MCNP 6 - Doubts about cells
- Given partially sorted array of type x<y => first apperance of x comes before first of y, sort in average O(n)
- What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- Dots and Boxes with apha-beta pruning
- What is the average and worst-case time complexity of my string searching algorithm?
- Building a School Schedule Generator
- TC problem 5-2:how to calculate the probability of the indicator random variable?
- LCA of a binary tree implemented in Python
- Identify the checksum algorithm
- Algorithm for finding a subset of nodes in a weighted connected graph such that the distance between any pair nodes are under a postive number?
- Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
- Algorithm to find neighbours of point by distance with no repeats
- Asking code suggestions about data structure and algorithm
- Heap sort with multithreading
Related Questions in RECURSION
- What is the problem in my "sumAtBis" code?
- Leetcode 1255-recursion and backtracking
- Unexpected Recursive Call
- Clang possibly skipping line(s) of code while compiling
- Return an arraylist without passing an argument
- Solving Maze using Backtracking C++
- I can't get the specific node of BST using recursion . i.e. every stack it erase
- Python Quadtree won't insert values
- Top View Of Binary Tree Depth First Search Using TreeMap
- Select/filter tree structure in postgres
- Python global variables in recursion get different result
- Trying to recursively find the area of a polygon
- *Dynamically* decorate a recursive function in Python
- What structure can be made to avoid having to use RefCell?
- Why is the output of the two given cout statements different in the given cpp code
Related Questions in MERGESORT
- Doubly Linked List, MergeSort, getting undefined and unreliable results
- Issue with Merge Sort - Implementation in C++
- Sorting algorithm that is stable in sorting ten million objects
- Problems with the pseudocode in CLRS
- merge sort list java
- Manipulating Merge-Sort
- Ordering java linked list alphabetically (dictionary-like)
- How to implement mergeSort?
- MergeSort not giving correct output
- This merge sort program is not giving the correct answer
- Loop to read array input unexpected behavior?
- Dynamic programming: design an algorithm that is in O(n log n) time
- Merge Sort java implementation error
- Lexically sorting a linked-list of Strings
- Merge Sorting in Objective C
Related Questions in DIVIDE-AND-CONQUER
- Google interview question - check if all subarrays of an array have at least one unique element
- Find max product using divide and conqure in O(n) time
- How to compute the product of a n x n size Toeplitz matrix and a n-length vector in O(nlogn) time using FFT algorithm
- Proof of correctness for algorithm to find the median of the union of two sorted arrays
- Is there an equivalent to divide and conquer when trying to identify multiple items?
- Divide and conquer algorithm problem applied to an n x n-matrix
- How can I adjust my code to use binary search to guess the number I am thinking in my head
- XSLT recursion crashes after 1000 calls - how to transform it to DVC style?
- labeling graph edges
- Restore the original array after merge Sort based on it's steps
- binary search left and right index to find median of two sorted arrays
- Divide and Conquer max profit algorithm
- How to add `n log n` stones to a grid to form a beautiful arrangement using divide-and-conquer? - algorithm idea
- How will the stack be formed by Recursion in the MergeSort function?
- How can I find all the matches of two sorted arrays in O(n) with limitations on number of comparisons?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
When you're recording the steps for a merge, you'll either get enough 1s to consume the whole left array OR enough 2s to consume the whole right array. For a 2+2 merge, these are the possibilities:
This set of strings is always prefix-free, meaning that if you know where the sequence for a merge starts, then you can tell where it ends.
Unfortunately, it's not suffix-free. It includes both
22and122, for example. That means that you can't tell where it starts by knowing where it ends. If your string ends in...1122, for example, and you know that it ends in a 2+2 merge, it could be either a22merge or a122merge. There's no way to tell the difference without tracing all the merges from the start.That makes it a little tricky to write your un-merge-sort function, because you have to start at the beginning of the step record string.
In fact, the easiest way to do this un-merge is: