473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Data Structure Problem

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.

Aug 8 '05 #1
1 1321
Joy wrote:


HE REACH THE PANCAKE SHOP EXACTLY BEFIRE IT.
Now please provide me the algorithm for finding the pancake shop which
is nearer to JOE


Well, how would you do it if you were Joe?

One of the secrets of programming is that you can't
write a program until you are able to solve the problem
by yourself.

I would do: Choose one direction. Walk into that direction
until either: the road ends or a shop is reached.
Turn around and return to the starting place.
Then walk in the other direction until either: the
road ends or a shop is reached.
Turn around, walk back to the starting point and make a
decission:
If 2 shops were reached then compare the distances and
choose the nearer one. If only one shop was reached, well,
take it and be happy.
That would be the overall strategy in order to solve that problem,
although I admit I would take the first shop I reach and would not
search for another one. But this is a different story and that
is not what the assignment asks for.

Another possibility would be:
turn one step to the left
is there a shop? if yes: goal reached
if no: turn around and make 2 steps to the right
is there a shop? if yes: goal reached
if no: turn around and make 3 steps to the left
is there a shop? if yes: goal rached
if no: turn around and make 4 steps to the right
is there a shop? if yes ....
and so on, and so on until both ends of the road have been
reached.

The ides behind all this is to make a pattern where you
investigate in alternate directions from the starting point

starting position *
try 1 to the left *|
try 1 to the right .|*
try 2 to the left *.|.
try 2 to the right ..|.*
try 3 to the left *..|..
try 3 to the right ...|..*
try 4 to the left *...|...
try 4 to the right ....|...*
..
..
..

so you know that the shop you find first must also be the nearest
one (measured from the starting position), because if there is a
nearer one, you would have discovered it in a previous step.

Or you can do ....
Well, think up a different strategy and try it.
Coming up with clever strategies is half of the fun in programming.

--
Karl Heinz Buchegger
kb******@gascad.at
Aug 8 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
1
by: Da-Breegster | last post by:
Hi. I'm attempting to write a roguelike (think nethack, crawl, angband, tome, adom, and yes, I suppose even rogue) in Perl and I've ran into a problem regarding the data structure for the map and...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
11
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
1
by: saleem | last post by:
Dear friends, I am working on the problem which deals with the data management of requests and how should we match the responses for the requests to compare the correct Response. my problem...
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.