Skip to content

NelsonBN/algorithms-data-structures-graphs-representation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Algorithms and Data Structures - Graphs Representation

Adjacency Matrix

Asymptotic Complexity

  • Time complexity:
    • Insertion: O(1)
    • Deletion: O(1)
  • Space complexity: O(V^2)

Pros

  • Simple to implement
  • Fast to access edge (u, v), O(1), fast to add and remove edges

Cons

  • Space complexity is O(V^2)
  • Its not efficient for sparse graphs

Demos

Adjacency List

Asymptotic Complexity

  • Time complexity:
    • Insertion: O(V) using list, O(1) using Hash Table
    • Deletion: O(V) using list, O(1) using Hash Table
  • Space complexity: O(V + E)

Pros

  • Space complexity is O(V + E)
  • Efficient for sparse graphs

Cons

  • Slow to access edge (u, v), O(V) using list, but can be O(1) using Hash Table

Demos

Edge List

Asymptotic Complexity

  • Time complexity:
    • Insertion: O(1)
    • Deletion: O(E)
  • Space complexity: O(E)

Pros

  • Space complexity is O(E)
  • Fast to add edges

Cons

  • Slow to access edge (u, v), O(E)

Demos

References

About

Algorithms and Data Structures - Graphs Representation

Topics

Resources

License

Stars

Watchers

Forks

Languages