job tessio job tessio Interview Question for job tessios job tessios


Team: engineer
Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
1
of 1 vote

I would suggest to use BFS to find distance from start to every checkpoint, from every checkpoint to the end, and then between every pair of checkpoints. The complexity is O(x*n) , where x = 18, n = 10000.
Then it become travelling salesman problem with 18 towns with complexity O(x^2*2^x) which is roughly 3*10^8, quite feasible.
Can we do better?

- Maxim November 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

A BFS is probably not the fastest for this case. Use A* to get the paths.

Also, your complexity for the TSP is very wrong. Unless I'm mistaken,TSP is a factorial computation so finding the optimal ordering of checkpoints is going to be quite difficult to compute ( O(18!) which will be 6,402,373,705,728,000 different paths). You're better off using some stochastic algorithm like an evolutionary algorithm or an ACO to get the checkpoint ordering.

- zortlord November 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is in reply to zortlord's comment. If I am not mistaken, the worst case complexity of A* is O(E), the same as of the BFS. It is true that A* may be faster on average for 2 points, but (a) we have to find the distance between 1 and many points, and (b) the path finding itself is not bottleneck here, the TSP is.

Also, the complexity of Held-Karp algorithm solving TSP is indeed O(n^2 2^n). O(n!) is the complexity of the most straightforward approach and Held-Karp is much faster.

- emaz.ip November 08, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

To emaz.jp:

Can you implement a complete and functional Held-Karp algorithm without using an outside library within a reasonable period of time? If so, I'd be very interested in seeing that code as a learning experience.

- zortlord November 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Bitmask -DP =D

- Ashpsycho November 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

could not get output,,,,
class orienting
{
public:
void main();
//height of map
const int mapHeight =6;
//width of map
const int mapWidth = 8;
// representation of map
char map[mapHeight][mapWidth + 1] =
{
"########",
"#@....G#",
"##.##@##",
"#..@..S#",
"#@.....#",
"########",
};
const char closeblock = '#';
const char openblock= '.';
const char checkpoint = '@';

class orienting::main(start.x,start.y)
{
public:
int X;
int Y;
orienting(int x = 0, int y = 0) { X = x, Y = y; }
orienting(const orientinggame &orientinggame)
{
X = orienting.X;// orienting position of the move
Y = orienting.Y;//orienting position of the move
}
};

orienting.start(4,7);
orienting.goal(2, 7);

void displaymap()
{
for (int Y = 0; Y < mapHeight; Y++)
{
for(int X=0;x<mapWidth;X++)
{
cout<<"The shortest path from start S(2,7) to goal G(4,7) is"<<map[Y][X]);
}
}
printf("\n");
}

bool Solve(int X, int Y)
{
// stop the searching progress in another direction
map[Y][X] =closeblock;
//progressive update of blocked positions that user cannot pass
displaymap();
sleep(50);
// move to the position if it is shortest path
map[y][x]=openblock;
displaymap();

// Make the move (if it's wrong, we will backtrack later.

map[Y][X] = checkpoint;
// for progressive update of map
displaymap();
Sleep(50);

// Check if we have reached our goal.
if (X == goal.X && Y == goal.Y)
{
return true;
}

// Recursively searching for our goal.
if (X > 0 && map[Y][X - 1] ==openblock && Solve(X - 1, Y))
{
return true;
}
if (X < mapWidth && map[Y][X + 1] ==openblock && Solve(X + 1, Y))
{
return true;
}
if (Y > 0 && map[Y - 1][X] == openblock && Solve(X, Y - 1))
{
return true;
}
if (Y < mapHeight && map[Y + 1][X] ==openblock && Solve(X, Y + 1))
{
return true;
}

// Otherwise we need to backtrack and find another solution.
map[Y][X] =openblock;

// for progressive update
display();
Sleep(50);
return false;
}

int _tmain(int argc, _TCHAR* argv[])
{
orienting o;
o.main(orienting.start,&orienting.goal);

if (Solve(start.X, start.Y))
{
displaymap();
}
else
{
printf("map does not exists\n");
}

return 0;
}

- sai November 13, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More