One algorithm problem

Discussion in 'C Programming' started by mohangupta13, Apr 18, 2009.

  1. mohangupta13

    mohangupta13 Guest

    hello everyone , I don't know its the write place to ask this or not.
    I have a problem and I am not able to get any algorithm for it.

    Given two arrays A,B of size N , each with integers from 0-(N-1) . We
    have to arrange the elements in array A as they are in B (by swapping
    values) with the place in A holding the digit '0' used as the temp
    variable for swapping , in O(n) time and WITHOUT using any extra
    variable space.

    example: A[]="3021"
    B[]="2130"

    output: A[]="2130" using position of '0' in A as temp variable
    for swap.


    Also please provide any links where I can discuss algorithm related
    questions if not here ( possibly any google groups?) ?


    Thank you

    Mohan Gupta
     
    mohangupta13, Apr 18, 2009
    #1
    1. Advertising

  2. mohangupta13

    dfighter Guest

    mohangupta13 wrote:
    > hello everyone , I don't know its the write place to ask this or not.
    > I have a problem and I am not able to get any algorithm for it.
    >
    > Given two arrays A,B of size N , each with integers from 0-(N-1) . We
    > have to arrange the elements in array A as they are in B (by swapping
    > values) with the place in A holding the digit '0' used as the temp
    > variable for swapping , in O(n) time and WITHOUT using any extra
    > variable space.
    >
    > example: A[]="3021"
    > B[]="2130"
    >
    > output: A[]="2130" using position of '0' in A as temp variable
    > for swap.
    >
    >
    > Also please provide any links where I can discuss algorithm related
    > questions if not here ( possibly any google groups?) ?
    >
    >
    > Thank you
    >
    > Mohan Gupta

    Hi!
    This group deals with "The C programming language", so I would say you
    are at the wrong place.
    You should probably try the comp.programming group.
     
    dfighter, Apr 18, 2009
    #2
    1. Advertising

  3. mohangupta13

    Eric Sosman Guest

    blargg wrote:
    > mohangupta13 wrote:
    >> Given two arrays A,B of size N , each with integers from 0-(N-1) . We
    >> have to arrange the elements in array A as they are in B (by swapping
    >> values) with the place in A holding the digit '0' used as the temp
    >> variable for swapping , in O(n) time and WITHOUT using any extra
    >> variable space.
    >>
    >> example: A[]="3021"
    >> B[]="2130"
    >>
    >> output: A[]="2130" using position of '0' in A as temp variable
    >> for swap.

    >
    > void algo( int a[], int const b[], int N )
    > {
    > memcpy( a, b, N * sizeof a[0] );
    > }
    >
    > memcpy shouldn't be using any temporary buffers related to N. What am I missing?


    "By swapping values," I think, although he's not stating
    his problem very clearly. In any event, he doesn't have a C
    question (not yet, anyhow), and has already been referred to
    comp.programming for ideas about algorithms.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Apr 19, 2009
    #3
  4. On Apr 18, 7:59 pm, mohangupta13 <> wrote:
    > hello everyone , I don't know its the write place to ask this or not.
    > I have a problem and I am not able to get any algorithm for it.
    >
    > Given two arrays A,B of size N , each with integers  from 0-(N-1) . We
    > have to arrange the elements in array A as they are in B (by swapping
    > values) with the place in A holding the digit '0' used as the temp
    > variable for swapping , in O(n) time and WITHOUT using any extra
    > variable space.
    >
    > example:  A[]="3021"
    >                B[]="2130"
    >
    >     output: A[]="2130"     using position of '0' in A as temp variable
    > for swap.
    >
    > Also please provide any links where I can discuss algorithm related
    > questions if not here ( possibly any google groups?) ?


    Ive written and posted a C implementation here:

    http://groups.google.com/group/comp.programming/browse_thread/thread/978a397950925727

    Please verify.
    -Andrew.
     
    Andrew Tomazos, Apr 20, 2009
    #4
  5. mohangupta13

    CBFalconer Guest

    blargg wrote:
    >

    .... snip ...
    >
    > I miss the days when people posted URLs to actual messages, so
    > they could be easily read with one's newsreader... here's a real
    > URL to the message, rather than a portal:


    Messages don't have URLs. A message mounted on google groups may
    have an URL, but that has nothing to do with the message, which has
    probably been mangled.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
     
    CBFalconer, Apr 20, 2009
    #5
  6. CBFalconer <> writes:

    > blargg wrote:
    >>

    > ... snip ...
    >>
    >> I miss the days when people posted URLs to actual messages, so
    >> they could be easily read with one's newsreader... here's a real
    >> URL to the message, rather than a portal:


    I was going to thank you for this and then I thought such a message
    would be noise, but since I am posting anyway: thanks, blargg.

    > Messages don't have URLs.


    Several RFCs beg to differ. The matter of what a message URL really
    locates (and how) is, I agree, not clear-cut but the fact that
    messages have URL is not really in doubt.

    --
    Ben.
     
    Ben Bacarisse, Apr 21, 2009
    #6
  7. CBFalconer <> writes:
    > blargg wrote:
    >>

    > ... snip ...
    >>
    >> I miss the days when people posted URLs to actual messages, so
    >> they could be easily read with one's newsreader... here's a real
    >> URL to the message, rather than a portal:

    >
    > Messages don't have URLs. A message mounted on google groups may
    > have an URL, but that has nothing to do with the message, which has
    > probably been mangled.


    You are mistaken. The portion of a URL preceding the ':' is called
    the "scheme"; valid schemes include "http", "news", and "nntp".

    The URL blargg posted:

    <news:>

    is both valid and correct (though it may actually be less useful than
    a Google Groups URL, since you have to define the news server to use
    it, and whatever server you're using might not have the article.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 21, 2009
    #7
  8. mohangupta13

    CBFalconer Guest

    Keith Thompson wrote:
    > CBFalconer <> writes:
    >

    .... snip ...
    >
    >> Messages don't have URLs. A message mounted on google groups may
    >> have an URL, but that has nothing to do with the message, which has
    >> probably been mangled.

    >
    > You are mistaken. The portion of a URL preceding the ':' is called
    > the "scheme"; valid schemes include "http", "news", and "nntp".
    >
    > The URL blargg posted:
    >
    > <news:>
    >
    > is both valid and correct (though it may actually be less useful than
    > a Google Groups URL, since you have to define the news server to use
    > it, and whatever server you're using might not have the article.)


    Thanks. I learned something new.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
     
    CBFalconer, Apr 21, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    0
    Views:
    811
    Ahmed Moustafa
    Nov 15, 2003
  2. news.frontiernet.net
    Replies:
    6
    Views:
    1,163
    news.frontiernet.net
    Apr 16, 2004
  3. loveNUNO
    Replies:
    2
    Views:
    963
    loveNUNO
    Nov 20, 2003
  4. Bapaiah Katepalli
    Replies:
    1
    Views:
    1,531
    Mike Treseler
    Jun 23, 2006
  5. Andrew Tomazos

    Solution to "One Algorithm Problem"

    Andrew Tomazos, Apr 20, 2009, in forum: C Programming
    Replies:
    8
    Views:
    326
    Andrew Tomazos
    Apr 28, 2009
Loading...

Share This Page