Answer the question
In order to leave comments, you need to log in
How difficult is this test task and what to look through to solve it?
Hello! there is a test (one of), time: until February 1 ...
What would you advise to look through, read, watch in order to approach the implementation of this algorithm?
Transport way
You have a map of the starry sky. It shows the name of each star, as well as the distance from it to other stars in light seconds. Implement the solution function, which should take three arguments: an object in which the keys are the names of the stars, and the values are the distances to the stars (one-way traffic in space), as well as the names of the start and end points of the path - start and finish, respectively. The function should return the shortest distance from the start star to the finish star and the path to follow.
Function signature:
const solution = function(graph, start, finish) {
// Ваше решение
}
const graph = {
start: { A: 50, B: 20 },
A: { C: 40, D: 20 },
B: { A: 90, D: 90 },
C: { D: 160, finish: 50 },
D: { finish: 20 },
finish: {}
};
const start = 'start';
const finish = 'finish';
{
distance: 90,
path: ['start', 'A', 'D', 'finish']
}
const solution = function(graph, start, finish) {
// Ваше решение
}
Answer the question
In order to leave comments, you need to log in
The most trivial way is through a breadth-wise traversal of the graph. google bfs
This is one of those tasks where you should show imagination, and a non-standard approach, and not the ability to google the solution.
4d. fantasy on the theme of the stars.
First, it's 3d. Second, stars move. Suppose stars have coordinates, velocity vectors, and besides this - relativistic displacement, due to the limitation of the speed of light, some stars can also move at speeds close to the speed of light. This is an amazing problem, and you're reducing it to the traveling salesman problem and the backpack problem.
I would consider that the task is relativistic, dynamic, since the distances between the stars are millions of set years, and the spacecraft cannot exceed the speed of light when moving, that is, in fact, this is a task that cannot be solved exactly, unlike any task on earth, with finite non-relativistic velocities,
I would also admit that the acceleration time to cruising speed and deceleration are insignificant when approaching a star and moving away from a star, since these distances are measured in light years, that is, 5-8 orders of magnitude less than the distances between stars, in addition, there are clusters and voids in stellar systems, which makes the task as such easier.
You can consider 4 ways to solve problems: genetic algorithms, neural networks, machine learning, and the standard approach - an approximate solution of problems with boundary conditions.
It is possible, for simplicity, to completely abandon the velocities of the stars, and consider that the traveling salesman moves with the help of teleportation, that is, fix the time t0. Then I would apply the Monte Carlo method, for example, since no one guarantees that the task will be on a small number of stars and there will not be trillions, or use some kind of condition that would decide how we will solve the problem, approximately, or exactly.
In any case, you can play with 3d, try using the clipping algorithms that Carmack developed in Quake, or somehow stand out and show non-standard thinking, including trying binary search trees, self-balancing RB trees, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question