473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

graph ADT

Hi

What is the best way to implement a undirected weighted graph ADT in
javascript?

Apr 6 '06 #1
11 2998
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
What is the best way to implement a undirected weighted graph ADT in
javascript?


Telling us what you are talking about?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 6 '06 #2
Sorry

I'm writing an extension to firefox where I want to grade all links on
the pages the user visits and then store this information in a weighted
graph (grade as edges, uri as nodes), to make it possible to find the
"best" link on the page or calculate the median grade of the path
between to pages the user has visited, etc.

What I want to know is how to implement the graph datastructure in
javascript in the most efficient way (performance wise and to some
extent also memory wise). I was thinking on using an adjacency matrix
but it would probably be to sparse since most urls on the web are not
connected to each other, and I wonder if someone had an better idea.

Apr 6 '06 #3
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
Sorry
Please quote what you are replying to. If you want to post a followup via
groups.google.com, don't use the "Reply" link at the bottom of the article.
Click on "show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
<http://www.safalra.com/special/googlegroupsreply/>

I'm writing an extension to firefox where I want to grade all links on
the pages the user visits and then store this information in a weighted
graph (grade as edges, uri as nodes), to make it possible to find the
"best" link on the page or calculate the median grade of the path
between to pages the user has visited, etc.
Clientside drawing of graphs is possible,
but should be carfully cross-browser designed.

An IE example of mine from 2003:

<http://devrijehuisarts.org/test/jsgraph.asp>

What I want to know is how to implement the graph datastructure in
javascript in the most efficient way (performance wise and to some
extent also memory wise). I was thinking on using an adjacency matrix
but it would probably be to sparse since most urls on the web are not
connected to each other, and I wonder if someone had an better idea.


'Graph datastructures' and 'adjacency matrices', do you need such beasts?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 6 '06 #4
Evertjan. skrev:
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
I'm writing an extension to firefox where I want to grade all links on
the pages the user visits and then store this information in a weighted
graph (grade as edges, uri as nodes), to make it possible to find the
"best" link on the page or calculate the median grade of the path
between to pages the user has visited, etc.


Clientside drawing of graphs is possible,
but should be carfully cross-browser designed.

An IE example of mine from 2003:

<http://devrijehuisarts.org/test/jsgraph.asp>


I dont want to draw graphs just store data in them i.e the
datastructure graph and then be able to traverse it depending on the
values of the edges.

What I want to know is how to implement the graph datastructure in
javascript in the most efficient way (performance wise and to some
extent also memory wise). I was thinking on using an adjacency matrix
but it would probably be to sparse since most urls on the web are not
connected to each other, and I wonder if someone had an better idea.


'Graph datastructures' and 'adjacency matrices', do you need such beasts?


Not sure there may be some better way to implement it. It's just that a
graph seemed like the natural choice since the internet already is a
graph.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Apr 6 '06 #5
An************@gmail.com wrote:
What I want to know is how to implement the graph datastructure in
javascript in the most efficient way (performance wise and to some
extent also memory wise). I was thinking on using an adjacency matrix
but it would probably be to sparse since most urls on the web are not
connected to each other, and I wonder if someone had an better idea.


var node1 = {target: null};
var node2 = {target: node1, weight: 1};

Got the idea?
PointedEars
Apr 6 '06 #6
Thomas 'PointedEars' Lahn wrote:
An************@gmail.com wrote:
What I want to know is how to implement the graph datastructure in
javascript in the most efficient way (performance wise and to some
extent also memory wise). I was thinking on using an adjacency matrix
but it would probably be to sparse since most urls on the web are not
connected to each other, and I wonder if someone had an better idea.


var node1 = {target: null};
var node2 = {target: node1, weight: 1};

Got the idea?


Sorry, I overlooked "undirected".
PointedEars
Apr 6 '06 #7
Thomas 'PointedEars' Lahn skrev:
Thomas 'PointedEars' Lahn wrote:
An************@gmail.com wrote:
What I want to know is how to implement the graph datastructure in
javascript in the most efficient way (performance wise and to some
extent also memory wise). I was thinking on using an adjacency matrix
but it would probably be to sparse since most urls on the web are not
connected to each other, and I wonder if someone had an better idea.
var node1 = {target: null};
var node2 = {target: node1, weight: 1};

Got the idea?


Not quite, I understand how that work if each node only is connected to
one node but how does it work in the following example:

<ascii graphic warning>

w1:2, w2:45, w3:34
|------------------> www.abc.com ->...
| w1:6, w2:1, w3:234
http://www.google.com -|------------------> www.def.com ->...
| w1:7, w2:6, w3:1
|------------------> www.ghi.com ->...
</acsii graphic warning>

As you can see I alsa need more then one weight value on each edge.
Sorry, I overlooked "undirected".
No my fault I meant directed.
PointedEars


Apr 6 '06 #8
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
It's just that a
graph seemed like the natural choice since the internet already is a
graph.


Are you sure?

I did not know I was sending my email on a graph,
reading usenet on a graph,
and more recently browse the www on a graph!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 6 '06 #9
Evertjan. skrev:
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
It's just that a
graph seemed like the natural choice since the internet already is a
graph.


Are you sure?

I did not know I was sending my email on a graph,
reading usenet on a graph,
and more recently browse the www on a graph!


I'm not sure if we are thinking of the same kind of graph... I mean
that the www is a directed graph with the urls as nodes and the links
as edges of the graph

i.e this kind of graph: http://en.wikipedia.org/wiki/Graph_theory

Apr 6 '06 #10
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
Evertjan. skrev:
An************@gmail.com wrote on 06 apr 2006 in comp.lang.javascript:
> It's just that a
> graph seemed like the natural choice since the internet already is a
> graph.
>


Are you sure?

I did not know I was sending my email on a graph,
reading usenet on a graph,
and more recently browse the www on a graph!


I'm not sure if we are thinking of the same kind of graph... I mean
that the www is a directed graph with the urls as nodes and the links
as edges of the graph

i.e this kind of graph: http://en.wikipedia.org/wiki/Graph_theory


Ah, now I understand, You are portretting the internet as the Kaballah.

I still do not agree that something you can portret as a graph is a
graph.

An abstraction is not the real thing.

Perhaps your quest has made the internet as nothing more than the dynamic
connection of IP addresses, but it is a "living" thing, changing with
time, having to make corrections on power outings and political pressure
of the Chinese government, of pornography and spamming, of learning,
passtime, emotion and joy.

Surely the joy is not part of your graph, though the graph could be your
joy?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 6 '06 #11
An************@gmail.com wrote:
Thomas 'PointedEars' Lahn skrev:
Thomas 'PointedEars' Lahn wrote:
> An************@gmail.com wrote:
>> What I want to know is how to implement the graph datastructure in
>> javascript in the most efficient way (performance wise and to some
>> extent also memory wise). I was thinking on using an adjacency matrix
>> but it would probably be to sparse since most urls on the web are not
>> connected to each other, and I wonder if someone had an better idea.
>
> var node1 = {target: null};
> var node2 = {target: node1, weight: 1};
>
> Got the idea?


Not quite, I understand how that work if each node only is connected to
one node but how does it work in the following example:

<ascii graphic warning>

w1:2, w2:45, w3:34
|------------------> www.abc.com ->...
| w1:6, w2:1, w3:234
http://www.google.com -|------------------> www.def.com ->...
| w1:7, w2:6, w3:1
|------------------> www.ghi.com ->...
</acsii graphic warning>

As you can see I alsa need more then one weight value on each edge.


A) The value of the property of the node object can be a reference to an
Array object. Each element of the array can be an object with the
target node object reference and different weights as property value:

var targetNodes = [
{name: 'www.abc.com', targets: [...]},
{name: 'www.def.com', targets: [...]},
{name: 'www.ghi.com', targets: [...]}
];

var sourceNode = {
name: 'www.google.com',
targets: [
{target: targetNodes[0], w1: 2, w2: 45, w3: 34},
{target: targetNodes[1], w1: 6, w2: 1, w3: 234},
{target: targetNodes[2], w1: 7, w2: 6, w3: 1}
]
};

B) The node object can have several enumerable properties, where the
value of each property is a reference to an object that has the
target node and the weights as its properties:

var sourceNode = {
target1: {targetNodes[0], w1: 2, w2: 45, w3: 34},
target2: {targetNodes[1], w1: 6, w2: 1, w3: 234},
target3: {targetNodes[2], w1: 7, w2: 6, w3: 1}
};

C) (recommended) Each node can be represented by name, as name of the
property of a graph object referencing a node object with the
aforementioned properties:

var graph = {
'www.google.com': {
targets: {
'www.abc.com': {w1: 2, w2: 45, w3: 34},
'www.def.com': {w1: 6, w2: 1, w3: 234},
'www.ghi.com': {w1: 7, w2: 6, w3: 1}
}
},

'www.abc.com': {
...
},

'www.def.com': {
...
},

'www.ghi.com': {
...
}
};

The object the `targets' property references can also be a collection[1],
so that the target node names and associated weights can be referred to
by numeric index too:

graph['http://www.google.com'].targets[0].name === 'www.abc.com'

graph[graph['http://www.google.com'].targets[0].name]
=== graph['www.abc.com']

graph['http://www.google.com'].targets['www.abc.com'].w1
=== graph['http://www.google.com'].targets[0].w1
=== 2

(etc.)

I recommend approach C because it does not require the resolution of
circular references (as the first two approaches), nevertheless displays
objects of graph theory directly in data structure and program logic, and
allows for full exploitation of the Object literal syntax, which makes it
easy to maintain.
Regards,
PointedEars
___________
[1] <URL:http://pointedears.de/scripts/collection.js>
Apr 6 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lilith | last post by:
Is there a python module somewhere (been searching today, no luck) which has efficiently coded various graph-handling routines, such as finding the shortest path through a graph, or the set of all...
25
by: Magnus Lie Hetland | last post by:
Is there any interest in a (hypothetical) standard graph API (with 'graph' meaning a network, consisting of nodes and edges)? Yes, we have the standard ways of implementing graphs through (e.g.)...
1
by: entropy123 | last post by:
Hey all, In an effort to solve a sticky - for me - problem I've picked up Sedgewick's 'Algorithm's in C'. I've tried working through the first few problems but am a little stumped when he refers...
2
by: MLH | last post by:
A97 Am having difficulty displaying graph in Form View that I see fine in graph control on form opened in design view. I know I'm doing something wrong. If I open the form in design view - I...
0
by: mylog | last post by:
I have downloaded a GLEE(Graph Layout Execution Engine) and written the following code to display a windows form from a web page but i am encountering with a small problem on displaying the graph...
2
by: sriniwas | last post by:
Hi Frnd's, m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my...
4
by: Man4ish | last post by:
namespace ve/////////////////ve.h { struct VertexProperties { std::size_t index; boost::default_color_type color; }; }...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
1
by: Man4ish | last post by:
I am creating a graph using boost library, I am making the network using create_Network function() i am adding the vertices to this graph by creating the object g of class Graph. I am trying to...
0
by: eureka2050 | last post by:
Hi all, I am creating a radar chart containing 2 plots using jpgraph. My code is as follows:- include ("./jpgraph/src/jpgraph.php"); include ("./jpgraph/src/jpgraph_radar.php"); //...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.