Count sequences of length $n$, with fixed first and last element and elements differ by one

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











up vote
1
down vote

favorite












I'm trying to solve the following problem: given $n, x, y$, count sequences of length $n$ with fixed first element - $x$ and last one - $y$, such that any two adjacent elements differ by one or minus one.



For example $n=3, x = 1, y = 1$, the answer is $2$, because there are two sequences of length $3$ which should be counted $[ 1,0,1], [1, 2,1]$.



I came up with function $f(i, x)$ which means sequences of length $i$ with $i-th$ element being $x$. We can express $f(i, x) = f(i-1, x-1) + f(i-1, x+1)$.



But this is hard to compute for large numbers, is there any solution that can solve this with combinatorics.







share|cite|improve this question
















  • 2




    Hint: any such sequence can be described as a sequence of $pm 1's$ of length $n-1$ where we can compute in advance the number of $+1's$ and $-1's$. In your case, for example, we know there has to be exactly one of each.
    – lulu
    Aug 13 at 11:21















up vote
1
down vote

favorite












I'm trying to solve the following problem: given $n, x, y$, count sequences of length $n$ with fixed first element - $x$ and last one - $y$, such that any two adjacent elements differ by one or minus one.



For example $n=3, x = 1, y = 1$, the answer is $2$, because there are two sequences of length $3$ which should be counted $[ 1,0,1], [1, 2,1]$.



I came up with function $f(i, x)$ which means sequences of length $i$ with $i-th$ element being $x$. We can express $f(i, x) = f(i-1, x-1) + f(i-1, x+1)$.



But this is hard to compute for large numbers, is there any solution that can solve this with combinatorics.







share|cite|improve this question
















  • 2




    Hint: any such sequence can be described as a sequence of $pm 1's$ of length $n-1$ where we can compute in advance the number of $+1's$ and $-1's$. In your case, for example, we know there has to be exactly one of each.
    – lulu
    Aug 13 at 11:21













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to solve the following problem: given $n, x, y$, count sequences of length $n$ with fixed first element - $x$ and last one - $y$, such that any two adjacent elements differ by one or minus one.



For example $n=3, x = 1, y = 1$, the answer is $2$, because there are two sequences of length $3$ which should be counted $[ 1,0,1], [1, 2,1]$.



I came up with function $f(i, x)$ which means sequences of length $i$ with $i-th$ element being $x$. We can express $f(i, x) = f(i-1, x-1) + f(i-1, x+1)$.



But this is hard to compute for large numbers, is there any solution that can solve this with combinatorics.







share|cite|improve this question












I'm trying to solve the following problem: given $n, x, y$, count sequences of length $n$ with fixed first element - $x$ and last one - $y$, such that any two adjacent elements differ by one or minus one.



For example $n=3, x = 1, y = 1$, the answer is $2$, because there are two sequences of length $3$ which should be counted $[ 1,0,1], [1, 2,1]$.



I came up with function $f(i, x)$ which means sequences of length $i$ with $i-th$ element being $x$. We can express $f(i, x) = f(i-1, x-1) + f(i-1, x+1)$.



But this is hard to compute for large numbers, is there any solution that can solve this with combinatorics.









share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Aug 13 at 11:15









someone123123

367213




367213







  • 2




    Hint: any such sequence can be described as a sequence of $pm 1's$ of length $n-1$ where we can compute in advance the number of $+1's$ and $-1's$. In your case, for example, we know there has to be exactly one of each.
    – lulu
    Aug 13 at 11:21













  • 2




    Hint: any such sequence can be described as a sequence of $pm 1's$ of length $n-1$ where we can compute in advance the number of $+1's$ and $-1's$. In your case, for example, we know there has to be exactly one of each.
    – lulu
    Aug 13 at 11:21








2




2




Hint: any such sequence can be described as a sequence of $pm 1's$ of length $n-1$ where we can compute in advance the number of $+1's$ and $-1's$. In your case, for example, we know there has to be exactly one of each.
– lulu
Aug 13 at 11:21





Hint: any such sequence can be described as a sequence of $pm 1's$ of length $n-1$ where we can compute in advance the number of $+1's$ and $-1's$. In your case, for example, we know there has to be exactly one of each.
– lulu
Aug 13 at 11:21











1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










We can think of such a sequence $x=a_1,a_2,dots,a_n=y$ where $|a_i-a_i-1|=1$ instead as a sequence of $pm 1$ of length $n-1$: $b_1,dots,b_n-1$ where $b_i=a_i+1-a_i$. In order to start at $x$ and end at $y$, we need a certain number of $+1$'s and $-1$'s. In particular, if $xleq y$, then we need $y-x$ more $+1$'s than $-1$'s and if $xgeq y$, then we need $x-y$ more $+1$'s than $-1$'s. Now, these $pm 1$'s can be placed wherever you want in the sequence provided there's the correct excess, so, for instance, we can choose in which of the $n-1$ available positions to place the $+1$'s, which is $n-1choose k$ if we need to use $+1$ $k$ times. Hopefully you can finish it from here.






share|cite|improve this answer




















    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: "69"
    ;
    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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    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%2fmath.stackexchange.com%2fquestions%2f2881260%2fcount-sequences-of-length-n-with-fixed-first-and-last-element-and-elements-di%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    We can think of such a sequence $x=a_1,a_2,dots,a_n=y$ where $|a_i-a_i-1|=1$ instead as a sequence of $pm 1$ of length $n-1$: $b_1,dots,b_n-1$ where $b_i=a_i+1-a_i$. In order to start at $x$ and end at $y$, we need a certain number of $+1$'s and $-1$'s. In particular, if $xleq y$, then we need $y-x$ more $+1$'s than $-1$'s and if $xgeq y$, then we need $x-y$ more $+1$'s than $-1$'s. Now, these $pm 1$'s can be placed wherever you want in the sequence provided there's the correct excess, so, for instance, we can choose in which of the $n-1$ available positions to place the $+1$'s, which is $n-1choose k$ if we need to use $+1$ $k$ times. Hopefully you can finish it from here.






    share|cite|improve this answer
























      up vote
      2
      down vote



      accepted










      We can think of such a sequence $x=a_1,a_2,dots,a_n=y$ where $|a_i-a_i-1|=1$ instead as a sequence of $pm 1$ of length $n-1$: $b_1,dots,b_n-1$ where $b_i=a_i+1-a_i$. In order to start at $x$ and end at $y$, we need a certain number of $+1$'s and $-1$'s. In particular, if $xleq y$, then we need $y-x$ more $+1$'s than $-1$'s and if $xgeq y$, then we need $x-y$ more $+1$'s than $-1$'s. Now, these $pm 1$'s can be placed wherever you want in the sequence provided there's the correct excess, so, for instance, we can choose in which of the $n-1$ available positions to place the $+1$'s, which is $n-1choose k$ if we need to use $+1$ $k$ times. Hopefully you can finish it from here.






      share|cite|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        We can think of such a sequence $x=a_1,a_2,dots,a_n=y$ where $|a_i-a_i-1|=1$ instead as a sequence of $pm 1$ of length $n-1$: $b_1,dots,b_n-1$ where $b_i=a_i+1-a_i$. In order to start at $x$ and end at $y$, we need a certain number of $+1$'s and $-1$'s. In particular, if $xleq y$, then we need $y-x$ more $+1$'s than $-1$'s and if $xgeq y$, then we need $x-y$ more $+1$'s than $-1$'s. Now, these $pm 1$'s can be placed wherever you want in the sequence provided there's the correct excess, so, for instance, we can choose in which of the $n-1$ available positions to place the $+1$'s, which is $n-1choose k$ if we need to use $+1$ $k$ times. Hopefully you can finish it from here.






        share|cite|improve this answer












        We can think of such a sequence $x=a_1,a_2,dots,a_n=y$ where $|a_i-a_i-1|=1$ instead as a sequence of $pm 1$ of length $n-1$: $b_1,dots,b_n-1$ where $b_i=a_i+1-a_i$. In order to start at $x$ and end at $y$, we need a certain number of $+1$'s and $-1$'s. In particular, if $xleq y$, then we need $y-x$ more $+1$'s than $-1$'s and if $xgeq y$, then we need $x-y$ more $+1$'s than $-1$'s. Now, these $pm 1$'s can be placed wherever you want in the sequence provided there's the correct excess, so, for instance, we can choose in which of the $n-1$ available positions to place the $+1$'s, which is $n-1choose k$ if we need to use $+1$ $k$ times. Hopefully you can finish it from here.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Aug 13 at 16:05









        Munchhausen

        68615




        68615






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2881260%2fcount-sequences-of-length-n-with-fixed-first-and-last-element-and-elements-di%23new-answer', 'question_page');

            );

            Post as a guest













































































            這個網誌中的熱門文章

            How to combine Bézier curves to a surface?

            Mutual Information Always Non-negative

            Why am i infinitely getting the same tweet with the Twitter Search API?