adjacency-list

Boost adjacency_list help needed

I'm trying to use Boost's adjacency_list type and I'm having trouble understanding the documentation. Say I define a class named State and I instantiate one instance for each state in the USA: class State { ... }; State california, oregon, nevada, arizona, hawaii, ... I want to enter these into a boost::adjacency_list the vertices ar...

Adjacency tree from single table

I've read a lot of people discussing nested lists, but I was wondering how to iterate through an adjacancy list/tree in PHP. I have a table with: id, title, parent_id And I've selected all records out into an array called $pages. Then using this php: function makeList($pages, $used) { if (count($pages)) { echo "<ul>"; ...

Flatten Adjacency List Hierarchy To A List Of All Paths

I have a Table that stores Hierarchical information using the Adjacency List model. (uses a self referential key - example below. This Table may look familiar): category_id name parent ----------- -------------------- ----------- 1 ELECTRONICS NULL 2 TELEVISIONS 1 3 TUBE ...

Multiple tables in nested sets hierarchy

I have a number of distinct items stored in different MySQL tables, which I'd like to put in a tree hierarchy. Using the adjacency list model, I can add a parent_id field to each table and link the tables using a foreign key relationship. However, I'd like to use a nested sets/modified preorder tree traversal model. The data will be use...

Triggers: Adjacency List to a Nested Set

I have an adjacency list on a legacy system that I would like to query recursively (need to get subtotals, etc). Can I make a trigger in MySQL that either store in a separate table, or alternatively store in separate columns in the same table the "Nested Set Equivalent" of a given set? My set is like this: +-------------+-------------...

How to pull grandchildren from database

I want to pull out menu items from MySQL. Main menu id=1, parentid=0 -Contact us id=2, parentid=1 -Music id=3, parentid=1 --Rock id=8, parentid=3 --Classic id=9, parentid=3 -Car id=4, parentid=1 --Toyota id=5, parentid=4, --Ford id=6, parentid=4...

adjacency list of a directed weighted graph

I am using adjacency lists to represent a directed weighted graph and based on the example code provided by this SO question, I have created the following: import java.util.HashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; import java.util.Set; public class _Graph { private Map<String, Link...

Adjacency List Tree Using Recursive WITH (Postgres 8.4) instead of Nested Set

I'm looking for a Django tree library and doing my best to avoid Nested Sets (they're a nightmare to maintain). The cons of the adjacency list model have always been an inability to fetch descendants without resorting to multiple queries. The WITH clause in Postgres seems like a solid solution to this problem. Has anyone seen any perfo...

Why is my adjacency list showing duplicate edges?

#include <iostream> using namespace std; struct node { int v; node* next; node (int x, node* t) { v = x; next = t; } }; typedef node *link; int **malloc2d(int, int); void printMatrix(int **, int); link *convertToList (int **, link *, int); void printList (link * a, int size); // program begins fun...

What is better adjacency lists or adjacency matrix for graph problems in c++?

What is better adjacency lists or adjacency matrix for graph problems in c++? And what are the advantages and disadvantages of each? EDIT:can anyone provide a link with a clean code for say Breadth first search in linked lists format ?? ...

How to remove all parrents with no children in SQL?

I have a table that has id, name, level (the depth) and parrent_id, is there any nice way to remove all nodes without any children? (On one level suffices)? I know I can do it in application - load all the nodes on given level and the check if they have children, if not remove, but this whould probably be more effective in SQL and I'm no...

Is it considered bad design to combine the adjancey list model and the nested sets model?

I'm working on building a tree structure in MySQL and have been experimenting with different ways of representing the data. However, no matter how I slice it, there are shortcomings. The nested sets model allows me to easily select entire branches of the tree - which I need to do. However it is not so easy to select immediate childr...

What is the most efficient way to determine if a directed graph is singly connected?

I am working on an assignment where one of the problems asks to derive an algorithm to check if a directed graph G=(V,E) is singly connected (there is at most one simple path from u to v for all distinct vertices u,v of V. Of course you can brute force check it, which is what I'm doing right now, but I want to know if there's a more eff...

Create unordered list tree menu from data stored in an table with the adjacency list model...php

I need to create a tree menu of "nth" subcategories. I settled on using the adjacency list model for my table structure, because I won't be updating this table very much and this seemed the easiest to implement for my use. I want to style the output using "ul" and "li" tags...I already have a css and jquery solution to do the styling...

boost graph adjacency_list, retrieving a node's parents

I want to find in an adjacency graph from the bgl how give a Vertexdescriptor and get the set of nodes that are parents of this given node. i would like to do this in directed graph, it seems you could use a bidirectional graph but i want to be able to restrict it so that there are no cycles. ...

How do I aggregate results from an Adjacency list using PHP's SPL

I've tried using nested sets, and they become very difficult to maintain when dealing with multiple trees and lots of other complications.. I'd like to give PHP's SPL library a stab at this (btw, we are PHP 5.3, MySQL 5.1). Given two datasets: The Groups: +-------+--------+---------------------+---------------+ | id | parent | Cate...

Most efficient way of creating tree from adjacency list

I have an adjacency list of objects (rows loaded from SQL database with the key and it's parent key) that I need to use to build an unordered tree. It's guaranteed to not have cycles. This is taking wayyy too long (processed only ~3K out of 870K nodes in about 5 minutes). Running on my workstation Core 2 Duo with plenty of RAM. Any i...

Graph representation benchmarking

Currently am developing a program that solves (if possible) any given labyrinth of dimensions from 3X4 to 26x30. I represent the graph using both adj matrix (sparse) and adj list. I would like to know how to output the total time taken by the DFS to find the solution using one and then the other method. Programatically, how could i produ...

adjacency list creation , out of Memory error

Hello , I am trying to create an adjacency list to store a graph.The implementation works fine while storing 100,000 records. However,when I tried to store around 1million records I ran into OutofMemory Error : Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Arrays.java:...

ArrayList<String> NullPointerException

Am trying to solve a labyrinth by DFS, using adj List to represent the vertices and edges of the graph. In total there are 12 nodes (3 rows[A,B,C] * 4 cols[0,..,3]). My program starts by saving all the vertex labels (A0,..C3), so far so good, then checks the adjacent nodes, also no problems, if movement is possible, it proceeds to create...