Data Structure problem

J

Joy

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.
 
C

Chris Croughton

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.

Please give us the email address of the person who set the homework so
we can mail the result directly.
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.

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...)
left<---- ------>right
Example:-------------------------------------------------

Road (Joe)in the middle of the road.

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

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
 
G

Gordon Burditt

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.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top