Jump to content

Recursive generation of Grey Code.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
TheUmer

TheUmer

    Newbie

  • Members
  • PipPip
  • 27 posts
I want to generate the Gray code in C using the shortest recursive algorithm. Can anyone help me with it?

Thanks.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Are you having trouble with how to generate the Gray code? Gray code - Wikipedia, the free encyclopedia
Where are you stuck? What do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
TheUmer

TheUmer

    Newbie

  • Members
  • PipPip
  • 27 posts
I already have an iterative implementation and the link you provided also directs to an iterative implementation. I'm having problem to determine the base case in the recursive implementation. What cold be the base case?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You always start with all zeros, and end with a one followed by all zeros.

Also, are you recursing on the digits, or on the entire string?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
theonejb

theonejb

    Learning Programmer

  • Members
  • PipPipPip
  • 52 posts
I found this at PasteBay. May this is what you need.

#6
sanfor

sanfor

    Newbie

  • Members
  • PipPip
  • 11 posts
good luck bro