Re: Fast pancake flipping
From: Richard Heathfield (invalid_at_address.co.uk.invalid)
Date: 02/19/04
- Next message: Michael Jørgensen: "Re: Fast pancake flipping"
- Previous message: CBFalconer: "Re: Algorithm ideas"
- In reply to: Alf P. Steinbach: "Re: Fast pancake flipping"
- Next in thread: Alf P. Steinbach: "Re: Fast pancake flipping"
- Reply: Alf P. Steinbach: "Re: Fast pancake flipping"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 19 Feb 2004 06:33:27 +0000
Alf P. Steinbach wrote:
> On Wed, 18 Feb 2004 12:42:29 +0000, Richard Heathfield
> <invalid@address.co.uk.invalid> wrote:
>
>>James Dow Allen wrote:
>>
>><snip>
>>
>>> Here I don't ask you to solve the Pancake Flipping Problem; just
>>> to write a subroutine that will perform a specified flip in constant
>>> time independent of sequence or prefix length. Define your own data
>>> structure and function interface. After the flip, the data structure
>>> must still be in a form that allows further constant-time flips
>>> by the same routine.
>>
>>Assuming there is no upper bound on N (the sequence length), this problem
>>is insoluble, since swapping takes time, making the operation inherently
>>O(N).
>>
>>Am I missing something?
>
> You can reverse an entire sequence by inverting a boolean flag.
>
> You can reverse a prefix of N elements of a sequence by storing the number
> N somewhere, associated with the sequence, and adjusting indexing
> operations as
>
> ElementType& operator[] ( size_t i )
> {
> return (i < N? myElements[N-i-1] : myElements[i]);
> }
Assuming this works (which I didn't check), it only pushes the O(N) issue
sideways, instead of dealing with it during the flip. It doesn't
/eliminate/ the O(N) issue. I don't consider that to be a satisfactory
solution.
-- Richard Heathfield : binary@eton.powernet.co.uk "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999. C FAQ: http://www.eskimo.com/~scs/C-faq/top.html K&R answers, C books, etc: http://users.powernet.co.uk/eton
- Next message: Michael Jørgensen: "Re: Fast pancake flipping"
- Previous message: CBFalconer: "Re: Algorithm ideas"
- In reply to: Alf P. Steinbach: "Re: Fast pancake flipping"
- Next in thread: Alf P. Steinbach: "Re: Fast pancake flipping"
- Reply: Alf P. Steinbach: "Re: Fast pancake flipping"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|