# Dynamic graphs

**URL:** https://discourse.julialang.org/t/dynamic-graphs/43097
**Category:** New to Julia
**Created:** [July 15, 2020, 2:13am UTC](https://discourse.julialang.org/t/dynamic-graphs/43097 "2020-07-15T02:13:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)
#### Post date: [July 15, 2020, 2:13am UTC](https://discourse.julialang.org/t/dynamic-graphs/43097/1 "2020-07-15T02:13:40Z")

</div>

I have been using `LightGraphs.jl` successfully, together with `MetaGraphs.jl`, and I recommend it to everybody.  
I am toying with the idea of dynamic networks, where links are created and destroyed according to various prescriptions relating to degrees, and subject to different probability distributions. I know that one can add and remove edges from graphs using `LightGraphs`, but how efficiently. I removing edges an `O(nv(graphs))` operations, or `O(1)`? Is it possible to remove an edge between two specific nodes? Of course, I can perform some experiments, but perhaps somebody has insight based on past experience. Also, are there alternative approaches I should consider? I am moving towards temporal networks.

Thanks!

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [July 15, 2020, 2:25am UTC](https://discourse.julialang.org/t/dynamic-graphs/43097/2 "2020-07-15T02:25:16Z")

</div>

In a graph `g`, edges are stored in `g.fadjlist` (“forward adjacency list”), which is a sorted vector of nodes connected to each node i.

Removing an edge between nodes i and j thus requires O(k) operations, where k = \max(\deg i, \deg j), and \deg i is the degree (number of neighbours) of node i.

---

<div class="post-metadata">

### Author: ![pjentsch0](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjentsch0/32/15148_2.png) [@pjentsch0](https://discourse.julialang.org/u/pjentsch0)
#### Post date: [July 15, 2020, 2:29am UTC](https://discourse.julialang.org/t/dynamic-graphs/43097/3 "2020-07-15T02:29:36Z")

</div>

depending on the size of your graphs, adjacency matrices might be the best option for fast edge modification

---

<div class="post-metadata">

### Author: ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)
#### Post date: [July 15, 2020, 2:51am UTC](https://discourse.julialang.org/t/dynamic-graphs/43097/4 "2020-07-15T02:51:57Z")

</div>

Keeping in mind that I could spend time on experiments, my graphs have about 250,000 nodes and about 1.5 million edges.  
When you say adjacency matrix, it would have to be in sparse format. In which case, the cost is not immediately clear. If I could store the full adjacency matrix, then of course, the cost is`O(1)`.
