Data Structures — Graphs

Anthony Johnson
3 min readMay 12, 2020

--

So, Graphs, and we’re not talking bars. A Graph in Computer Science is collection of data that may or may not be connected, for example you’re in a library the library is divided up into a few sections, you have a movie section, a children's section, a coffee section, and of course riddled throughout the “Book” store are numerous collections of books; we’re in Barns and Nobles (give me a clap if you love Barnes and Nobles).

So, we have a few sections that are completely unrelated and have completely different “Roots” but even within those subjects we have a lot of overlap;

  • Black — Barnes and Nobles.
  • Red — Books
  • Blue — Movies
  • Green-Children Toys
  • Yellow — “Starbucks”

So we have a visual representation of our graph, you will notice that we have our book store “Barnes and Nobles” and it is connected to a Book node, a Movie node, and a Children’s Toys node. The Book store has ownership or relation with all of this items or objects, we have a node in graph that isn’t connected to anything, our Coffee Shop is renting its own space and its ownership lies elsewhere. it is part of the internal Building graph, but it is not directly connected the same way the bookstores products are.

Also, something unique about a graph, multiple connections, we have Books that are related to movies and Movies that have relationship to toys. And, again, the coffee shop has zero connection to the bookstore outside of the face that it resides inside of the same building.

Graphs do come in a few different flavors when regarding how they are set up and organized in your code. the three main types are Adjacency Lists, Adjacency Matrix, and an Indices Matrix.

To wrap it up a graph is just a collection of data where each data-point can hold its on relationship with any other data-point , the points in the graph do not need to have relation for example if we had a food truck in-front of the TikTok building in Los Angeles, the food truck is not a part of TikTok, but it may have a relation to some of the employees and it is in the same area if we were graphing the area of TikTok.

This is an extremely short overview of graphs, and I hope it eliminates some fear when approaching them. they are like linked-lists with a little extra.

This is a very short article. I will be going over some code that will better illustrate the graph tomorrow May 12th 2020. Questions Comments, post below.

--

--