The complexity of sorting a list having one free cell









up vote
1
down vote

favorite












Making a standard bureocracy (using Word tables), I arrived to the following




Problem. Assume that we have a table with $n+1$ rows. The first $n$ rows are filled with names of students (and say topics of their Master works) and the last row is empty. It is required to sort this table in alphabetic order (of student names) using the operations of cut and copy-past over rows. What is the complexity of this problem (i.e., the smallest number of cut-copy-past operations in the worst case)?




I suspect that this problem has been considered (say in Computer Sciences) but I can not find a proper reference.



Remark. A simple argument shows that this worst case complexity is between $n$ and $frac32n$ (more precisely, $lfloorfrac32nrfloor+1$).




Can we always do better than $frac32n$?











share|cite|improve this question



















  • 1




    To clarify: A move consists of switching an occupied row with the empty row?
    – Stefan Mesken
    Nov 10 at 17:50















up vote
1
down vote

favorite












Making a standard bureocracy (using Word tables), I arrived to the following




Problem. Assume that we have a table with $n+1$ rows. The first $n$ rows are filled with names of students (and say topics of their Master works) and the last row is empty. It is required to sort this table in alphabetic order (of student names) using the operations of cut and copy-past over rows. What is the complexity of this problem (i.e., the smallest number of cut-copy-past operations in the worst case)?




I suspect that this problem has been considered (say in Computer Sciences) but I can not find a proper reference.



Remark. A simple argument shows that this worst case complexity is between $n$ and $frac32n$ (more precisely, $lfloorfrac32nrfloor+1$).




Can we always do better than $frac32n$?











share|cite|improve this question



















  • 1




    To clarify: A move consists of switching an occupied row with the empty row?
    – Stefan Mesken
    Nov 10 at 17:50













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Making a standard bureocracy (using Word tables), I arrived to the following




Problem. Assume that we have a table with $n+1$ rows. The first $n$ rows are filled with names of students (and say topics of their Master works) and the last row is empty. It is required to sort this table in alphabetic order (of student names) using the operations of cut and copy-past over rows. What is the complexity of this problem (i.e., the smallest number of cut-copy-past operations in the worst case)?




I suspect that this problem has been considered (say in Computer Sciences) but I can not find a proper reference.



Remark. A simple argument shows that this worst case complexity is between $n$ and $frac32n$ (more precisely, $lfloorfrac32nrfloor+1$).




Can we always do better than $frac32n$?











share|cite|improve this question















Making a standard bureocracy (using Word tables), I arrived to the following




Problem. Assume that we have a table with $n+1$ rows. The first $n$ rows are filled with names of students (and say topics of their Master works) and the last row is empty. It is required to sort this table in alphabetic order (of student names) using the operations of cut and copy-past over rows. What is the complexity of this problem (i.e., the smallest number of cut-copy-past operations in the worst case)?




I suspect that this problem has been considered (say in Computer Sciences) but I can not find a proper reference.



Remark. A simple argument shows that this worst case complexity is between $n$ and $frac32n$ (more precisely, $lfloorfrac32nrfloor+1$).




Can we always do better than $frac32n$?








algorithms computational-complexity permutations






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Nov 10 at 18:59

























asked Nov 10 at 17:26









Taras Banakh

15.1k13187




15.1k13187







  • 1




    To clarify: A move consists of switching an occupied row with the empty row?
    – Stefan Mesken
    Nov 10 at 17:50













  • 1




    To clarify: A move consists of switching an occupied row with the empty row?
    – Stefan Mesken
    Nov 10 at 17:50








1




1




To clarify: A move consists of switching an occupied row with the empty row?
– Stefan Mesken
Nov 10 at 17:50





To clarify: A move consists of switching an occupied row with the empty row?
– Stefan Mesken
Nov 10 at 17:50











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










No, $frac32n$ is optimal. Consider the case in which the initial order has the elements swapped in pairs, $BADCFEHG...$. Take any possible sequence of moves that sorts them; we shall show that this sequence contains at least $frac32n$ moves.



Focus on the first two locations 1 and 2 (those that contain $BA$ initially). We associate to them three distinct operations among the ones in the sequence:



  • the first operation that involves one of the first two elements (locations 1-2 in the list), which will swap one of the initial elements appearing in it with the empty space;

  • the operation that writes $A$ in location 1 (for the last time, if there is more than one);

  • the operation that writes $B$ in location 2 (for the last time, if there is more than one).

Note that these are three distinct operations, and they all involve cutting-and-pasting either the letter $A$ or the letter $B$.



Similarly, we can associate three distinct operations of the sequence to each pair of consecutive locations $(2i-1,2i)$: the first one that involves either location $2i-1$ or $2i$, the last one that involves location $2i-1$, and the last one that involves location $2i$. All of these involve cutting-and-pasting one of the two letters that go in those locations, hence there cannot be duplicates with the ones associated to a different pair.



We have built a list of $frac32n$ distinct operations among those in the sequence, so this proves that the sequence has length at least $frac32n$.



For completeness: the $frac32n$ optimal algorithm is: we have to apply a certain permutation of the letters; decompose this permutation into disjoint cycles; each $k$-cycle permutation can be applied in $k+1$ distinct operations using the empty location $X$; for instance $$BCDAXto BCDXA to BCXDA to BXCDA to XBCDA to ABCDX$$
I hope the general strategy is clear to see from this example: swap $X$ with the preceding letter $k$ times, then move back $A$ into place.






share|cite|improve this answer






















  • Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
    – Taras Banakh
    Nov 10 at 18:26











  • @TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
    – Federico Poloni
    Nov 10 at 18:33











  • Yes you are right. So I accept your answer. Thank you.
    – Taras Banakh
    Nov 10 at 18:36











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "504"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathoverflow.net%2fquestions%2f315027%2fthe-complexity-of-sorting-a-list-having-one-free-cell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










No, $frac32n$ is optimal. Consider the case in which the initial order has the elements swapped in pairs, $BADCFEHG...$. Take any possible sequence of moves that sorts them; we shall show that this sequence contains at least $frac32n$ moves.



Focus on the first two locations 1 and 2 (those that contain $BA$ initially). We associate to them three distinct operations among the ones in the sequence:



  • the first operation that involves one of the first two elements (locations 1-2 in the list), which will swap one of the initial elements appearing in it with the empty space;

  • the operation that writes $A$ in location 1 (for the last time, if there is more than one);

  • the operation that writes $B$ in location 2 (for the last time, if there is more than one).

Note that these are three distinct operations, and they all involve cutting-and-pasting either the letter $A$ or the letter $B$.



Similarly, we can associate three distinct operations of the sequence to each pair of consecutive locations $(2i-1,2i)$: the first one that involves either location $2i-1$ or $2i$, the last one that involves location $2i-1$, and the last one that involves location $2i$. All of these involve cutting-and-pasting one of the two letters that go in those locations, hence there cannot be duplicates with the ones associated to a different pair.



We have built a list of $frac32n$ distinct operations among those in the sequence, so this proves that the sequence has length at least $frac32n$.



For completeness: the $frac32n$ optimal algorithm is: we have to apply a certain permutation of the letters; decompose this permutation into disjoint cycles; each $k$-cycle permutation can be applied in $k+1$ distinct operations using the empty location $X$; for instance $$BCDAXto BCDXA to BCXDA to BXCDA to XBCDA to ABCDX$$
I hope the general strategy is clear to see from this example: swap $X$ with the preceding letter $k$ times, then move back $A$ into place.






share|cite|improve this answer






















  • Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
    – Taras Banakh
    Nov 10 at 18:26











  • @TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
    – Federico Poloni
    Nov 10 at 18:33











  • Yes you are right. So I accept your answer. Thank you.
    – Taras Banakh
    Nov 10 at 18:36















up vote
3
down vote



accepted










No, $frac32n$ is optimal. Consider the case in which the initial order has the elements swapped in pairs, $BADCFEHG...$. Take any possible sequence of moves that sorts them; we shall show that this sequence contains at least $frac32n$ moves.



Focus on the first two locations 1 and 2 (those that contain $BA$ initially). We associate to them three distinct operations among the ones in the sequence:



  • the first operation that involves one of the first two elements (locations 1-2 in the list), which will swap one of the initial elements appearing in it with the empty space;

  • the operation that writes $A$ in location 1 (for the last time, if there is more than one);

  • the operation that writes $B$ in location 2 (for the last time, if there is more than one).

Note that these are three distinct operations, and they all involve cutting-and-pasting either the letter $A$ or the letter $B$.



Similarly, we can associate three distinct operations of the sequence to each pair of consecutive locations $(2i-1,2i)$: the first one that involves either location $2i-1$ or $2i$, the last one that involves location $2i-1$, and the last one that involves location $2i$. All of these involve cutting-and-pasting one of the two letters that go in those locations, hence there cannot be duplicates with the ones associated to a different pair.



We have built a list of $frac32n$ distinct operations among those in the sequence, so this proves that the sequence has length at least $frac32n$.



For completeness: the $frac32n$ optimal algorithm is: we have to apply a certain permutation of the letters; decompose this permutation into disjoint cycles; each $k$-cycle permutation can be applied in $k+1$ distinct operations using the empty location $X$; for instance $$BCDAXto BCDXA to BCXDA to BXCDA to XBCDA to ABCDX$$
I hope the general strategy is clear to see from this example: swap $X$ with the preceding letter $k$ times, then move back $A$ into place.






share|cite|improve this answer






















  • Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
    – Taras Banakh
    Nov 10 at 18:26











  • @TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
    – Federico Poloni
    Nov 10 at 18:33











  • Yes you are right. So I accept your answer. Thank you.
    – Taras Banakh
    Nov 10 at 18:36













up vote
3
down vote



accepted







up vote
3
down vote



accepted






No, $frac32n$ is optimal. Consider the case in which the initial order has the elements swapped in pairs, $BADCFEHG...$. Take any possible sequence of moves that sorts them; we shall show that this sequence contains at least $frac32n$ moves.



Focus on the first two locations 1 and 2 (those that contain $BA$ initially). We associate to them three distinct operations among the ones in the sequence:



  • the first operation that involves one of the first two elements (locations 1-2 in the list), which will swap one of the initial elements appearing in it with the empty space;

  • the operation that writes $A$ in location 1 (for the last time, if there is more than one);

  • the operation that writes $B$ in location 2 (for the last time, if there is more than one).

Note that these are three distinct operations, and they all involve cutting-and-pasting either the letter $A$ or the letter $B$.



Similarly, we can associate three distinct operations of the sequence to each pair of consecutive locations $(2i-1,2i)$: the first one that involves either location $2i-1$ or $2i$, the last one that involves location $2i-1$, and the last one that involves location $2i$. All of these involve cutting-and-pasting one of the two letters that go in those locations, hence there cannot be duplicates with the ones associated to a different pair.



We have built a list of $frac32n$ distinct operations among those in the sequence, so this proves that the sequence has length at least $frac32n$.



For completeness: the $frac32n$ optimal algorithm is: we have to apply a certain permutation of the letters; decompose this permutation into disjoint cycles; each $k$-cycle permutation can be applied in $k+1$ distinct operations using the empty location $X$; for instance $$BCDAXto BCDXA to BCXDA to BXCDA to XBCDA to ABCDX$$
I hope the general strategy is clear to see from this example: swap $X$ with the preceding letter $k$ times, then move back $A$ into place.






share|cite|improve this answer














No, $frac32n$ is optimal. Consider the case in which the initial order has the elements swapped in pairs, $BADCFEHG...$. Take any possible sequence of moves that sorts them; we shall show that this sequence contains at least $frac32n$ moves.



Focus on the first two locations 1 and 2 (those that contain $BA$ initially). We associate to them three distinct operations among the ones in the sequence:



  • the first operation that involves one of the first two elements (locations 1-2 in the list), which will swap one of the initial elements appearing in it with the empty space;

  • the operation that writes $A$ in location 1 (for the last time, if there is more than one);

  • the operation that writes $B$ in location 2 (for the last time, if there is more than one).

Note that these are three distinct operations, and they all involve cutting-and-pasting either the letter $A$ or the letter $B$.



Similarly, we can associate three distinct operations of the sequence to each pair of consecutive locations $(2i-1,2i)$: the first one that involves either location $2i-1$ or $2i$, the last one that involves location $2i-1$, and the last one that involves location $2i$. All of these involve cutting-and-pasting one of the two letters that go in those locations, hence there cannot be duplicates with the ones associated to a different pair.



We have built a list of $frac32n$ distinct operations among those in the sequence, so this proves that the sequence has length at least $frac32n$.



For completeness: the $frac32n$ optimal algorithm is: we have to apply a certain permutation of the letters; decompose this permutation into disjoint cycles; each $k$-cycle permutation can be applied in $k+1$ distinct operations using the empty location $X$; for instance $$BCDAXto BCDXA to BCXDA to BXCDA to XBCDA to ABCDX$$
I hope the general strategy is clear to see from this example: swap $X$ with the preceding letter $k$ times, then move back $A$ into place.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Nov 10 at 18:49

























answered Nov 10 at 18:07









Federico Poloni

12.6k25481




12.6k25481











  • Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
    – Taras Banakh
    Nov 10 at 18:26











  • @TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
    – Federico Poloni
    Nov 10 at 18:33











  • Yes you are right. So I accept your answer. Thank you.
    – Taras Banakh
    Nov 10 at 18:36

















  • Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
    – Taras Banakh
    Nov 10 at 18:26











  • @TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
    – Federico Poloni
    Nov 10 at 18:33











  • Yes you are right. So I accept your answer. Thank you.
    – Taras Banakh
    Nov 10 at 18:36
















Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
– Taras Banakh
Nov 10 at 18:26





Ok. But this is just one example of an argorithm that fulfils this task. Why is this algorithm optimal? How to prove that any argorithm sorting the list of n/2 pairs will require at least 3n/2 operations?
– Taras Banakh
Nov 10 at 18:26













@TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
– Federico Poloni
Nov 10 at 18:33





@TarasBanakh The first half of my answer is an optimality proof. For any algorithm that accomplishes the task, we build a list of $frac32n$ distinct moves that appear in it.
– Federico Poloni
Nov 10 at 18:33













Yes you are right. So I accept your answer. Thank you.
– Taras Banakh
Nov 10 at 18:36





Yes you are right. So I accept your answer. Thank you.
– Taras Banakh
Nov 10 at 18:36


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathoverflow.net%2fquestions%2f315027%2fthe-complexity-of-sorting-a-list-having-one-free-cell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線