Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

concept check please

Posted on 2004-09-26
5
Medium Priority
?
195 Views
Last Modified: 2011-09-20
1. A stack can be used to permute numbers. For example, assume you have '1
2 3' as an input stream (reading from the right) into your stack. Assume
you can push or pop in any order at any time (with the restriction that
you cannot pop from an empty stack). Thus, if you push all three and
pop_top all three, your output is '1 2 3'. What are all the possible
permutations for output you can achieve for this input stream?

ANSWER: 5

321   312   231   213   123

The choices in this case are limited by the fact that you cannot execute
a pop on an empty stack and you cannot push from an empty input stream.
Thus allowable choices can be shown by using a binary decision tree.

<EXAMPLE>

                        PUSH
                       /      \
                    POP       PUSH
                   /          /   \
                PUSH        POP    PUSH
               /  \        /   \      \
           POP    PUSH   POP  PUSH    POP
           /        \     /      \       \
       PUSH        POP  PUSH     POP     POP
        |           |    |        |       |
       POP         POP   POP     POP     POP
      321          312   231     213     123

2. Prove by induction that for any n >= 1, 1^3 + 2^3 + 3^3 + ... + n^3 =
(1 + 2 + 3 + ... + n)^2.

Call this summation SUM3.

*1. Establish a base case:     SUM3(1) = 1^3 = 1.

*2. Now assume SUM3 true for some k.  Recall that we proved by induction
    (in class) that 1 + 2 + 3 + ... + k =  2 | k(k+1) (meaning 2 divides
    k(k+1) )   thus:

    SUM3(k) =  ( 2 | k(k+1) ) ^2

*3. Show that if true for k, true for k+1.

    SUM3(k + 1) =  ( 2 | k(k+1) ) ^2  + (k+1)^3
                       =  ( 2 | k^2 + k ) ^2 + (k+1)^3
                       =  ( 2 | k+1(k+2) ) ^2 =  ( 2 | k^2 + 3k + 2) ^2


    SUM3(k+1) = SUM3(k) + (k+1)^3

    ( 2 | k(k+1) ) ^2


3. Prove by induction that the sum 1 + 3 + 5 + 7 + ... + 2n-1 is n^2; e.g. // not sure on this one...please advise.
for n=3, 1 + 3 + 5 = 3^2

        1 + 3 + 5 + ... + (2n - 1) = n^2
        Assume true for sample n;

        1 + 3 + 5 + ... + (2n - 1) - 2(n - 1) = (n - 1)^2

        n^2 - 2(n - 1) = (n - 1)^2
        n^2 - 2n + 2 - 1 = n^2 - 2n +1
        n^2 - 2n + 1 = n^2 - 2n + 1

        Since true for n + 1,..true for any n.
0
Comment
Question by:edelossantos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:edelossantos
ID: 12157932
Please advise on #3.  Del
0
 
LVL 9

Accepted Solution

by:
jhshukla earned 2000 total points
ID: 12158005
>> ANSWER: 5
>> 321   312   231   213   123

NO! Answer: 6
321   312   231   213   123   132
this may b because i did not understand how you permute using stack.

and this is not a math room. anyways since most comp sci people like math this is a good place to seek answers.
1 + 3 + 5 + 7 + ... + 2n-1 is n^2
next number in the series is 2(n+1)-1; substituting (1 + 3 + 5 + 7 + ... + 2n-1) = n^2 the series becomes
n^2 + 2(n+1)-1
= n^2 + 2n + 1
= (n+1)^2
THE END
0
 

Author Comment

by:edelossantos
ID: 12162712
sorry... and thanks again for your help.  Truly appreciate it.  Regards.  Del
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 12166068
sorry? for what? you haven't hurt anyone or done anything harmful to this world. plus I love induction. so i thank you for asking.
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 12166536
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question