about summary refs log tree commit diff
path: root/scratch/deepmind/part_two/todo.org
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-03-20T16·49+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-03-20T16·49+0000
commitae9e83f5d7eb2bf6860ec88785b7216e98f53adf (patch)
tree7734bc7ffb1877bc05443501469077f6c9463880 /scratch/deepmind/part_two/todo.org
parent117f0be7c2dee368944263ebe482a397acc7ea55 (diff)
Solve InterviewCake.com's mesh-message problem
Write a function that returns the shortest path between nodes A and B in an
unweighted graph.

I know two algorithms for finding the shortest path in a *weighted* graph:
- Use a heap as a priority queue instead of the regular queue that you would use
  when doing a BFT. This is called Dijkstra's algorithm. You can also use
  Dijkstra's algorithm in an unweight graph by imaginging that all of the
  weights on the edges are the same value (e.g. 1).
- Map the weighted graph into an unweighted graph by inserting N nodes between
  each node, X and Y, where N is equal to the weight of the edge between X and
  Y. After you map the weighted graph into an unweighted graph, perform a BFT
  from A to B. A BFT will always find the shortest path between nodes A and B in
  an unweighted graph.

I had forgotten that a BFT in an unweighted graph will always return the
shortest path between two nodes. I learned two things from InterviewCake.com's
solution:
1. I remembered that a BFT in an unweighted graph will return the shortest
   path (if one exists).
2. I learned to use a dictionary to store the edge information and then
   back-tracking to reconstruct the shortest path.
Diffstat (limited to 'scratch/deepmind/part_two/todo.org')
-rw-r--r--scratch/deepmind/part_two/todo.org2
1 files changed, 1 insertions, 1 deletions
diff --git a/scratch/deepmind/part_two/todo.org b/scratch/deepmind/part_two/todo.org
index b767ecb3d4a0..5d296b9b5287 100644
--- a/scratch/deepmind/part_two/todo.org
+++ b/scratch/deepmind/part_two/todo.org
@@ -25,7 +25,7 @@
 ** DONE Binary Search Tree Checker
 ** DONE 2nd Largest Item in a Binary Search Tree
 ** DONE Graph Coloring
-** TODO MeshMessage
+** DONE MeshMessage
 ** TODO Find Repeat, Space Edition BEAST MODE
 * Dynamic programming and recursion
 ** TODO Recursive String Permutations