adjacency-list

create graph using adjacency list

#include<iostream> using namespace std; class TCSGraph{ public: void addVertex(int vertex); void display(); TCSGraph(){ head = NULL; } ~TCSGraph(); private: struct ListNode { string name; struct ListNode *next; }; List...

A RecursiveParentChildIterator -- like the RecursiveDirectoryIterator

There are tons of examples of using the RecursiveIterator to flatten a tree structure.. but what about using it to explode a tree structure? Is there an elegant way to use this, or some other SPL library to recursively build a tree (read: turn a flat array into array of arbitrary depth) given a table like this: SELECT id, parent_id, na...

SQL help for retrieving some records using the adjacency list model

I'm struggling with writing an SQL query to display the leaf node (last node) along with their parents names without having to use a procedural function in php (I need to do this in the SQL) and I'm wondering if someone can help me. Im using MySQL as the db. I'm using the adjacency list model for storing the data. What I want returned...

How to generate Markov Chain in C#

I want to create this Markov Chain in C#. I need to know if there is any other structure other than adjacency list which can work better in this situation. Also how can I use the existing .Net collection type to implement this. ...

How do I display non-normalized data in a hierarchical structure?

My issue is that I want to display data in a hierarchal structure as so: Democrat County Clerk Candidate 1 Candidate 2 Magistrate Candidate 1 Candidate 2 Candidate 3 But I'm retrieving the dataset like this: Party | Office | Candidate -------------------------------------------- Democrat | County Clerk | Candidate 1 Democrat |...

Deeply nested subqueries for traversing trees in MySQL

I have a table in my database where I store a tree structure using the hybrid Nested Set (MPTT) model (the one which has lft and rght values) and the Adjacency List model (storing parent_id on each node). my_table (id, parent_id, lft, rght, alias) This question doesn't relate to any of the MPTT aspects of the tree but I thought I'd le...

SELECT an arbitrarily deep tree that is represented by the adjacency list model in mysql?

In mysql, I have a tree that is represented using the adjacency list model. MYTREE id parent_id title I am wondering: Given the id of a node, is there any way to SELECT the entire tree beneathe that node, complete with depth information? The tree is arbitrarily deep, so I cannot say how many levels there may be. But the re...

How to calculate the number of immediate children for each node in an adjacency list

I have hierarchical data that I represent using the adjacency list model. TABLE ID parentID title I am wondering, what is the simplest way to SELECT the number of immediate children for each node? If possible, I'd like to do this in a single select, yielding a resultset like so... RESULTS... ID title childCount 1...

Adjacency List Model Select by Path

I'm trying to select a node in my heirarchical system. I have the "/Path/To/Some/Node" (In exactly that form) and I am trying to figure out how I can get the children of "Node". Naturally "Node" is pseudo-unique, in that it is the only child called "Node" inside of Some, but there could be another "Node" inside of "Path" so you obvious...

Converting adjacency list tables to MPTT in SQL Server 2008

Is there a helpful tool or script resource to aid conversion from old-school adjacency list tables to MPTT? I would have thought it was a problem faced by a few cleverer souls than I in the past, and thought I'd check here first in case they came up with a clever solution in their travels - before embarking on my own journey to do such ...

Java: Using adjacency list to compute all pairs shortest path?

I am writing a Graph library that has both adjacency list and matrix implementations. Here is some code I came across in a Java data structures textbook: static void floyd(Graph<V,E> g) // post: g contains edge (a,b) if there is a path from a to b { Iterator<V> witer = g.iterator(); //vertex iterator while (witer.hasNext()...

PHP/MySQL: Retrieve a single path in the Adjacency List model

Is there any effective way to, without limiting the depth, retrieve a single path in a Adjacency List model based on the node's ID? Like if I've got an ID for a node named "Banana" I could get the following Path: Food > Fruits > Banana It's not a big problem if it's impossible, but I thought about if it could be possible to run joins th...

Jquery nestedSortable and MYSQL adjacency list model

Hi there... I have the following table using the MySQL adjacency list model: id | parent | name | order ----------------------------------- 1 | 0 | Kitches | 1 4 | 0 | Chairs | 2 5 | 0 | Sofas | 3 43 | 4 | Blue | 1 44 | 4 | Red | 2 Implemented the Jquery nestedSort...

Edge length in an adjacency list

Where would be the best place to put the edge length in an adjacency list implementation? I using this site as reference. What I am thinking is to put it in the edge node so to find the length from one vertex to another, you go to one of the vertex nodes and find its connecting edges and access the relevant member. (see part 5: "Data typ...