Graph and Trees – Basic

Graph

A graph is a non-linear data structure composed of nodes and edges. The nodes are also known as vertices; edges are lines or arcs connecting any two nodes in the graph. There are two types of representation techniques for a graph. Thos…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Debjoty Mitra

Graph

A graph is a non-linear data structure composed of nodes and edges. The nodes are also known as vertices; edges are lines or arcs connecting any two nodes in the graph. There are two types of representation techniques for a graph. Those are:

  • Matrix: Even though we won't be using it frequently, it's still helpful to have some familiarity with it.
  • List:
    • Arrays of Vectors
    • Vectors of Vectors

Vertices and Edges

Graph

This is a graph with five Vertices. We can also call them Nodes. If we connect the vertices with lines, then the lines will be called Edges.

Graph

Basically, all the edges above are bidirectional. It means that we can go from 1 to 3 and also from 2 to 1. We can make an edge unidirectional by giving it a detection using an arrow.

Graph

Tree

A tree is a graph that has no cycles in it.

Graph

This is not a tree because there is a cycle between 1, 2, and 3. If we remove that edge, then it will become a tree.

Graph

If a tree has n nodes, then the number of edges it will have is n-1.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Debjoty Mitra


Print Share Comment Cite Upload Translate Updates
APA

Debjoty Mitra | Sciencx (2022-11-08T17:03:52+00:00) Graph and Trees – Basic. Retrieved from https://www.scien.cx/2022/11/08/graph-and-trees-basic/

MLA
" » Graph and Trees – Basic." Debjoty Mitra | Sciencx - Tuesday November 8, 2022, https://www.scien.cx/2022/11/08/graph-and-trees-basic/
HARVARD
Debjoty Mitra | Sciencx Tuesday November 8, 2022 » Graph and Trees – Basic., viewed ,<https://www.scien.cx/2022/11/08/graph-and-trees-basic/>
VANCOUVER
Debjoty Mitra | Sciencx - » Graph and Trees – Basic. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/08/graph-and-trees-basic/
CHICAGO
" » Graph and Trees – Basic." Debjoty Mitra | Sciencx - Accessed . https://www.scien.cx/2022/11/08/graph-and-trees-basic/
IEEE
" » Graph and Trees – Basic." Debjoty Mitra | Sciencx [Online]. Available: https://www.scien.cx/2022/11/08/graph-and-trees-basic/. [Accessed: ]
rf:citation
» Graph and Trees – Basic | Debjoty Mitra | Sciencx | https://www.scien.cx/2022/11/08/graph-and-trees-basic/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.