Comments (4)
Code for BFS
const bfs = (graph, node) => {
let visited = [];
let nodes= [];
nodes.push(node);
while (nodes.length !== 0) {
const newNode = nodes.shift();
if (!visited.includes(newNode )) {
visited.push(newNode );
nodes= [...nodes, ...graph[newNode ]];
}
}
return visited;
};
Code for DFS
const dfs = (graph, node) => {
let stack= [];
let queue= [];
stack.push(node);
while (stack.length !== 0) {
const newNode = stack.pop();
if (!queue.includes(newNode )) {
queue.push(newNode );
stack= [...stack, ...graph[newNode]];
}
}
return queue;
};
from age-viewer.
Code for DFS:
class Graph_Implementation
{
constructor(v)
{
this.V = v;
this.adj = new Array(v);
for(let i = 0; i < v; i++)
this.adj[i] = [];
}
addedges(v, w)
{
this.adj[v].push(w);
}
DFSUtil(v, visited)
{
visited[v] = true;
document.write(v + " ");
for(let i of this.adj[v].values())
{
let n = i
if (!visited[n])
this.DFSUtil(n, visited);
}
}
DFS(v)
{
let visited = new Array(this.V);
for(let i = 0; i < this.V; i++)
visited[i] = false;
this.DFSUtil(v, visited);
}
}
g = new Graph_Implementation(4);
g.addedges(0, 1);
g.addedges(0, 2);
g.addedges(1, 2);
g.addedges(2, 0);
g.addedges(2, 3);
g.addedges(3, 3);
document.write("Following is Depth First Traversal " +
" ");
g.DFS(2);
BFS Code:
class Graph_Implmentation
{
constructor(v)
{
this.V = v;
this.adj = new Array(v);
for(let i = 0; i < v; i++)
this.adj[i] = [];
}
addedges(v, w)
{
this.adj[v].push(w);
}
BFS(s)
{
let visited = new Array(this.V);
for(let i = 0; i < this.V; i++)
visited[i] = false;
let queue=[];
visited[s]=true;
queue.push(s);
while(queue.length>0)
{
s = queue[0];
document.write(s+" ");
queue.shift();
this.adj[s].forEach((adjacent,i) => {
if(!visited[adjacent])
{
visited[adjacent]=true;
queue.push(adjacent);
}
});
}
}
}
g = new Graph_Implmentation(11);
g.addedges(1,2);
g.addedges(1,4);
g.addedges(2,3);
g.addedges(2,6);
g.addedges(3,5);
g.addedges(3,7);
g.addedges(4,6);
g.addedges(5,2);
g.addedges(5,6);
g.addedges(6,1);
g.addedges(7,5);
console.log("Following is Breadth First Traversal " + " ");
g.BFS(1);
from age-viewer.
@aked21 I guess this will help you. If it is so then you can close this issue.
from age-viewer.
Thank you @Nimra-1234 @MJinH
from age-viewer.
Related Issues (20)
- Scrolling behaviour in Age-viewer HOT 1
- Refresh button doesn't work properly
- Properties not showing in Age Viewer for any graph
- Copy query to editor message HOT 2
- issue connecting viewer the apache-age running on docker HOT 6
- Text spam in console logs HOT 2
- Tooltips for Node Menu Items HOT 1
- start frontend error:BREAKING CHANGE: The request './nonIterableRest' failed to resolve only because it was resolved as fully specified
- AGEViewer or browser is not clickable.. HOT 1
- AGEViewer or browser is not clickable..and i have attched the error from console below..can anyone help me out HOT 7
- Installation error at 'npm run start' HOT 1
- Error in 'npm run setup' HOT 1
- Error when trying to run with "npm run start" HOT 1
- AGE-Viewer front-end not building (backend seems fine) HOT 7
- Incompatible Postgres version 16 with age-viewer's backend HOT 1
- Allow collapsing a vertice
- Timeout exception, unable to recover
- Would like to be able to specify what property or label name itself to use when presenting visualization of linked nodes and / or edges
- Would like to be able to view data output in JSON vs. TABULAR ( HTML TABLE ) format. Possibly being able to add/remove visible fields / sort.
- Design 3D view into graph with controls similar to XBox hand in AR glasses
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from age-viewer.