Skip to content

Instantly share code, notes, and snippets.

View temirov's full-sized avatar

Vadym Tyemirov temirov

  • San Francisco, CA
View GitHub Profile
@temirov
temirov / dfs.rb
Last active September 18, 2015 17:10 — forked from gosuri/dfs.rb
Recursive depth-first search (DFS) for traversing a graph in ruby.
# Depth-first search (DFS) is an algorithm for traversing or
# searching a tree, tree structure, or graph. One starts at
# the root (selecting some node as the root in the graph case)
# and explores as far as possible along each branch before backtracking.
#
# A graph can be represented by its adjacency matrix G,
# where G[i][j] == 1 if there is an edge between
# vertices i and j and 0 otherwise.
#
# Below Graph in diagram http://i.imgur.com/sV1UzUn.png