Chapter 18

These are the solutions to the exercises found in the section Exercises.

  1. If a user is browsing “nails”, the website will recommend “nail polish”, “needles”, “pins”, and “hammer”.

  2. The order of depth-first search would be A-B-E-J-F-O-C-G-K-D-H-L-M-I-N-P, as seen in the following image:

    images/graphs/solution_2_graph.png
  3. The order of breadth-first search would be A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P, as seen in the following image:

    images/graphs/solution_3_graph.png
  4. Following is an implementation of breadth-first search:

     import​ Queue ​from​ ​'./queue_implementation.js'​;
     
     function​ bfs(startingVertex, searchValue) ...

Get A Common-Sense Guide to Data Structures and Algorithms in JavaScript, Volume 1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.