adjacency-list

How do you convert a parent-child (adjacency) table to a nested set using PHP and MySQL?

∥☆過路亽.° 提交于 2019-11-28 16:34:29
I've spent the last few hours trying to find the solution to this question online. I've found plenty of examples on how to convert from nested set to adjacency... but few that go the other way around. The examples I have found either don't work or use MySQL procedures. Unfortunately, I can't use procedures for this project. I need a pure PHP solution. I have a table that uses the adjacency model below: id parent_id category 1 0 Books 2 0 CD's 3 0 Magazines 4 1 Books/Hardcover 5 1 Books/Large Format 6 3 Magazines/Vintage And I would like to convert it to a Nested Set table below: id left right

MySQL - Adjacency List Model - Get Depth

别说谁变了你拦得住时间么 提交于 2019-11-28 10:29:31
I have an organization table that has an id , a parent_id , and a name column. There are roughly 50k rows in this table. There is just one top level parent and the rest are all under that. In Oracle, I am able to easily retrieve the current depth of a particular organization with the level pseudocolumn: SELECT id, parent_id, level, name FROM organizations START WITH parent_id = 1 CONNECT BY PRIOR id = parent_id I am at a loss of what the proper way to do the above in MySQL is. I need to fetch the entire tree along with the node's depth in one query. There are a plethora of questions on

BFS traversal of all paths in graph using adjacency list

无人久伴 提交于 2019-11-28 06:02:09
问题 I am currently trying to traverse all paths from source to destination in a graph which uses adjacency matrix. I have been trying to do it in BFS way.Thanks for the help. I am getting only one path. How do I get to print other paths as well ? public class AllPossiblePaths { static int v; static ArrayList<Integer> adj[]; public AllPossiblePaths(int v) { this.v = v; adj = new ArrayList[v]; for (int i = 0; i < v; i++) { adj[i] = new ArrayList<>(); } } // add edge from u to v public static void

Adjacency List and Adjacency Matrix in Python

和自甴很熟 提交于 2019-11-27 12:29:40
Hello I understand the concepts of adjacency list and matrix but I am confused as to how to implement them in Python: An algorithm to achieve the following two examples achieve but without knowing the input from the start as they hard code it in their examples: For adjacency list: a, b, c, d, e, f, g, h = range(8) N = [ {b:2, c:1, d:3, e:9, f:4}, # a {c:4, e:3}, # b {d:8}, # c {e:7}, # d {f:5}, # e {c:2, g:2, h:2}, # f {f:1, h:6}, # g {f:9, g:8} # h ] For adjacency matrix: a, b, c, d, e, f, g, h = range(8) _ = float('inf') # a b c d e f g h W = [[0,2,1,3,9,4,_,_], # a [_,0,4,_,3,_,_,_], # b [_

Flatten Adjacency List Hierarchy To A List Of All Paths

喜欢而已 提交于 2019-11-27 10:03:55
问题 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 2 4 LCD 2 5 PLASMA 2 6 PORTABLE ELECTRONICS 1 7 MP3 PLAYERS 6 8 FLASH 7 9 CD PLAYERS 6 10 2 WAY RADIOS 6 What is the best method to "flatten" the above data into something like this? category_id lvl1 lvl2 lvl3 lvl4 ----------

How to create weighted adjacency list/matrix from edge list?

感情迁移 提交于 2019-11-27 10:03:20
问题 My problem is very simple: I need to create an adjacency list/matrix from a list of edges. I have an edge list stored in a csv document with column1 = node1 and column2 = node2 and I would like to convert this to a weighted adjacency list or a weighted adjacency matrix. To be more precise, here's how the data looks like -where the numbers are simply node ids: node1,node2 551,548 510,512 548,553 505,504 510,512 552,543 512,510 512,510 551,548 548,543 543,547 543,548 548,543 548,542 Any tips on

MySQL - Adjacency List Model - Get Depth

倖福魔咒の 提交于 2019-11-27 03:40:53
问题 I have an organization table that has an id , a parent_id , and a name column. There are roughly 50k rows in this table. There is just one top level parent and the rest are all under that. In Oracle, I am able to easily retrieve the current depth of a particular organization with the level pseudocolumn: SELECT id, parent_id, level, name FROM organizations START WITH parent_id = 1 CONNECT BY PRIOR id = parent_id I am at a loss of what the proper way to do the above in MySQL is. I need to fetch

How to transform a MSSQL CTE query to MySQL?

穿精又带淫゛_ 提交于 2019-11-26 16:37:31
in my MySQL schema, I have the category(id, parentid, name) table In the MSSQL, I have that CTE query (to build a category tree from the bottom up for a supplied category ID: with CTE (id, pid, name) as ( select id, parentid as pid,name from category where id = 197 union all select CTE.pid as id , category.parentid as pid, category.name from CTE inner join category on category.id = CTE.pid ) select * from CTE How to 'transform' that query to MySQL ? Jon Black Unfortunately MySQL doesn't support CTE (Common Table Expressions). This is long overdue IMO. Often, you can just use a subquery instead

What is better, adjacency lists or adjacency matrices for graph problems in C++?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 07:53:26
问题 What is better, adjacency lists or adjacency matrix, for graph problems in C++? What are the advantages and disadvantages of each? 回答1: It depends on the problem. Adjacency Matrix Uses O(n^2) memory It is fast to lookup and check for presence or absence of a specific edge between any two nodes O(1) It is slow to iterate over all edges It is slow to add/delete a node; a complex operation O(n^2) It is fast to add a new edge O(1) Adjacency List Memory usage depends on the number of edges (not