# JavaScript Data Structures: Graphs (pt. 1)

Surprise! I’m in Korea — and currently I’m undergoing the mandatory 2-week quarantine at a government facility (unfortunately, I do not have Korean citizenship since I was born in America, and I’m here on visa-free travel aka without a long-term visa). Jet lag is *so* real.

Today, I’ll be introducing another JavaScript data structure — the graph. To be honest, I’m not confident in my knowledge of graphs, but that’s why I’m writing this post. So I can understand it better and help others understand it too!

Let’s get started (before I fall asleep)!

# Graphs

Graphs kind of look like trees — in the sense that they have nodes and nodes can be connected to other nodes. However, the main difference between graphs and trees is that graphs are less restricted. Unlike trees, graphs do not have parent or child nodes — nodes can be connected to other nodes and even itself!

In graphs, nodes can also be called **vertices**. The *connection between one node to another node* is called an **edge**. The number of edges a node has is called the **degree**.

Graphs can be either **undirected** or **directed**. If a graph is undirected, it means that the edges are bi-directional (meaning the node is connected to/pointed at each other). If a graph is directed, that means node A is connected to node B in one direction, but node B is not connected back to node A. However, in a directed graph, some edges can be undirected.

Graphs can also have **cycles** or be **acyclic **(not have cycles). A graph with cycles means that the flow of the graph can have the *same node occur more than once*.

The last main trait that I will be discussing is regarding the connectivity of the graph. Not all nodes have to be connected in the graph — meaning, some *nodes can be isolated or separated* from the main graph. In this scenario, the graph is **disconnected**. Graphs can also be **connected**, where *all nodes have at least one edge*, or **complete**, where *all nodes are connected to each other*.

And those are the basics of a graph! There is so much more to uncover with graphs, like how to implement and use them, which I will go over another time.