Most algorithm puzzles requires intuitive thinking and clear approach and the saddest part is that ..many fail to adapt the motivation and beauty of algorithm analysis and design. Its easy to be a victim of algorithms if you dive into depths and prune for the essence of creativity behind modeling an algorithm for a real world problem. However i will try my best to persuade you to the roadway to establish the better bonding in the same. Explicitly speaking, its not about how brainy you are or how persuasive you are to this either,its about how much flexible and agile your thinking is.I came across quite a possibly short quote yet this can inspire you a lot .
The problem goes like this :
An accident occurs in George’s Lab and his lab is a mess. His minions are scattered around his lab.
Gru manages to rescue all of his minions except Penny. To find Penny, as last resort George plans to use Dr.Sheldon’s cookie robots to search throughout his lab.
In a step a cookie robot can move either North, South, East or West. Cookie robots are extremely intelligent,
they will search for Penny at all locations that they can access.
If even the cookie robots fail to find Penny, George will declare that Penny is no more.
Given the map of George’s Lab showing all the free spaces through which the cookie robots can pass through and the obstacles,
you have to tell if Penny will be found or not.
* * * * *
* * P * *
* 0 0 * *
* 0 * * *
* 0 0 G *
P : represent P’s initial position
G: represents G’s initial postion
* : represents a block/wall
0 :represents empty space or a path :
For every input in the form a matrix shown above you have to output whether George can reach Penny or not.
“Penny is no more”. in a single line if Penny won’t be found by the cookie robots. Quotes are used for clarity.
“Found Penny.” in a single line if the cookie robots will find Penny. Quotes are used for clarity.
Explanation : The matrix clearly shows that empty path/space shown by “0” ,P can easily traverse and reach G.
Is your brain pointing you the right way ?
- Which algorithm should I choose ?
- How I’m gonna do this is in my computer ? Oh! I got the book by Tanenbaum 😉
- Can this be more efficient or Can I have a better fix?
- Which data structure should i use ?
We have no time… Lets get our pen and paper working .
Visualization of the matrix as a graph
Some of the programmers often tackle a problem without even clearly analyzing and designing the problem.Well,I used to do the same thing earlier but as I proceeded I came to know even shorter,simple or easiest problems requires a clear,accurate analyze and design.
- Read the problem statement clearly until the objective of the question becomes crystal clear to you.
- Now when you have understood the objective of the question,you may ask yourself ” Have I come across this similar problem before “. If you have, then try tackling the problem as u did for the earlier .If you haven’t ..it’s time for your brain to run
- Clearly analyze the problem with a set of inputs and observe the outputs . Did u find something interesting ?