Data Structure problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joy

    #1

    Data Structure problem

    Hi,
    I have a problem in data structures which most of the people find a
    homework but that it is and I am sorry for that.
    i am stuck in this one .Please try to help me , just provide me the
    outline how to analyse this problem.

    Question : A man Joe has a habbit of eating pancakes & driving
    bikes.Once he went for outside by his bike,now he is EXACTLY IN THE
    MIDDLE OF A ROAD his stomach is crying for pancakes and also his
    contact lenses are full of dirt.Now HE CANNOT SEE A PANCAKE SHOP UNTILL
    HE REACH THE PANCAKE SHOP EXACTLY BEFIRE IT.
    Now please provide me the algorithm for finding the pancake shop which
    is nearer to JOE & also tell me how can I calculate time and space
    complexity.

    Note: Information given as if he goes to the right side it is
    considered as 1unit,2unit.... and son on and if he chooses left then
    -1unit,-2unit...and so on.

    II)Second part of the problem says that if Joe wants to flip a coin for
    ,in which direction(left or right) he has to move.
    Then what happens to the code/algorithm.

    left<---- ------>right
    Example:-------------------------------------------------

    Road (Joe)in the middle of the road.

    --------------------------------------------------

    Thanks
    Paul.

  • Chris Croughton

    #2
    Re: Data Structure problem

    On 8 Aug 2005 01:11:54 -0700, Joy <pp_5555@yahoo. com> wrote:
    [color=blue]
    > I have a problem in data structures which most of the people find a
    > homework but that it is and I am sorry for that.[/color]

    Please give us the email address of the person who set the homework so
    we can mail the result directly.
    [color=blue]
    > i am stuck in this one .Please try to help me , just provide me the
    > outline how to analyse this problem.
    >
    > Question : A man Joe has a habbit of eating pancakes & driving
    > bikes.Once he went for outside by his bike,now he is EXACTLY IN THE
    > MIDDLE OF A ROAD his stomach is crying for pancakes and also his
    > contact lenses are full of dirt.Now HE CANNOT SEE A PANCAKE SHOP UNTILL
    > HE REACH THE PANCAKE SHOP EXACTLY BEFIRE IT.
    > Now please provide me the algorithm for finding the pancake shop which
    > is nearer to JOE & also tell me how can I calculate time and space
    > complexity.[/color]

    Simple. Joe gets off the bike and wanders around in the road until he
    is run over by a car. End of problem. Driving or riding a bike while
    unable to see as far as the side of the road is an offence in most
    civilised countries so if he's lucky he might get arrested first.

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>

    int main(void)
    {
    srand((int)time (NULL));
    if (rand() & 1)
    printf("Joe is dead\n");
    else
    printf("Joe is in prison\n");
    return 0;
    }

    (Using time(NULL) to initialise srand() is not totally portable in C,
    although it is on POSIX systems, but there is no other portable way of
    getting anything close to a random seed either...)
    [color=blue]
    > left<---- ------>right
    > Example:-------------------------------------------------
    >
    > Road (Joe)in the middle of the road.
    >
    > --------------------------------------------------[/color]

    Example:
    _____
    _/o |
    |_______|
    O-/-< o o
    --------------------------------------------------

    Joe having been knocked over by a car (you can't see the bike, it's
    hidden behind Joe's body). Actually it looks more like a van than a
    car, because I'm not a very good artist, but you should get the idea.
    For homework you should adapt the program I gave above to print out a
    better picture, and also pictures of Joe in hospital, Joe's funeral, Joe
    getting arrested, Joe in court, Joe in prison, etc. according to the
    random number.

    (Or, to put it another way, your question is off topic and you knew it,
    and you should do your own homework. However, I couldn't resist the
    story of poor hungry Joe...)

    Chris C

    Comment

    • Gordon Burditt

      #3
      Re: Data Structure problem

      >I have a problem in data structures which most of the people find a[color=blue]
      >homework but that it is and I am sorry for that.
      >i am stuck in this one .Please try to help me , just provide me the
      >outline how to analyse this problem.
      >
      > Question : A man Joe has a habbit of eating pancakes & driving
      >bikes.Once he went for outside by his bike,now he is EXACTLY IN THE
      >MIDDLE OF A ROAD his stomach is crying for pancakes and also his
      >contact lenses are full of dirt.Now HE CANNOT SEE A PANCAKE SHOP UNTILL
      >HE REACH THE PANCAKE SHOP EXACTLY BEFIRE IT.[/color]

      Joe keeps going in one direction until he sees a pancake shop (or
      starves or runs out of gas). This means he's now AT a different
      pancake shop, so he drives around in small circles until he hits
      it (even though he, for some odd reason, can't see it, probably due
      to some darn fool executing fflush(stdin).) Then he can order
      pancakes and pay for the damage.

      Gordon L. Burditt

      [color=blue]
      >Now please provide me the algorithm for finding the pancake shop which
      >is nearer to JOE & also tell me how can I calculate time and space
      >complexity.
      >
      >Note: Information given as if he goes to the right side it is
      >considered as 1unit,2unit.... and son on and if he chooses left then
      >-1unit,-2unit...and so on.
      >
      >II)Second part of the problem says that if Joe wants to flip a coin for
      >,in which direction(left or right) he has to move.
      >Then what happens to the code/algorithm.
      >
      > left<---- ------>right
      >Example:-------------------------------------------------
      >
      >Road (Joe)in the middle of the road.
      >
      > --------------------------------------------------
      >
      >Thanks
      >Paul.
      >[/color]


      Comment

      Working...