Adobe Interview Question
Member Technical StaffsTeam: Live Cycle
Country: India
Interview Type: In-Person
I asked him whether x,y,z co-ordinates of vertex are given or not. He told nothing is given.
Anyway I came up with this data structure (6-ary tree like).
struct node{
int point[3];
struct node* east;
struct node* west;
struct node* north;
struct node* south;
struct node* top;
struct node* bottom;
}
Then told him that to search for a node we can do BFS. However he was not satisfied. He was asking me to improve it.
I could not come up with better DS.
What I was lacking ??
i think it can be done like this cuboid all sides are equal so u can simply have int point instead int point[3] and based on size of the point we can store it in list .eg the input node are like this 50 30 49 20 11 2 22 then in first node store 50 in first list next 30 comes so again move 50 to second node and store 30 in first next 49 comes now move 50 to 3rd position 49 in 2nd now 20 move 49 to 3rd and 50 4th and 20 to 2nd then for 11 make it as first then for 2 make this as first node now for 22 all the entry in first node is done so check 22 comes in between which node 20 and 30 so put 22 as first entry on node 20 if u do like this searching will be more easy then bst only thing here is considering each node size is unique .please let me know any thing wrong.
@Anonymous :- From where did you get this idea "in cuboid all sides are equal". I learnt this property for cubes only. Anyway, I asked interviewer if co-ordinates are given or not. He told me nothing is given. If co-ordinates along with length,breadth and hight of cuboid would have been given then no need to use 6 pointers here, we can traverse simply by comparing co-ordinates moving accordingly.
Comments please.
I think he was not satisfied because every node can be reached many different ways. Suppose if you reached a node traversing n nodes then it can be reached 6^n ways. This is exponential and therefore BFS would be inefficient. I would say go to the first node by traversing as much left, below and behind then traverse all the nodes layer by layer, row by row, cell by cell.
i think take a 3D array to store each cuboid and take another 3D array to store chain of cuboid like
struct cuboid
{
int east;
int west;
int north;
int south;
int top;
int bottom;
}
cuboid chain_of_cuboid[][][][][][];
Imagine the cuboid center to be the named point of reference. Then the problem will pan down to "finding search algorithm from a given sent of points (centers) in a 3-D space".
So, one possible data structure that can be used is
struct center
{
int/float x; #x-direction ref
int/float y; #y-direction
int/float z; #z - direction
}
I believe we shld treat this as a normal graph and do a DFS (since it wld be faster than BFS in this case). Seems to me as a rip off the problem wherein we need path between 2 given nodes in a graph, also herein we may have more than 1 solution (obviously) and the next question that wld come up wld be to find the shortest path (Dijiktra shld be answer of that). Cube or cuboid used here wld just be distraction. Do comment your thoughts
A* graph search with the heuristic function equal to the manhattan distance between the start state and the goal state
- mayank gupta October 08, 2012