663 questions
2
votes
2
answers
103
views
Mutual Friends using Graph Data Structure
I’m trying to implement a mutual friends feature using a graph data structure represented as an adjacency list in Python.
Each node represents a person, and each edge represents a friendship (an ...
0
votes
2
answers
213
views
How to build a nested adjacency list from an adjacency list and a hierarchy? [closed]
I have a simple adjacency list representation of a graph like this
{
1: [2, 3, 4],
2: [5],
3: [6, 9],
4: [3],
5: [3],
6: [7, 8],
7: [],
8: [],
9: []
}
which looks ...
0
votes
1
answer
31
views
Storing and accessing edge data in a graph characterized by its adjacency list representation in C++
I am currently solving a problem concerning graphs in Data Structures in C++. The exercise says I should "build on the adjacency list representation of a graph, so that a field named data of type ...
1
vote
1
answer
115
views
Does malloc assign memory in the same location if you use the same variable name again on every iteration of a loop?
I am writing code to take in a weighted adjacency list in C. Each edge is stored in the form of a struct. I created an array of pointers where each pointer leads to the list for a node. Here's what I ...
1
vote
2
answers
178
views
Finding quad faces in a planar graph / 2D mesh
Description:
I have a set of coordinate points and an adjacency list that describes how each point (node) is connected to other points. Using these, I plotted a graph using NetworkX in Python.
Here ...
2
votes
1
answer
168
views
How to write JS recursive function to trace sub-graphs, with adjacency list, for a list of initial nodes
Aim:
The aim is to develop a function that quickly traces sub-graphs for a list of nodes, given an existing adjacency list implementation, and returns a list of connected ID's in addition to the ...
1
vote
1
answer
67
views
Turning a length k array of length l lists ranking n items into a graph with the vertices as the n items in O(kl) time
The problem statement is that there is a array with indices 1 to k which each contain a list that ranks l of n total items via order (i.e. list 1-2-3-4 is equivalent to 1>2>3>4). Is it ...
2
votes
1
answer
77
views
Python code for calculation of very large adjacency matrix crashes using networkx MultiDiGraph
I need to calculate the adjacency matrix (in flat format) of a very large graph. Number nodes is 54327 and number edges is 46 million. The input are 46 million edges, so input looks like
1 6
2 7
1 6
3 ...
1
vote
1
answer
71
views
Error: calling 'EDGE' with incomplete return type 'struct ptrEdge' on Depth-First Search Code
I'm working on a college assignment, and in order to do the assignment, I need to have a program that simulates Depth-First Search for graphs represented with adjacency lists. To be clear; the ...
0
votes
1
answer
111
views
Trying to create edge list (weighted) to create adjacency list
I am storing the open coords as two attributes in one list:
self.x, self.y = []
My attempt at an edge list (lifted from stack overflow lol):
edge = []
for i in self.x, self.y:
for ...
0
votes
0
answers
102
views
Weighted adjacency list in Python from a graph
I want to create a weighted adjacency list (with weight=length) in Python from a graph that I downloaded.
Now, I struggle with creating such a list
of the following form:
adjacency_list = { 'A': [('C',...
-1
votes
1
answer
66
views
Deleting multiple occurring edges in a graph
I am trying to delete the multiple occurring edges in a graph. Each vertex in the graph can have multiple outgoing edges to the same destination. like this one (this is the adjacency list). For ...
1
vote
1
answer
75
views
SQLAlchemy: How to join a second table to a hierarchical table and make the join available to all levels of the query?
I'm try to join a second table to hierarchical table in SQLAlechemy, and have the results of that join available to all levels the query.
class NodeType(Base):
id = Column(Integer, primary_key=...
1
vote
1
answer
100
views
big graph storing in adjacency list
My project is to create a graph with 1-2 milions nodes using adjacency list. Input data is from text file. I need to count the connected components and max/min degree of vetices of each components. My ...
1
vote
1
answer
76
views
Cannot run graph with over 1 milion vertices using adjacency list in C
I want to create a graph with 2-3 million vertices using an adjacency list. The input is created randomly. When I ran a version that only prints out the increasing numbers of edges, it worked ...
2
votes
1
answer
382
views
laravel adjacency list - get subquery exists depth
rootCategory is HasOne relation:
public function rootCategory()
{
return $this->hasOne(PartnerCategory::class, 'partner_id', 'id')->where('partner_category_main', 1);
}
then:
$categories = ...
0
votes
1
answer
91
views
Create adjacency matrix from a list of Id and the corresponding club they are part of
The structure of the data in Stata looks something like this:
id club_id
1 1
2 1
3 2
4 2
5 2
6 3
7 3
8 3
9 3
I assume that the network ...
0
votes
1
answer
232
views
How to optimize memory footprint of a graph with large amount of vertex?
I was tasked my my prof to solve a graph question. However, he hinted that one of his hidden test cases that I failed have over 80k, my code would fail as it exceeded the amount of memory that was ...
1
vote
1
answer
90
views
MySQL validating parents by children
I am programming in Visual Studio, but I need to perform validation on mySQL (v8.0.28) table and I guess it would be faster if it will be performed as procedure on server. Unfortunatelly, my MySQL ...
0
votes
0
answers
49
views
Preventing loops when changing parent of a node in the adjacency list model of MySQL?
I want the user to be able to change the parent of a node. However, there has to be some check so that the loop situation does not arise. For eg. Parent of 9 is 8. Parent of 8 is 7. User might assign ...
0
votes
0
answers
107
views
Extracting adjacency list from 2D and 3D skeleton images in python
I have skeletonized 2D and 3D images as follows:
2D skeleton
3D skeleton
Now, I want to analyze the skeletons in python and obtain the following information:
The location of nodes.
The adjacency list....
-3
votes
1
answer
87
views
How to clone adjacency list in c++?
I have trying to make a clone of adjacency list in c++. But couldn't possibly do so.
I have declared using:
vector<int> adj[N]; // N is the number of vertices
How do I make the clone of this ...
0
votes
1
answer
106
views
Space complexity of adjacency lists
Can anyone explain to me why the space complexity of adjacency lists is Theta(m + n)?
Example graph:
a: b, c, d
b : e
c : d, e
d : empty
e : a
So here n = 5, m = 7.
Even crazier: The professor told us ...
0
votes
1
answer
392
views
Assuming that this graph is stored in an adjacency list. What would the time complexity be and how would we determine it in the worst case?
Let G = (V, E) be an undirected, connected graph with n vertices and m > n edges. All vertices are initially un-marked and they are stored in an array V . Consider the following algorithm:
...
-1
votes
1
answer
165
views
how to program Prim's and Kruskal's algorithm using adjacency lists in C
I have understood and implemented Prim's and Kruskal's algorithm using adjacency matrix but I am not understanding how to write a program using adjacency lists
I tried creating 2 matrices one for min ...
0
votes
1
answer
66
views
Develop equivalence relations among pairs of strings
I have a set of <string, string> pairs which represents equivalency among them:
[(“Player1”, “Player2”), (“Player3”, “Player4”), (“Player2”, “Player3”), (“Player11”, “Player13”)]
This means, “...
1
vote
1
answer
542
views
Minimum cost path on a undirected weighted graph using an adjacency list
I have implemented a minimum cost path function to my undirected weighted graph using an adjacency list. My approach of the minimum cost path function does not use a priority queue. My goal is to ...
0
votes
1
answer
119
views
Adding Nodes to a graph displays object instead of string (adjacency list)
I'm learning how to create a graph using an adjacency list on Python. My current problem is when trying to add a node to the list, it displays the Node object at 0x0000.... instead of a string. When I ...
0
votes
0
answers
41
views
Reading data to make adjacency list with two weights
I'm making an adjacency list to represent a graph of roads, there are two kinds of weights (length and capacity) and for some reason this code never exits the for loop. it gets stuck on the cin for ...
0
votes
1
answer
133
views
Finding downstream member of tree within SQL Hierarchy Query?
I have a binary tree with devices attached to nodes (connected by an adjacency list). I'm trying to compare a device's value to the device downstream of it. I'm having trouble getting the downstream ...
-1
votes
1
answer
315
views
Creating an adjacency list class in Python
I was wondering how to create an adjacency list class
Here is what I have so far:
class AdjNode:
def __init__(self, value):
self.vertex = value
self.next = None
class Graph:
...
0
votes
1
answer
211
views
adding items to a dictionary
I'm converting adjacency matrix to adjacency list. I need to add items to a dictionary and return it in a function, but output is the only last item. How to makes an output full list of items?
def ...
0
votes
0
answers
46
views
Compare character by character of strings from an array efficiently
Palavras = (char***)malloc(maxLen*sizeof(char**));
matrizAdj = (int***)malloc(maxLen*sizeof(int**));
for(i=0; i<maxLen; i++){
Palavras[i]= (char**)malloc(NMax_Palavras[i]*sizeof(char*));
...
0
votes
0
answers
67
views
Converting matrix(list) to a dictionary
I need to convert format of my adjacency from list to a dictionary with following skeleton:
def adjmat_to_adjlist(adjmat: List\[List\[int\]\]) -\> Dict\[int,
List\[int\]\]:
pass
Here's what i ...
0
votes
1
answer
424
views
Reading a text file into an undirected graph using adjacency list
I am trying to create an undirected graph using a text file with the following format:
0 5
4 3
0 1
9 12
6 4
5 4
0 2
11 12
I made a method to read the file and insert nodes/vertices into an arraylist. ...
0
votes
1
answer
75
views
Inserting hierarchal data into adjacency table
I have a hierarchy table:
CREATE TABLE tmp.myTable
(
[Id] int IDENTITY(1,1) PRIMARY KEY ,
[Desc] nvarchar(50) NOT NULL,
[Lvl] TINYINT NOT NULL,
[ParentId] int REFERENCES ...
0
votes
1
answer
409
views
Graph - Adjacency List solved as Linked List
What does this line do?
node.next = self.graph[src]
EX: [1:2]
here I know how to make 2 as a node, then make index 1 equal it, but what if i have [1:3] too, how to add 3 to 2?
Here's the full code of ...
1
vote
1
answer
118
views
Error in DFS implementation of an undirected graph (based on Cormen algorithm) using adjacency list in C
I have written this code for DFS traversal of graph represented using adjacency list in C. It is based on algorithm given in Cormen. The issue with this code is the while loop within "dfs_visit&...
1
vote
0
answers
129
views
Space complexity of Adjacency list and Adjacency matrix
I am studying the MIT introduction to algorithms (6.006) course and I could not understand the space complexity of representing a graph in the Adjacency matrix and Adjacency list.
I have copied the ...
0
votes
2
answers
233
views
Adjacency List in graph
Hi I am try to implement a graph using adjacency list using following code.
#include<iostream>
#include<list>
#include<vector>
#include<unordered_map>
using namespace std;
...
0
votes
1
answer
219
views
How to turn a directed graph to undirected graph?
My method "addEdge" adds a node to the adjacency list of the selected node, but I want the method to add the selected node to its adjacency list as well and turn it into an undirected graph.
...
1
vote
0
answers
61
views
How to compare elements in the same list efficiently and create an adjaney list
I have an excel file that contains ~74000 entries, which are then stored into an array. I want to compare each element with each other (i.e compare [0] with [1], [2]. [3] .... then compare [1] with [0]...
8
votes
1
answer
4k
views
How do I construct a self-referential/recursive SQLModel
I want to define a model that has a self-referential (or recursive) foreign key using SQLModel. (This relationship pattern is also sometimes referred to as an adjacency list.) The pure SQLAlchemy ...
0
votes
1
answer
688
views
Getting full path in C++ adjacency list Dijkstra
I want to get full path in adjacency list Dijkstra algorithm using C++ queue. Graph edges are oriented.
Dijkstra algorithm works fine and I understand why. However getting full path is a bit more ...
0
votes
0
answers
207
views
I wrote a function that calculates all simple paths for an undirected graph, and the total weight sum of all. How do i store them now?
I wrote some code that takes as input a graph (weighted) i've made and it calculates and prints all possible simple paths, and it also prints a sum of the total weight cost of each path.
I want to be ...
1
vote
3
answers
127
views
Segmentation fault on vector class implementation
As for many coding tests STL is not allowed so I am trying to implement vector class. To represent the graph I am using an adjacency list. It's giving me segmentation fault at new_allocation method. ...
1
vote
0
answers
150
views
unknown run-time exception in kattis problem "marbles on a tree"
I've been trying to implement this solution (https://algorithmist.com/wiki/UVa_10672_-_Marbles_on_a_tree) to this kattis problem (https://open.kattis.com/problems/marblestree). This is a graph theory ...
1
vote
2
answers
64
views
Divide the number into different groups according to the adjacency relationship
I have a dataframe that stores adjacency relations. I want to divide numbers into different groups according to this dataframe. The dataframe are as follows:
df = data.frame(from=c(1,1,2,2,2,3,3,3,4,4,...
0
votes
2
answers
221
views
Why space complexity of adjacency list representation is O(V+E) not O(E)?
#include<bits/stdc++.h>
using namespace std;
const int N=1e3;
vector <int> graph2[N];
int main(){
int n,m;
cin>> n>>m;
for(int i=0;i<m;i++){
int v1,v2;
...
0
votes
1
answer
523
views
Preventing cyclic Parent/Child data when using Entity Framework Core
Given a data model which contains reference to its parent (adjacency list):
class Foo
{
public int Id { get; set; }
virtual Foo Parent { get; set; }
}
How can I guarantee that no cyclic ...