Why does tsort not report any loop in this example?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












How does tsort find the order in the following examples?



Why does tsort not report any loop in this example,



$ tsort <<EOF
a b c d c b a b
EOF

a
c
b
d


whereas it does in this one? Thanks.



$ tsort <<EOF
a b c d d c b a
EOF

tsort: -: input contains a loop:
tsort: a
tsort: b
a
b
tsort: -: input contains a loop:
tsort: c
tsort: d
c
d









share|improve this question

























    up vote
    0
    down vote

    favorite












    How does tsort find the order in the following examples?



    Why does tsort not report any loop in this example,



    $ tsort <<EOF
    a b c d c b a b
    EOF

    a
    c
    b
    d


    whereas it does in this one? Thanks.



    $ tsort <<EOF
    a b c d d c b a
    EOF

    tsort: -: input contains a loop:
    tsort: a
    tsort: b
    a
    b
    tsort: -: input contains a loop:
    tsort: c
    tsort: d
    c
    d









    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      How does tsort find the order in the following examples?



      Why does tsort not report any loop in this example,



      $ tsort <<EOF
      a b c d c b a b
      EOF

      a
      c
      b
      d


      whereas it does in this one? Thanks.



      $ tsort <<EOF
      a b c d d c b a
      EOF

      tsort: -: input contains a loop:
      tsort: a
      tsort: b
      a
      b
      tsort: -: input contains a loop:
      tsort: c
      tsort: d
      c
      d









      share|improve this question













      How does tsort find the order in the following examples?



      Why does tsort not report any loop in this example,



      $ tsort <<EOF
      a b c d c b a b
      EOF

      a
      c
      b
      d


      whereas it does in this one? Thanks.



      $ tsort <<EOF
      a b c d d c b a
      EOF

      tsort: -: input contains a loop:
      tsort: a
      tsort: b
      a
      b
      tsort: -: input contains a loop:
      tsort: c
      tsort: d
      c
      d






      tsort






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 17 at 16:36









      Tim

      1




      1




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          There is no loop in your first input. Let's break it down:



          a b c d c b a b


          Or, putting it in pairs:



          • a < b

          • c < d

          • c < b

          • a < b (this one specified twice!)

          So you have that both "a" and "c" come before "b" and that "c" also comes before "d". But there are no loops there!



          On your second example though, what you have is two direct loops, both a < b, b < a (loop!) and also c < d, d < c (loop!)



          Putting these in a graph for visualization (you might want to look into the dot program) might help you visualize these loops easily!






          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482364%2fwhy-does-tsort-not-report-any-loop-in-this-example%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
            2
            down vote



            accepted










            There is no loop in your first input. Let's break it down:



            a b c d c b a b


            Or, putting it in pairs:



            • a < b

            • c < d

            • c < b

            • a < b (this one specified twice!)

            So you have that both "a" and "c" come before "b" and that "c" also comes before "d". But there are no loops there!



            On your second example though, what you have is two direct loops, both a < b, b < a (loop!) and also c < d, d < c (loop!)



            Putting these in a graph for visualization (you might want to look into the dot program) might help you visualize these loops easily!






            share|improve this answer
























              up vote
              2
              down vote



              accepted










              There is no loop in your first input. Let's break it down:



              a b c d c b a b


              Or, putting it in pairs:



              • a < b

              • c < d

              • c < b

              • a < b (this one specified twice!)

              So you have that both "a" and "c" come before "b" and that "c" also comes before "d". But there are no loops there!



              On your second example though, what you have is two direct loops, both a < b, b < a (loop!) and also c < d, d < c (loop!)



              Putting these in a graph for visualization (you might want to look into the dot program) might help you visualize these loops easily!






              share|improve this answer






















                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                There is no loop in your first input. Let's break it down:



                a b c d c b a b


                Or, putting it in pairs:



                • a < b

                • c < d

                • c < b

                • a < b (this one specified twice!)

                So you have that both "a" and "c" come before "b" and that "c" also comes before "d". But there are no loops there!



                On your second example though, what you have is two direct loops, both a < b, b < a (loop!) and also c < d, d < c (loop!)



                Putting these in a graph for visualization (you might want to look into the dot program) might help you visualize these loops easily!






                share|improve this answer












                There is no loop in your first input. Let's break it down:



                a b c d c b a b


                Or, putting it in pairs:



                • a < b

                • c < d

                • c < b

                • a < b (this one specified twice!)

                So you have that both "a" and "c" come before "b" and that "c" also comes before "d". But there are no loops there!



                On your second example though, what you have is two direct loops, both a < b, b < a (loop!) and also c < d, d < c (loop!)



                Putting these in a graph for visualization (you might want to look into the dot program) might help you visualize these loops easily!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 17 at 17:00









                Filipe Brandenburger

                6,1141625




                6,1141625



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482364%2fwhy-does-tsort-not-report-any-loop-in-this-example%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

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)