# How to remove the vertex in Graphs or LightGraphs?

**URL:** <https://discourse.julialang.org/t/how-to-remove-the-vertex-in-graphs-or-lightgraphs/70789>\
**Category:** Graphs\
**Tags:** lightgraphs, graphs\
**Created:** [November 2, 2021, 9:36am UTC](https://discourse.julialang.org/t/how-to-remove-the-vertex-in-graphs-or-lightgraphs/70789 "2021-11-02T09:36:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [November 2, 2021, 9:36am UTC](https://discourse.julialang.org/t/how-to-remove-the-vertex-in-graphs-or-lightgraphs/70789/1 "2021-11-02T09:36:00Z")

</div>

```julia
julia> myedges = [ 1 => 2,
         1 => 3,
        2 => 1,
        2 => 3,
        3 => 1,
        3 => 2,
        3 => 4,
        4 => 3,
        4 => 8,
        4 => 13,
       5 => 6,
        6 => 5,
         7 => 8,
        8 => 4,
         8 => 7,
         9 => 10,
        10 => 9,
        11 => 12,
        12 => 11,
        13 => 4,
        13 => 14,
        14 => 13]
julia> ed =Edge.(myedges)
22-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
 Edge 1 => 2
 Edge 1 => 3
 Edge 2 => 1
 Edge 2 => 3
 Edge 3 => 1
 Edge 3 => 2
 Edge 3 => 4
 Edge 4 => 3
 Edge 4 => 8
 Edge 4 => 13
 Edge 5 => 6
 Edge 6 => 5
 Edge 7 => 8
 Edge 8 => 4
 Edge 8 => 7
 Edge 9 => 10
 Edge 10 => 9
 Edge 11 => 12
 Edge 12 => 11
 Edge 13 => 4
 Edge 13 => 14
 Edge 14 => 13

julia> g = SimpleDiGraph(ed)
{14, 22} directed simple Int64 graph

```

lets remove vertex 2

```julia
julia> rem_vertex!(g, 2)
true

```

but i still see the vertex 2 in following edges

```julia

julia> collect(edges(g))
18-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
 Edge 1 => 3
 Edge 2 => 13
 Edge 3 => 1
 Edge 3 => 4
 Edge 4 => 3
 Edge 4 => 8
 Edge 4 => 13
 Edge 5 => 6
 Edge 6 => 5
 Edge 7 => 8
 Edge 8 => 4
 Edge 8 => 7
 Edge 9 => 10
 Edge 10 => 9
 Edge 11 => 12
 Edge 12 => 11
 Edge 13 => 2
 Edge 13 => 4

```

Why do i still see vertex 2 in the edges ? Shouldn’t all the edges involving vertex 2 be removed ?

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [November 2, 2021, 10:00am UTC](https://discourse.julialang.org/t/how-to-remove-the-vertex-in-graphs-or-lightgraphs/70789/2 "2021-11-02T10:00:20Z")

</div>

Unfortunately, the LightGraphs documentation seems to be currently offline. I cannot remember how it was written there (but it was stated to be careful with this operation). I think the vertex to be removed is moved to the last index and then deleted (thus, vertex 14 is missing after deletion in your example). However, I cannot remember if simply vertex 2 and 14 are swapped, or if all vertices \> 2 get a new index, i.e., i-1.

---

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [November 2, 2021, 10:02am UTC](https://discourse.julialang.org/t/how-to-remove-the-vertex-in-graphs-or-lightgraphs/70789/3 "2021-11-02T10:02:14Z")

</div>

[Getting Started · LightGraphs](https://docs.juliahub.com/LightGraphs/Xm08G/1.3.5/) here is the documentation

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [November 2, 2021, 10:13am UTC](https://discourse.julialang.org/t/how-to-remove-the-vertex-in-graphs-or-lightgraphs/70789/4 "2021-11-02T10:13:13Z")

</div>

Ok, then see the “Implementation Notes” [here](https://docs.juliahub.com/LightGraphs/Xm08G/1.3.5/generators/#LightGraphs.SimpleGraphs.rem_vertex!).
