Originally posted by Kaydell Leavitt:
I can see how to do it in 4n moves.
Hint: use a 'merge sort' and move stack1 and stack2 onto stack3. The result of stack3 will be sorted but will be the wrong way, so you could order stack3 by popping off the 2n elements that it contains onto an empty stack.
This is 4n which is Order-n , in "big-Oh" notation, that is O(n).
The minus-four isn't really significant because it's just a constant.
I just looked up "merge sort" in wikipedia.org and I must have used the wrong terminology.
1. Create a new stack, called stack4
2. loop as long as stack1 or stack2 has objects on them
Originally posted by donaldth smithts:
so is there a way to solve it with 3 stacks??
4n-4 moves
move bank:
push =1 move
pop =1 move
top =2 moves (because its implemented using i pop and one push command)
Originally posted by donaldth smithts:
so by your definition how whould you solve it??
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
|