Skip to content

Depth-limited search #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions algorithm/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"bfs": "BFS",
"bridges": "Find-Bridges",
"dfs": "DFS",
"dls": "Depth-Limited Search",
"dijkstra": "Dijkstra",
"floyd_warshall": "Floyd-Warshall",
"page_rank": "PageRank Algorithm",
Expand Down
17 changes: 17 additions & 0 deletions algorithm/graph_search/dls/count_descendant/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This is a sample DLS applications where
// we try to find number of descendant of root within some depth
function DLSCount (limit, node, parent) { // node = current node, parent = previous node
tracer._visit(node, parent)._wait();
var child = 0;
if (limit>0) { // cut off the search
for (var i = 0; i < G[node].length; i++) {
if (G[node][i]) { // if current node has the i-th node as a child
child += 1 + DLSCount(limit-1, i, node); // recursively call DLS
}
}
return child;
}else{
return child;
}
}
logger._print('Number of descendant is ' + DLSCount(2,0));
17 changes: 17 additions & 0 deletions algorithm/graph_search/dls/count_descendant/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var tracer = new DirectedGraphTracer();
var logger = new LogTracer();
tracer.attach(logger);
var G = [ // G[i][j] indicates whether the path from the i-th node to the j-th node exists or not
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
];
tracer._setTreeData(G, 0);
15 changes: 15 additions & 0 deletions algorithm/graph_search/dls/desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"DLS": "Depth-Limited search (DLS) is an algorithm for traversing or searching tree or graph data structures. It's actually specific type of DFS where the search is limited to some depth from start node (root). One starts at the root (selecting some arbitrary node as the root in the case of a graph) and explores as far as possible (within some limit) along each branch before backtracking.",
"Complexity": {
"time": "worst $O(b^l)$",
"space": "worst $O(bl)$",
"notes" : "</br>b is branching factor, for example binary tree has branching factor 2 </br> l is limit that we define"
},
"References": [
"<a href='http://www.cs.colostate.edu/~anderson/cs440/index.html/doku.php?id=notes:week2b'>Colorado State University Lecture Notes</a>"
],
"files": {
"tree": "Searching a tree (limited depth)",
"count_descendant": "Count all descendant of root within some depth"
}
}
13 changes: 13 additions & 0 deletions algorithm/graph_search/dls/tree/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a sample DLS where
// we try to find number of descendant of root within some depth
function DLS (limit, node, parent) { // node = current node, parent = previous node
tracer._visit(node, parent)._wait();
if (limit>0) { // cut off the search
for (var i = 0; i < G[node].length; i++) {
if (G[node][i]) { // if current node has the i-th node as a child
DLS(limit-1, i, node); // recursively call DLS
}
}
}
}
DLS(2,0);
17 changes: 17 additions & 0 deletions algorithm/graph_search/dls/tree/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var tracer = new DirectedGraphTracer();
var logger = new LogTracer();
tracer.attach(logger);
var G = [ // G[i][j] indicates whether the path from the i-th node to the j-th node exists or not
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
];
tracer._setTreeData(G, 0);
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy