Giter VIP home page Giter VIP logo

depth-first-search's Introduction

Author:  Jeffrey Lembeck
Class:  CSE 680
Assignment: HW 6
Date Due: 5/16/10

To Run:
	ruby main.rb file
	where file is the folder/file structure where the test file is, example:  ruby main.rb data/cyc1


Detect Cycle in a Directed Graph

function detect_cycle(G)
/* return True if directed graph G contains a cycle */
1.  for each vertex vi of G do
2.		G.V[i].mark <- not-visited;
3.	time <- 0;
4.	for each vertex vi of G do
5.		if (G.V[i].mark) = not-visited) then
6.			G.V[i].parent <- -1;
7.			dfs_order(G,i,time);
8.	for each edge(vi,vj) of G do
9.		if (G.V[i].discover_time > G.V[j].discover_time and G.V[i].finish_time < G.V[j].finish_time) then
10.			return true
11. return false


Depth First Search - Preorder/Postorder

procedure dfs_order(G, i, alters time)
/*depth first search from vertex vi */
/* label visited vertices in preorder and postorder */
1.	G.V[i].mark <- visited;
2.	time <- time + 1;
3.	G.V[i].discover_time <- time
4.	for each edge (i,j) incident on i do
5.		if (G.V[j].mark = not-visited) then
6.			G.V[j].parent <- i;
7.			dfs_order(G, j, time);
8.	time <- time + 1;
9.	G.V[i].finish_time <- time;

depth-first-search's People

Contributors

jefflembeck avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.