Skip to main content

All Questions

2 votes
1 answer
273 views

Turn an array of pairs of start and end points into an ordered series

Given an array of pairs, for example: [["Denver", "Miami"], ["Miami", "Tulsa"], ["LA", "Okmulgee"], ["Mobile", "Portland"...
JB Wilson's user avatar
  • 123
1 vote
1 answer
524 views

Cheapest flights within k stops algorithm in JavaScript

The problem: There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is ...
myTest532 myTest532's user avatar
8 votes
5 answers
296 views

Sort a list of pairs representing an acyclic, partial automorphism

I have this sample data: let trips = [ { from: "DEN", to: "JFK" }, { from: "SEA", to: "DEN" }, { from: 'JFK', to: 'SEA' }, ]; ...
Shivam Bhalla's user avatar
0 votes
1 answer
651 views

Cracking the Coding Interview - 4.1 Graph Traversal

I'm working through the classic Cracking the Coding Interview book. I'm trying to solve the following graph problem: 4.1) Route Between Nodes: Given a directed graph, design an algorithm to find ...
Narin Luangrath's user avatar
3 votes
2 answers
2k views

Dijkstra's algorithm in JavaScript

I'm trying to implement Dijkstra's algorithm to find the shortest path. This is from a challenge on CodeWars. In this scenario there is a map: ...
BrunoLM's user avatar
  • 183
5 votes
0 answers
180 views

Assembling and traversing a graph, given a list of items and parent pointers

I've written a function which takes input such as this: ...
Tomáš Hübelbauer's user avatar
8 votes
1 answer
4k views

Cyclic "dependency detection" in JavaScript

I have written some simple code to detect cyclic dependencies for a module loading system and I'd like some feedback on how I can go about improving it. The code itself finds the first cycle in the ...
Jack Wilsdon's user avatar
  • 1,651
3 votes
0 answers
3k views

Implementation of Dijkstra's Algorithm in JavaScript that returns both shortestDist/shortestPaths

I decided to try to understand the basic idea behind Dijkstra's algorithm better so I implemented it in JavaScript (the only language I am proficient in as of now) so I could really see what was ...
WinchenzoMagnifico's user avatar
3 votes
2 answers
203 views

Vertex cover approximation in JavaScript

I believe this runs in \$O(V+E)\$ but I wouldn't be able to explain the reasons why. I was looking for some general code review and any help on understanding the runtime. ...
Daniel Jacobson's user avatar
2 votes
0 answers
312 views

Return the Euler Cycle for a graph with es6

My algorithm for finding an Euler tour of a digraph, G⃗, if such a tour exists, starting from some vertex, v. ...
Daniel Jacobson's user avatar
3 votes
0 answers
4k views

Depth first search implementation

I've been practicing my algorithms using The Algorithm Design Manual. I've decided to implement the depth first search section (5.8) using javascript. Note you can execute the code here if you don't ...
Daniel Jacobson's user avatar
3 votes
1 answer
59 views

Find order to install dependencies

Given a JavaScript map object of dependencies and their dependencies, determine order to install them: Example: Input: ...
Daniel Jacobson's user avatar
2 votes
1 answer
334 views

Is this code for getting the dependency tree of a file correct?

...
MaiaVictor's user avatar
  • 1,101