1
$\begingroup$

I was wondering if it is possible to animate the following graph.

enter image description here

The command used to generate the graph is the following:

ListPlot[{{{1, 1}}, {{1, 2}}, {{1, 3}}, {{1, 4}}, {{2, 1}}, {{2, 
2}}, {{3, 1}}, {{3, 2}}, {{4, 1}}, {{4, 2}}}, 
PlotMarkers -> {{"\[Pi]", Large}, {"8", Large}, {"9", Large}, {"10", 
Large}, {"2", Large}, {"5", Large}, {"3", Large}, {"4", 
Large}, {"1", Large}, {"\!\(\*SqrtBox[\(2\)]\)", Large}}, 
Ticks -> {{1, 2, 3, 4}, {0, 1, 2, 3, 4}}, 
AxesLabel -> {"Number of columns", "Size of the columns"}, 
AxesStyle -> Directive[Black, Thick, 20, Arrowheads[0.03]], 
PlotRange -> {{0, 5}, {0, 5}}, 
PlotStyle -> Directive[Black, Thick, Large], 
LabelStyle -> Directive[Thick, Large], 
TicksStyle -> Directive[Black, Thick, 20], ImageSize -> Large]

Ideally, I would like to animate a graph where I arrange the numbers of the sequence $(\pi,2,8,9,5,10,3,4,1,\sqrt{2})$ using Hammersley's argument (see J. Michael Steele, "Variations on the Monotone subsequence theme of Erdős and Szekeres") .

enter image description here

So, first $\pi$, then $2$ in the next column, then $8$ and $9$ above $\pi$ and so on.

I would greatly appreciate any suggestion or hint.

Thank you.

$\endgroup$
4
  • $\begingroup$ For completeness, can you give a reference for this? $\endgroup$ – J. M.'s ennui Nov 24 '15 at 14:52
  • $\begingroup$ @J.M. What do you mean? $\endgroup$ – johnny09 Nov 24 '15 at 14:58
  • $\begingroup$ From what book/paper/whatever did you see "Hammersley's argument"? $\endgroup$ – J. M.'s ennui Nov 24 '15 at 15:04
  • $\begingroup$ @J.M. Okay, thanks. I have edited my question. $\endgroup$ – johnny09 Nov 24 '15 at 15:06
2
$\begingroup$

Here's how I understand your question:

hammersley = With[{k = If[#1 === {}, {}, Position[Last /@ #1, x_ /; x < #2]]}, 
                  If[k === {}, Append[#1, {#2}],
                     MapAt[Function[l, Append[l, #2]], #1, First[k]]]] &;

myList = {π, 2, 8, 9, 5, 10, 3, 4, 1, Sqrt[2]};

gathered = Rest[FoldList[hammersley, {}, myList]];
dims = Dimensions[PadRight[Last[gathered]]];

ListAnimate[
    Graphics[MapIndexed[Text, #, {2}],
             PlotRange -> Transpose[{{1, 1}/2, dims + 1/2}]] &
    /@ gathered]

Hammersley's sort?


With axes:

ListAnimate[
    Graphics[MapIndexed[Text, #, {2}], Axes -> True,
             PlotRange -> Transpose[{{0, 0}, dims + 1/2}]] &
    /@ gathered]

but really, wasn't it apparent?

$\endgroup$
4
  • $\begingroup$ Thank you for the answer. Although, is it possible to include the axes? And also how did you export it as a gif? $\endgroup$ – johnny09 Nov 24 '15 at 18:42
  • $\begingroup$ I can do the axes, but maybe later. As for exporting, I used Export[] instead of ListAnimate[]. $\endgroup$ – J. M.'s ennui Nov 24 '15 at 18:46
  • $\begingroup$ J.M., I would like to know that did you have a copy of this paper :The insertion algorithm. The lbrary of our university doesn't buy the paper that published before 1993. $\endgroup$ – xyz Nov 27 '15 at 7:35
  • $\begingroup$ @J.M. I cannot understand the algorithm 5.4 of Knot Refinement in page 165 of "The NURBS Book" without that paper. $\endgroup$ – xyz Nov 27 '15 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.