<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>unweighted graph Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/unweighted-graph/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/unweighted-graph/</link>
	<description></description>
	<lastBuildDate>Mon, 09 Nov 2026 06:56:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>unweighted graph Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/unweighted-graph/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Representing a Directed Unweighted Graph with an Adjacency Matrix</title>
		<link>https://www.NeuralLantern.com/representing-a-directed-unweighted-graph-with-an-adjacency-matrix/</link>
					<comments>https://www.NeuralLantern.com/representing-a-directed-unweighted-graph-with-an-adjacency-matrix/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 09 Nov 2026 06:56:48 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[adjacency matrix]]></category>
		<category><![CDATA[adjacency matrix tutorial]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[directed graph]]></category>
		<category><![CDATA[directed graphs]]></category>
		<category><![CDATA[graph representation]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[unweighted graph]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=444</guid>

					<description><![CDATA[<p>A directed unweighted graph can be stored in an adjacency matrix where each row is a starting node and each column is an ending node. A value of 0 means no edge and 1 means an edge exists. Because the structure is really a contiguous one dimensional array under the hood, reading or writing any cell is constant time. Self connections are not implied unless explicitly added, and the matrix is not symmetric the way an undirected graph matrix would be.</p>
<p>The post <a href="https://www.NeuralLantern.com/representing-a-directed-unweighted-graph-with-an-adjacency-matrix/">Representing a Directed Unweighted Graph with an Adjacency Matrix</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Representing a Directed Unweighted Graph with an Adjacency Matrix" width="1380" height="776" src="https://www.youtube.com/embed/oa5PfA1gANo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Learn how to represent a directed unweighted graph using an adjacency matrix. We cover why a two dimensional matrix is really just a one dimensional array under the hood, making cell access and updates extremely fast. For directed graphs the starting node is the row and the ending node is the column. A zero means no connection and a one means an edge exists. Self connections are not implied by default. Adding or removing an edge is constant time. Directed graphs do not produce a symmetric matrix like undirected ones. This is one practical way your program can store and work with a graph. If you have been following the previous videos on undirected graphs this builds directly on that. The next video will cover directed weighted graphs with an adjacency matrix. Thanks for watching and I hope you picked up something useful.</p>



<p class="wp-block-paragraph">00:00 Intro to Directed Unweighted Graphs<br>00:01 Matrix Stored as Contiguous 1D Array<br>03:09 Building the Adjacency Matrix<br>04:25 Filling Outgoing Edges Node by Node<br>09:43 Directed Graphs Are Not Symmetric<br>10:36 Adding a New Edge<br>11:08 Adding Self-Connections<br>11:53 Removing an Edge<br>13:04 Adding Bidirectional Edges<br>15:28 Next Video and Outro</p>



<p class="wp-block-paragraph">=-=-=-=-=-=-=-=-=</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li><a href="https://www.NeuralLantern.com/social">https://www.NeuralLantern.com/social</a></li>



<li>Twitter / X: <a href="https://x.com/NeuralLantern">https://x.com/NeuralLantern</a></li>



<li>Rumble: <a href="https://rumble.com/c/c-3696939">https://rumble.com/c/c-3696939</a></li>



<li>BitChute: <a href="https://www.bitchute.com/channel/pg1Pvv5dN4Gt">https://www.bitchute.com/channel/pg1Pvv5dN4Gt</a></li>



<li>Daily Motion: <a href="https://www.dailymotion.com/neurallantern">https://www.dailymotion.com/neurallantern</a></li>



<li>Minds: <a href="https://www.minds.com/neurallantern/">https://www.minds.com/neurallantern/</a></li>



<li>Odysee: <a href="https://odysee.com/@NeuralLantern:5">https://odysee.com/@NeuralLantern:5</a></li>
</ul>



<p class="wp-block-paragraph">Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: <a href="https://ko-fi.com/neurallantern">https://ko-fi.com/neurallantern</a></li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to the Blog: <a href="https://www.NeuralLantern.com">https://www.NeuralLantern.com</a></li>



<li>Watch the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there. Let&#8217;s talk about representing a directed, unweighted graph inside your</p>



<p class="wp-block-paragraph">machine using an adjacency matrix. It&#8217;s going to be fun.</p>



<p class="wp-block-paragraph">Okay, sorry about that. Anyway, so I hope you&#8217;ve been watching my previous videos.</p>



<p class="wp-block-paragraph">We covered already how to do an undirected weighted graph and also unweighted graph</p>



<p class="wp-block-paragraph">using an adjacent</p>



<p class="wp-block-paragraph">and also unweighted graph using an adjacency matrix we&#8217;re going to basically represent a graph</p>



<p class="wp-block-paragraph">inside of the machine like this is one of the ways that your machine can do it we&#8217;re not going to</p>



<p class="wp-block-paragraph">talk about code exactly but you know kind of allude to code but this is this is a really good</p>



<p class="wp-block-paragraph">way to you know get started in practicing the concept okay first thing i want to say i&#8217;ve said</p>



<p class="wp-block-paragraph">this in my previous videos i&#8217;m sorry if you&#8217;ve been watching all of them is that this matrix</p>



<p class="wp-block-paragraph">this two-dimensional matrix it&#8217;s really just a one-dimensional array think about this we have</p>



<p class="wp-block-paragraph">Thank you for watching.</p>



<p class="wp-block-paragraph">array think about this we have some numbers in an array I&#8217;m going to put six numbers in there</p>



<p class="wp-block-paragraph">we could just as easily represent this as a two-dimensional matrix a two-dimensional array</p>



<p class="wp-block-paragraph">right it&#8217;s the same amount of numbers what&#8217;s really happening under the hood when you have</p>



<p class="wp-block-paragraph">a two-dimensional array is your computer just has it as a one-dimensional array so the question is</p>



<p class="wp-block-paragraph">why is that useful oh hang on okay anyway so what i wanted to say is that you see</p>



<p class="wp-block-paragraph">So what I wanted to say is that you see a two-dimensional matrix,</p>



<p class="wp-block-paragraph">but really what&#8217;s happening inside your computer is a one-dimensional matrix.</p>



<p class="wp-block-paragraph">I&#8217;m just going to make a one-dimensional matrix.</p>



<p class="wp-block-paragraph">I&#8217;m going to say we&#8217;re putting numbers in the matrix.</p>



<p class="wp-block-paragraph">I&#8217;m just going to put like, you know, six hashes or pound signs or hashtags in the modern era.</p>



<p class="wp-block-paragraph">So a one-dimensional array could be represented as a two-dimensional matrix</p>



<p class="wp-block-paragraph">if we just reformat it a little bit.</p>



<p class="wp-block-paragraph">last part of that first array on a second line that&#8217;s what&#8217;s happening in the computer</p>



<p class="wp-block-paragraph">even if you&#8217;re working with a two-dimensional array in your computer it&#8217;s still just a</p>



<p class="wp-block-paragraph">one-dimensional array under the hood which means it&#8217;s incredibly fast to access one particular</p>



<p class="wp-block-paragraph">index not necessarily to scooch things remove things and add things but if i wanted to go to</p>



<p class="wp-block-paragraph">index three and a one-dimensional array if you know time complexities already that&#8217;s really fast</p>



<p class="wp-block-paragraph">That&#8217;s constant time. We&#8217;ll do time complexities in another video, but um if</p>



<p class="wp-block-paragraph">but um if i wanted to access you know a certain row in a certain column intuitively you think</p>



<p class="wp-block-paragraph">well i gotta like scan down and scan to the right uh so maybe it&#8217;s slower but it&#8217;s not because it&#8217;s</p>



<p class="wp-block-paragraph">still just going to be math to find exactly the right offset in uh your two-dimensional matrix</p>



<p class="wp-block-paragraph">because it&#8217;s really a one-dimensional array all of the items in this array i didn&#8217;t say this in</p>



<p class="wp-block-paragraph">previous videos all the items in this array are contiguously allocated so all we really have to</p>



<p class="wp-block-paragraph">do is compute an offset from some</p>



<p class="wp-block-paragraph">compute an offset from some starting memory location so it&#8217;s incredibly fast</p>



<p class="wp-block-paragraph">to read a cell in this matrix and to modify a cell in this matrix you&#8217;ll see in a second</p>



<p class="wp-block-paragraph">that&#8217;s well you&#8217;ll see in several minutes why that&#8217;s one useful feature of a of an adjacency</p>



<p class="wp-block-paragraph">matrix okay so adjacency matrix uh suppose you&#8217;re presented with this matrix you see</p>



<p class="wp-block-paragraph">i&#8217;m sorry with this diagram you see right here this is a graph it&#8217;s got direction on all the</p>



<p class="wp-block-paragraph">edges i really hope i didn&#8217;t forget any particular edge i think i&#8217;ve got arrows on all of them</p>



<p class="wp-block-paragraph">think i&#8217;ve got arrows on all of them we&#8217;ve got nodes and edges and i just</p>



<p class="wp-block-paragraph">need to figure out how can i put that into a matrix so my computer</p>



<p class="wp-block-paragraph">my program understands the graph and it it has a representation of the graph</p>



<p class="wp-block-paragraph">so with directed graphs the start row uh sorry the start node and the end node</p>



<p class="wp-block-paragraph">actually matter a lot in my other videos where we talked about</p>



<p class="wp-block-paragraph">undirected graphs we could just easily swap the row and the column</p>



<p class="wp-block-paragraph">in this matrix and it didn&#8217;t really make a difference because the whole matrix</p>



<p class="wp-block-paragraph">was going to end up being a mirror anyway.</p>



<p class="wp-block-paragraph">was going to end up being a mirror anyway but that&#8217;s not going to happen this time so what i&#8217;m</p>



<p class="wp-block-paragraph">going to say for the way that i like to do things is the starting node is the row and the ending</p>



<p class="wp-block-paragraph">node is the column so this is also an unweighted diagram an unweighted graph so we don&#8217;t really</p>



<p class="wp-block-paragraph">need to store floats or infinities or anything like we did in the other video we can just say</p>



<p class="wp-block-paragraph">that no connection means no connection is a zero and yes connection is a one of course you could</p>



<p class="wp-block-paragraph">You could still do that with floats if you want to,</p>



<p class="wp-block-paragraph">of course you could still do that with floats if you want to but whatever you could have a a matrix</p>



<p class="wp-block-paragraph">of booleans if you really wanted to like true and false and true and false but you know for this</p>



<p class="wp-block-paragraph">diagram we&#8217;re going to say 0 and 1. so i&#8217;m going to start with node number one and node number one</p>



<p class="wp-block-paragraph">therefore is going to be the the source node and i&#8217;m going to see where does where does it go out</p>



<p class="wp-block-paragraph">to what edges are outbound from the number one so the start node is the one that means the row is</p>



<p class="wp-block-paragraph">one that i&#8217;m working with and the destination nodes or the end nodes or the sync nodes those</p>



<p class="wp-block-paragraph">Those will be the calls.</p>



<p class="wp-block-paragraph">nodes are the sync nodes those will be the columns so i&#8217;m not really going to look at how six is</p>



<p class="wp-block-paragraph">coming into one because i&#8217;m only interested right now in what uh what one starts uh in terms of an</p>



<p class="wp-block-paragraph">edge you know what edges come out of one so one forget about the six and the two those are incoming</p>



<p class="wp-block-paragraph">edges i&#8217;m just going to look at the outgoing edges so one goes out to three and four and five so</p>



<p class="wp-block-paragraph">by default in our diagrams at least at this point we&#8217;re going to say</p>



<p class="wp-block-paragraph">our diagrams at least at this point we&#8217;re going to say that self connections are not implied</p>



<p class="wp-block-paragraph">meaning by default if i don&#8217;t see an actual edge on the diagram going from one back into one then</p>



<p class="wp-block-paragraph">i&#8217;m going to say one is not connected to itself so i&#8217;m gonna put a zero to say there&#8217;s no connection</p>



<p class="wp-block-paragraph">uh one going to uh the two that&#8217;s not happening because two is actually going into one</p>



<p class="wp-block-paragraph">so i&#8217;m going to put another zero then uh there uh one going to three that is happening</p>



<p class="wp-block-paragraph">uh one going to three that is happening so i&#8217;m gonna put a one so one does have an outbound</p>



<p class="wp-block-paragraph">connection or an edge to three so i&#8217;m gonna put a one in that row and column</p>



<p class="wp-block-paragraph">one going to four uh yes so i&#8217;m gonna put a one one going to five uh yes so i&#8217;m gonna put a one</p>



<p class="wp-block-paragraph">there one going to six uh no so i&#8217;m gonna put a zero there i should have put you know</p>



<p class="wp-block-paragraph">edges that go back and forth uh to make this more interesting but you can probably imagine</p>



<p class="wp-block-paragraph">imagine well i&#8217;ll add that maybe later in this video so one going to seven uh nope someone put</p>



<p class="wp-block-paragraph">a zero so that&#8217;s the first row we represented all of the outbound edges from one to some other node</p>



<p class="wp-block-paragraph">and we used a zero to say it doesn&#8217;t exist and a one to say it does exist so then we just move on</p>



<p class="wp-block-paragraph">to the two so if i&#8217;m focusing on the two node then i&#8217;m on the two row and its outgoing connections</p>



<p class="wp-block-paragraph">are going to be represented in the columns.</p>



<p class="wp-block-paragraph">in the columns so does two go to one yes I&#8217;m going to put a one there does two go to itself</p>



<p class="wp-block-paragraph">self-connections are not implied at this point and then uh hang on a second</p>



<p class="wp-block-paragraph">does two go to three um nope because three goes into two and not the other way around</p>



<p class="wp-block-paragraph">uh we&#8217;ll add those other edges in a second does two go to four nope does two go to five</p>



<p class="wp-block-paragraph">nope there&#8217;s two</p>



<p class="wp-block-paragraph">nope does two go to six um i don&#8217;t see that so i&#8217;m going to say nope and then does two go to seven</p>



<p class="wp-block-paragraph">uh yes i&#8217;m going to put a one so now we&#8217;re done with the two um this is a directed graph by the</p>



<p class="wp-block-paragraph">way so like i said about my previous videos we will not see a mirror at least we won&#8217;t necessarily</p>



<p class="wp-block-paragraph">see a mirror we might accidentally make a mirror depending on what the graph is but we&#8217;re not going</p>



<p class="wp-block-paragraph">to see a mirror. So we have to do this whole graph with no shortcuts. So the</p>



<p class="wp-block-paragraph">shortcuts so the three uh does it go out to the one that&#8217;s a no does it go out to the two</p>



<p class="wp-block-paragraph">um where the heck is the three oh yeah it goes out to the two</p>



<p class="wp-block-paragraph">uh no implied self-connections three goes to the four nope three goes to the five yes</p>



<p class="wp-block-paragraph">3 goes to the 6</p>



<p class="wp-block-paragraph">nope</p>



<p class="wp-block-paragraph">3 goes to the 7</p>



<p class="wp-block-paragraph">uh three goes to the seven nope okay so now we&#8217;re done with the three</p>



<p class="wp-block-paragraph">and then we&#8217;ll say now does four go to the one i&#8217;m looking at the four where the heck&#8217;s the four</p>



<p class="wp-block-paragraph">i&#8217;m losing the four oh four doesn&#8217;t go anywhere except for the seven so i can actually just put</p>



<p class="wp-block-paragraph">like zeros in this whole thing you know just to save a little time oh god there we go but the</p>



<p class="wp-block-paragraph">four does go to the seventh. I&#8217;m going to put a one right there. Okay.</p>



<p class="wp-block-paragraph">the sevens i&#8217;m gonna put a one right there okay so uh the five um it has outbound connections i&#8217;m</p>



<p class="wp-block-paragraph">gonna i&#8217;m gonna be cheap here i&#8217;m gonna be cheesy the five goes to six and seven so i&#8217;m just gonna</p>



<p class="wp-block-paragraph">put zeros everywhere else so whoops in fact i probably could have just copied that whole row</p>



<p class="wp-block-paragraph">of zeros and then just overwrote the last two but i guess so the five goes to the six that&#8217;s a yes</p>



<p class="wp-block-paragraph">The 5 goes to the 7. That&#8217;s a yes also.</p>



<p class="wp-block-paragraph">the seven that&#8217;s a yes also and then we&#8217;re ready for the six the six has three outbound connections</p>



<p class="wp-block-paragraph">one three and seven so i&#8217;m just gonna you know what i&#8217;m just gonna copy a whole row i wish i</p>



<p class="wp-block-paragraph">had a whole row of zeros and i&#8217;m gonna maybe change that to a zero real fast and then i&#8217;m</p>



<p class="wp-block-paragraph">gonna say all right where does where does six actually connect to let&#8217;s change those zeros to</p>



<p class="wp-block-paragraph">ones six connects to the uh the one and the three and the seven</p>



<p class="wp-block-paragraph">and the 7 okay so 1 goes to 1 3 goes to 1 and 7 goes to 1 okay then the 7 uh has no outbound</p>



<p class="wp-block-paragraph">connections so this is indeed a row of zeros maybe i could have done that one first it would</p>



<p class="wp-block-paragraph">have been fun oh well uh notice one more time that there&#8217;s no mirror so if we like you know</p>



<p class="wp-block-paragraph">if you trace your eyes along this identity line right here and you were expecting to see a mirror</p>



<p class="wp-block-paragraph">you would be sadly disappointed.</p>



<p class="wp-block-paragraph">a mirror you would be sadly disappointed because what would actually happen is not a mirror let me</p>



<p class="wp-block-paragraph">do the highlighter here and we&#8217;ll say we have like an identity line that goes down the middle</p>



<p class="wp-block-paragraph">and then i&#8217;ll just try to highlight some stuff let&#8217;s see the three four five six over here on row</p>



<p class="wp-block-paragraph">uh one and and those columns let&#8217;s go now to uh column one and notice how it&#8217;s like not the same</p>



<p class="wp-block-paragraph">three four five six so that&#8217;s not</p>



<p class="wp-block-paragraph">five six so that&#8217;s not a mirror because those numbers don&#8217;t match so there&#8217;s no mirror in</p>



<p class="wp-block-paragraph">directed graphs in terms of the matrix anyway let&#8217;s see i&#8217;m going to get rid of these little</p>



<p class="wp-block-paragraph">pound signs these hashtags uh the next question is uh let&#8217;s do a self-connect how do we add an</p>



<p class="wp-block-paragraph">edge like if i wanted to add an edge from uh you know one to seven for example actually let me</p>



<p class="wp-block-paragraph">duplicate this first, and then we&#8217;ll work on it.</p>



<p class="wp-block-paragraph">first and then we&#8217;ll work on it if i just wanted to add a brand new edge going from one to seven</p>



<p class="wp-block-paragraph">uh then i just have to make sure that i look at the row one and then look at the seven column</p>



<p class="wp-block-paragraph">and then just change that value to a one to say did i do that yeah to say that uh the edge now</p>



<p class="wp-block-paragraph">exists right so that&#8217;s pretty easy to add a brand new edge let&#8217;s look at self connects now just in</p>



<p class="wp-block-paragraph">in case um if i wanted to say that four connects to itself i have to do an arrow</p>



<p class="wp-block-paragraph">4 connects to itself. I have to do an arrow by the way. Did I do an arrow on the last one?</p>



<p class="wp-block-paragraph">Yeah, okay. 4, we&#8217;re saying now it connects to 4. So before we assumed that there were no</p>



<p class="wp-block-paragraph">self-connections by default. So all the nodes had no self-connections. But the 4, we just added</p>



<p class="wp-block-paragraph">a self-connection. So that means right here, that 0 is going to change to a 1. Pretty easy and fast</p>



<p class="wp-block-paragraph">to add an edge. And by the way, how fast was it to just access a cell and modify a value?</p>



<p class="wp-block-paragraph">modify a value it&#8217;s constant time again big O is going to happen in other videos but uh this</p>



<p class="wp-block-paragraph">is lightning fast for adding and removing edges okay so then the other thing is um let me see</p>



<p class="wp-block-paragraph">can I do oh I gotta get rid of that how do we remove an edge oh bro bro what&#8217;s happening here</p>



<p class="wp-block-paragraph">just select that oh how do we remove an edge we talked about this in other videos</p>



<p class="wp-block-paragraph">we talked about this in other videos for our adjacency matrix but it&#8217;s pretty easy we just say</p>



<p class="wp-block-paragraph">all right suppose i just want to kill this edge going from three to two so now there&#8217;s</p>



<p class="wp-block-paragraph">no connection no edge going from three to two um well i just have to go find the appropriate</p>



<p class="wp-block-paragraph">part of the matrix and that&#8217;s it so row three because three was the start node or the source</p>



<p class="wp-block-paragraph">node row three and then two is the destination node so i&#8217;m just gonna like overwrite that with</p>



<p class="wp-block-paragraph">the zero and now we have effectively removed an edge remember the computer doesn&#8217;t actually</p>



<p class="wp-block-paragraph">See you next time.</p>



<p class="wp-block-paragraph">Remember, the computer doesn&#8217;t actually see this diagram that you&#8217;re looking at on the left.</p>



<p class="wp-block-paragraph">The computer just has the matrix.</p>



<p class="wp-block-paragraph">The computer doesn&#8217;t really even need to know that the 3 is on top visually.</p>



<p class="wp-block-paragraph">It just needs to know what the 3 is actually connected to.</p>



<p class="wp-block-paragraph">At least most applications of graphs.</p>



<p class="wp-block-paragraph">There are some where it&#8217;s more visual, and so there needs to be some coordinates.</p>



<p class="wp-block-paragraph">But just the easiest and most simple way right here with an adjacency matrix doesn&#8217;t need that.</p>



<p class="wp-block-paragraph">Okay, so then the next thing I want to do is&#8230;</p>



<p class="wp-block-paragraph">is um i want to add edges that kind of like point towards you know two nodes that sort of point</p>



<p class="wp-block-paragraph">towards each other like you know opposing is this going to work yeah opposing uh edges that&#8217;s not a</p>



<p class="wp-block-paragraph">technical term so suppose for the sake of argument that you&#8217;re looking at the three and you say well</p>



<p class="wp-block-paragraph">the three can go outbound to the two but can the two go outbound to the three yeah totally</p>



<p class="wp-block-paragraph">Okay, so I now have two edges, each going in a different direction between the 3 and the 2.</p>



<p class="wp-block-paragraph">And by the way, in your mind, you might be thinking,</p>



<p class="wp-block-paragraph">hey, isn&#8217;t that what undirected graphs are doing?</p>



<p class="wp-block-paragraph">Yeah, basically, you have just an edge that goes in both directions.</p>



<p class="wp-block-paragraph">Here we have to draw two separate edges.</p>



<p class="wp-block-paragraph">Then we just have to update the matrix to match.</p>



<p class="wp-block-paragraph">So I added an edge going from 3 to 2.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go row 3, and then column 2, and&#8230;</p>



<p class="wp-block-paragraph">Oh, sorry, sorry.</p>



<p class="wp-block-paragraph">originally which worked from three to two that&#8217;s why is that what that&#8217;s why</p>



<p class="wp-block-paragraph">there&#8217;s a one there but now I just added an edge from two to three so we look at</p>



<p class="wp-block-paragraph">row two and then column three and then I update that to match so that zero became</p>



<p class="wp-block-paragraph">a one and it did become a little bit more like a mirror if we went ahead and</p>



<p class="wp-block-paragraph">added these like you know opposing edges on every single pair of nodes then the</p>



<p class="wp-block-paragraph">matrix would start to look like a mirror anyways what else can I talk about we&#8217;re</p>



<p class="wp-block-paragraph">We&#8217;re at about 16 minutes.</p>



<p class="wp-block-paragraph">about we&#8217;re at about 16 minutes and i&#8217;ve lost my mouse cursor what the heck oh there we go i need</p>



<p class="wp-block-paragraph">i need accessibility controls you know it&#8217;s true actually i really need glasses i&#8217;ve needed glasses</p>



<p class="wp-block-paragraph">for a couple of years maybe like five years and for some reason i just can&#8217;t get myself to go so</p>



<p class="wp-block-paragraph">what&#8217;s happening now is when people show me memes on their phones my face goes it goes backwards</p>



<p class="wp-block-paragraph">like this it&#8217;s like a it&#8217;s like a repellent for my face if you show me a meme i&#8217;m like</p>



<p class="wp-block-paragraph">me a meme i&#8217;m like not not fun to live that way so i gotta get glasses should i get a chain i want</p>



<p class="wp-block-paragraph">a gold chain that&#8217;s like studded and like blinged out and then like i have the glasses here only</p>



<p class="wp-block-paragraph">when i need to read and then it hangs the rest of the time and it maybe it plays music or something</p>



<p class="wp-block-paragraph">i don&#8217;t know i don&#8217;t think i&#8217;m gonna go that far so uh when we did undirected unweighted i&#8217;m just</p>



<p class="wp-block-paragraph">trying to make sure that i didn&#8217;t forget anything there&#8217;s no cheesy broccoli in this video directed</p>



<p class="wp-block-paragraph">and unweighted. Yeah, I guess that was it.</p>



<p class="wp-block-paragraph">weighted yeah i guess that was it okay so we&#8217;re at the end of this particular video i&#8217;m going to do</p>



<p class="wp-block-paragraph">one more before we shift topics the next one is going to be how to represent a directed and</p>



<p class="wp-block-paragraph">weighted graph inside the machine um using an adjacency matrix okay thank you for watching</p>



<p class="wp-block-paragraph">this video i hope you learned a little bit of stuff and had a little bit of fun i&#8217;ll see you</p>



<p class="wp-block-paragraph">soon i&#8217;m gonna go have a burrito no i&#8217;m not i&#8217;m just gonna keep recording hey everybody</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really</p>



<p class="wp-block-paragraph">appreciate it i do hope you did learn something and have some fun uh if you could do me a please</p>



<p class="wp-block-paragraph">a small little favor could you please subscribe and follow uh this channel or these videos or</p>



<p class="wp-block-paragraph">whatever it is you do on the current social media website that you&#8217;re looking at right now</p>



<p class="wp-block-paragraph">it would really mean the world to me and it&#8217;ll help make more videos and grow this community</p>



<p class="wp-block-paragraph">so we&#8217;ll be able to do more videos longer videos better videos or just i&#8217;ll be able to keep making</p>



<p class="wp-block-paragraph">Thank you.</p>



<p class="wp-block-paragraph">or just i&#8217;ll be able to keep making videos in general so please do do me a kindness and uh and</p>



<p class="wp-block-paragraph">subscribe you know sometimes i&#8217;m sleeping in the middle of the night and i just wake up because i</p>



<p class="wp-block-paragraph">know somebody subscribed or followed it just wakes me up and i get filled with joy that&#8217;s exactly</p>



<p class="wp-block-paragraph">what happens every single time so you could do it as a nice favor to me or you could you could troll</p>



<p class="wp-block-paragraph">me if you want to just wake me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll</p>



<p class="wp-block-paragraph">just wake up i promise that&#8217;s what will happen also uh if you look at the middle of the screen</p>



<p class="wp-block-paragraph">right now you should see a</p>



<p class="wp-block-paragraph">look at the middle of the screen right now you should see a QR code which you can scan in order</p>



<p class="wp-block-paragraph">to go to the website which I think is also named somewhere at the bottom of this video and it&#8217;ll</p>



<p class="wp-block-paragraph">take you to my main website where you can just kind of like see all the videos I published and</p>



<p class="wp-block-paragraph">the services and tutorials and things that I offer and all that good stuff and uh if you have a</p>



<p class="wp-block-paragraph">suggestion for uh uh clarifications or errata or just future videos that you want to see please</p>



<p class="wp-block-paragraph">leave a comment, or if you just want to say, hey, what&#8217;s up? What&#8217;s going on?</p>



<p class="wp-block-paragraph">to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me i would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">That&#8217;s all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/representing-a-directed-unweighted-graph-with-an-adjacency-matrix/">Representing a Directed Unweighted Graph with an Adjacency Matrix</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/representing-a-directed-unweighted-graph-with-an-adjacency-matrix/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Represent an Undirected Unweighted Graph with an Adjacency Matrix</title>
		<link>https://www.NeuralLantern.com/how-to-represent-an-undirected-unweighted-graph-with-an-adjacency-matrix/</link>
					<comments>https://www.NeuralLantern.com/how-to-represent-an-undirected-unweighted-graph-with-an-adjacency-matrix/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 12 Oct 2026 06:55:15 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[adjacency matrix]]></category>
		<category><![CDATA[adjacency matrix tutorial]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[coding interview]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[edge list vs adjacency matrix]]></category>
		<category><![CDATA[graph algorithms]]></category>
		<category><![CDATA[graph data structure]]></category>
		<category><![CDATA[graph representation]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[matrix graph]]></category>
		<category><![CDATA[self loop graph]]></category>
		<category><![CDATA[undirected graph]]></category>
		<category><![CDATA[unweighted graph]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=437</guid>

					<description><![CDATA[<p>Represent an undirected unweighted graph as an adjacency matrix of ones and zeros. A one in the cell at row i and column j means an edge exists between those nodes. Because the graph is undirected the matrix is symmetric across the diagonal. Changing a cell from zero to one adds an edge and changing it back removes the edge. Self-loops appear on the diagonal. This representation stores only the connection relationships and supports constant-time edge checks.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-represent-an-undirected-unweighted-graph-with-an-adjacency-matrix/">How to Represent an Undirected Unweighted Graph with an Adjacency Matrix</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How to Represent an Undirected Unweighted Graph with an Adjacency Matrix" width="1380" height="776" src="https://www.youtube.com/embed/tzCqcHK-9Tw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Learn how to store an undirected unweighted graph inside a computer using an adjacency matrix. In this video we build a matrix of ones and zeros where each cell shows whether an edge exists between two nodes. Rows represent the starting node and columns represent the ending node. Because the graph is undirected the matrix ends up as a mirror image across the diagonal. We also cover how to add or remove edges by simply changing a cell value, how self-loops appear on the diagonal, and why this representation lets you check any connection in constant time. The computer only needs the connection data, not the physical layout of the nodes. Perfect if you are learning graph theory, data structures, or preparing for algorithm interviews.</p>



<p class="wp-block-paragraph">0:00 Introduction to Adjacency Matrix<br>1:16 Arrays as Two Dimensional Matrices<br>2:20 Ones and Zeros Represent Edges<br>3:44 Filling the Matrix for Node One<br>6:20 Completing the Remaining Nodes<br>10:38 Finished Matrix and Practice Advice<br>11:02 Computer Stores Only Connections<br>11:40 Mirror Property of Undirected Graphs<br>14:17 Adding and Removing Edges<br>17:31 Parallel Edges Are Not Supported<br>18:50 Conclusion and Future Topics</p>



<p class="wp-block-paragraph">=-=-=-=-=-=-=-=-=</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li><a href="https://www.NeuralLantern.com/social">https://www.NeuralLantern.com/social</a></li>



<li>Twitter / X: <a href="https://x.com/NeuralLantern">https://x.com/NeuralLantern</a></li>



<li>Rumble: <a href="https://rumble.com/c/c-3696939">https://rumble.com/c/c-3696939</a></li>



<li>BitChute: <a href="https://www.bitchute.com/channel/pg1Pvv5dN4Gt">https://www.bitchute.com/channel/pg1Pvv5dN4Gt</a></li>



<li>Daily Motion: <a href="https://www.dailymotion.com/neurallantern">https://www.dailymotion.com/neurallantern</a></li>



<li>Minds: <a href="https://www.minds.com/neurallantern/">https://www.minds.com/neurallantern/</a></li>



<li>Odysee: <a href="https://odysee.com/@NeuralLantern:5">https://odysee.com/@NeuralLantern:5</a></li>
</ul>



<p class="wp-block-paragraph">Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: <a href="https://ko-fi.com/neurallantern">https://ko-fi.com/neurallantern</a></li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to the Blog: <a href="https://www.NeuralLantern.com">https://www.NeuralLantern.com</a></li>



<li>Watch the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there! Let&#8217;s talk about representing an undirected,</p>



<p class="wp-block-paragraph">unweighted graph in your machine using an adjacency matrix.</p>



<p class="wp-block-paragraph">All right everybody, so I hope you&#8217;ve been watching my previous videos.</p>



<p class="wp-block-paragraph">I just did some videos on edge list representation. Before that,</p>



<p class="wp-block-paragraph">I talked about like the basics of graphs and like terminology and stuff like that.</p>



<p class="wp-block-paragraph">You don&#8217;t need</p>



<p class="wp-block-paragraph">terminology and stuff like that. You don&#8217;t need to watch the edge list videos if you&#8217;re not</p>



<p class="wp-block-paragraph">interested in representing using an edge list, but you should probably at least watch the graphing</p>



<p class="wp-block-paragraph">video basics if you haven&#8217;t. Okay, so what are we looking at right here? I&#8217;ve just made a graph.</p>



<p class="wp-block-paragraph">I made a random graph and I kind of like, you know, wired up a bunch of edges to make it kind</p>



<p class="wp-block-paragraph">of complicated. I then spent a whole bunch of time making this very beautiful two-dimensional</p>



<p class="wp-block-paragraph">Matrix, just for you. I&#8217;m sorry you couldn&#8217;t watch me</p>



<p class="wp-block-paragraph">you i&#8217;m sorry you couldn&#8217;t watch me write it you know i sometimes i&#8217;ll i&#8217;ll have people say that</p>



<p class="wp-block-paragraph">they like when i yell at myself while i&#8217;m drawing something sorry it took too long but anyway what</p>



<p class="wp-block-paragraph">we&#8217;re going to do is take these concepts and put them together and we&#8217;ll we&#8217;ll say this is how we</p>



<p class="wp-block-paragraph">can represent the graph inside of the machine so what am i even talking about uh well the first</p>



<p class="wp-block-paragraph">thing is imagine an array in your machine right an array of integers like an array of uh i don&#8217;t know</p>



<p class="wp-block-paragraph">doubles you know an array of whatever so i&#8217;m gonna say like 5.4 and like you know 7.7 and</p>



<p class="wp-block-paragraph">8 and you know like whatever so i&#8217;m just like making an array of numbers probably a lot of</p>



<p class="wp-block-paragraph">you like this notation but inside your machine an array uh that is one-dimensional could be</p>



<p class="wp-block-paragraph">interpreted as a two-dimensional array so this matrix up here on the top right of the screen</p>



<p class="wp-block-paragraph">that&#8217;s really a one-dimensional ray array inside of the computer it&#8217;s just that we choose to treat</p>



<p class="wp-block-paragraph">it as a two-dimensional array.</p>



<p class="wp-block-paragraph">a two-dimensional array and um it&#8217;s important to understand that you can jump to any cell</p>



<p class="wp-block-paragraph">in constant time uh just like you can with a one-dimensional array because getting to a certain</p>



<p class="wp-block-paragraph">cell is really just a simple mathematical formula i think i&#8217;m going to do time complexities of this</p>



<p class="wp-block-paragraph">in a different video so for now i&#8217;m just going to say here&#8217;s how we represent the diagram first off</p>



<p class="wp-block-paragraph">let me label this so i don&#8217;t forget uh this is definitely where the heck is that how come that&#8217;s</p>



<p class="wp-block-paragraph">That&#8217;s not working, okay.</p>



<p class="wp-block-paragraph">Oh, this is definitely.</p>



<p class="wp-block-paragraph">okay uh this is definitely an undirected unweighted graph</p>



<p class="wp-block-paragraph">trying to type with the pen in my hand i have to change my brain okay</p>



<p class="wp-block-paragraph">so this is an undirected and also unweighted graph</p>



<p class="wp-block-paragraph">so for the purposes of this particular graph if it&#8217;s unweighted that means in the cells um we&#8217;re</p>



<p class="wp-block-paragraph">just we&#8217;re not going to put weight because there&#8217;s no weight in the graph i mean you could if you</p>



<p class="wp-block-paragraph">Wanted to.</p>



<p class="wp-block-paragraph">the graph i mean you could if you wanted to just say that every edge was a weight of one if it was</p>



<p class="wp-block-paragraph">unweighted but i&#8217;m gonna say let&#8217;s forget about you know what is the actual value of an edge</p>



<p class="wp-block-paragraph">because we don&#8217;t really have that in this graph and we&#8217;ll just say that if an edge exists then uh</p>



<p class="wp-block-paragraph">we&#8217;ll put a we&#8217;ll put a one there and if an edge does not exist we&#8217;ll put a zero in there</p>



<p class="wp-block-paragraph">at the corresponding cell we&#8217;ll talk about what cells mean you know what edges in a second</p>



<p class="wp-block-paragraph">The other thing is because it&#8217;s undirected, it doesn&#8217;t actually matter.</p>



<p class="wp-block-paragraph">It doesn&#8217;t actually matter whether we&#8217;re describing a start node or an end node with an edge because it goes in both directions.</p>



<p class="wp-block-paragraph">So actually what&#8217;s going to happen is this graph is going to be a mirror.</p>



<p class="wp-block-paragraph">I&#8217;ll show it to you in a second, but for now we&#8217;ll just say it&#8217;s not going to matter what the direction is.</p>



<p class="wp-block-paragraph">I like to do starting nodes as the rows, even though I just said that doesn&#8217;t matter.</p>



<p class="wp-block-paragraph">It&#8217;s just the way that I like to do things because it makes it easier to remember how to do this when you start to add direction to the graph.</p>



<p class="wp-block-paragraph">the graph so one by one i&#8217;m going to look at every single node and i&#8217;m going to chart what exactly is</p>



<p class="wp-block-paragraph">going on with that node in the two-dimensional matrix so i&#8217;m going to start uh i guess i&#8217;m going</p>



<p class="wp-block-paragraph">to go numerically because that&#8217;s kind of easier i&#8217;m going to start with the node index 1. so i&#8217;m</p>



<p class="wp-block-paragraph">going to go here at row 1 because i&#8217;m going to say that&#8217;s my start node and um where does the</p>



<p class="wp-block-paragraph">one node connect to it connects to node number two so um let&#8217;s see actually i think i&#8217;m going</p>



<p class="wp-block-paragraph">I&#8217;m going to say that.</p>



<p class="wp-block-paragraph">actually, I think I&#8217;m going to say that it is not self-connected. I mean, if you consider your</p>



<p class="wp-block-paragraph">graph to have by default every node is connected to itself, you could put a one there across that</p>



<p class="wp-block-paragraph">little diagonal line that you see. But I&#8217;m going to put a zero saying that these nodes are not</p>



<p class="wp-block-paragraph">connected to themselves, unless we do a little loop from a node to itself. Maybe I should add</p>



<p class="wp-block-paragraph">that later. So node number one is connected to node number two. I&#8217;m going to write a one there</p>



<p class="wp-block-paragraph">to say that there is a connection.</p>



<p class="wp-block-paragraph">What do I mean by that?</p>



<p class="wp-block-paragraph">What do I mean by that? Just to clarify, this, let&#8217;s see, the one two edge, that edge that I</p>



<p class="wp-block-paragraph">just highlighted in pink, that corresponds to this cell. So the start node, I&#8217;m going to do</p>



<p class="wp-block-paragraph">that in maybe orange. The start node is the row number. And maybe I&#8217;ll do like, I don&#8217;t know,</p>



<p class="wp-block-paragraph">light blue or something, baby blue for the destination node. And that&#8217;s going to be the</p>



<p class="wp-block-paragraph">column number. So basically just like the row</p>



<p class="wp-block-paragraph">so basically just like the row number is where the node where you start what node you start at</p>



<p class="wp-block-paragraph">the column is what node you end at um and then if you see a zero or a one in that particular cell</p>



<p class="wp-block-paragraph">at that particular row and column it&#8217;ll tell you whether there&#8217;s an edge there or not</p>



<p class="wp-block-paragraph">so i&#8217;m going to duplicate this real fast so i can erase the markings i just made</p>



<p class="wp-block-paragraph">and i&#8217;m going to say oops whoa whoa what&#8217;s happening here i want to get dude</p>



<p class="wp-block-paragraph">dude are you kidding me can i just erase it like that yeah okay i keep thinking these are lines i</p>



<p class="wp-block-paragraph">actually made a diagram in a different program so these are not even lines i can&#8217;t even erase this</p>



<p class="wp-block-paragraph">it sucks so um we did the uh the two node so i&#8217;m just going to quickly say the one is connected</p>



<p class="wp-block-paragraph">also to the three yes or no yes that&#8217;s a one uh then the one node is connected to the four</p>



<p class="wp-block-paragraph">uh yes i&#8217;m going to put a one the one node is connected to the</p>



<p class="wp-block-paragraph">the one node is connected to the five yes so i&#8217;m going to put a one a lot of connections this is</p>



<p class="wp-block-paragraph">pretty good uh and then also to the six and not to the seven so if it&#8217;s not connected to the seven</p>



<p class="wp-block-paragraph">i&#8217;m going to put a zero there okay we do the same thing for the two node so i&#8217;m going to start at</p>



<p class="wp-block-paragraph">the two node actually let me duplicate this start at the two node and i&#8217;m going to say</p>



<p class="wp-block-paragraph">we&#8217;re now looking at the two node oh my gosh</p>



<p class="wp-block-paragraph">okay I&#8217;m gonna put a question mark I guess we&#8217;re looking at the two node and</p>



<p class="wp-block-paragraph">well is the two node connected to the one node yes we just saw that was true</p>



<p class="wp-block-paragraph">is the two node connected to itself we said in this particular graph there are</p>



<p class="wp-block-paragraph">no self connections by default because I want to be able to draw them if that</p>



<p class="wp-block-paragraph">ends up being true is the two connected to the three I see a connection there I</p>



<p class="wp-block-paragraph">see an edge so I&#8217;m gonna put a one is it connected to the four I don&#8217;t see an</p>



<p class="wp-block-paragraph">edge, I&#8217;m going to put a zero.</p>



<p class="wp-block-paragraph">the four i don&#8217;t see an edge so i&#8217;m gonna put a zero to the five uh yes to the six uh yes and to</p>



<p class="wp-block-paragraph">the seven um whoops what did i just do uh the two is not connected to the six i was thinking of the</p>



<p class="wp-block-paragraph">one uh the two connected to the seven yes okay so we just basically do this over and over and</p>



<p class="wp-block-paragraph">over again until you have a giant matrix of ones and zeros which can very efficiently store um</p>



<p class="wp-block-paragraph">store um a graph i mean this is pretty much it this is all you have to do i want to do uh let&#8217;s</p>



<p class="wp-block-paragraph">see three is connected to i&#8217;m gonna say one one and a two and it&#8217;s not connected to itself by</p>



<p class="wp-block-paragraph">default put a zero it&#8217;s connected to the four nope it&#8217;s connected to the five</p>



<p class="wp-block-paragraph">oh gosh i gotta make that even connected to the five</p>



<p class="wp-block-paragraph">Oh.</p>



<p class="wp-block-paragraph">i&#8217;m losing my brain here uh yes and then uh three connected to the six right three connected to the</p>



<p class="wp-block-paragraph">seven uh no okay somebody leave me a comment uh if you have a corruption and then for the four</p>



<p class="wp-block-paragraph">um let&#8217;s see dude this is getting out of control for the four um</p>



<p class="wp-block-paragraph">yes i&#8217;m just going to look at the diagram pretty soon we&#8217;re going to start realizing something fun</p>



<p class="wp-block-paragraph">about an underachiever.</p>



<p class="wp-block-paragraph">realizing something fun about an undirected graph in that it is a mirror in this matrix</p>



<p class="wp-block-paragraph">so technically you only have to do like one half of the matrix in your code if you wanted to</p>



<p class="wp-block-paragraph">so i&#8217;m gonna say the one exists um one you know what i should have done i should have just filled</p>



<p class="wp-block-paragraph">this whole thing with zeros and then change the zeros to ones um okay so the four is connected</p>



<p class="wp-block-paragraph">to the two, yes or no? Nope. All the fours connected to the three? Nope. Fours connect&#8230;</p>



<p class="wp-block-paragraph">Nope, or it&#8217;s connected to the 4, we&#8217;re going to say no by default, or it&#8217;s connected to the 5, nope, it&#8217;s only connected to the two things, it&#8217;ll just be the 7 I guess, okay, so we&#8217;re going to put a nope there, and then a yep for the 7.</p>



<p class="wp-block-paragraph">Okay, then the 5 is connected to 1, 2, 3, 4, what if I just did a whole bunch of zeros, and then I overwrote only the ones, that would probably be a little bit faster.</p>



<p class="wp-block-paragraph">bit faster except for this first time i&#8217;m doing it okay and then i&#8217;ll just copy paste this</p>



<p class="wp-block-paragraph">tap it past okay i should have done this should i edit that out of the video i don&#8217;t know it&#8217;s fun</p>



<p class="wp-block-paragraph">to watch my mistakes so five to one yes five to two no five to three yes uh five to four</p>



<p class="wp-block-paragraph">we say no by default five to six yes five to seven yes okay i think that was a little bit</p>



<p class="wp-block-paragraph">faster let&#8217;s see how fast it is this time uh the six is connected to the five well let&#8217;s say it&#8217;s</p>



<p class="wp-block-paragraph">the one and then uh a one a three a five and a seven right six one three five and seven okay so</p>



<p class="wp-block-paragraph">going to be one, three, five, seven. That&#8217;s probably right. Again, leave me a comment.</p>



<p class="wp-block-paragraph">probably right again leave me a comment if i screwed something up i did not practice this</p>



<p class="wp-block-paragraph">i&#8217;m just kind of winging it the seven is connected to uh five six two four five six okay so i&#8217;m gonna</p>



<p class="wp-block-paragraph">do two four five six whoops that six didn&#8217;t happen let me just do it again okay all right</p>



<p class="wp-block-paragraph">so now we have it this is a uh an adjacency matrix that represents the graph that you see on the left</p>



<p class="wp-block-paragraph">Keep in mind that if you saw a matrix, I mean in general you should probably practice doing this both ways, like look at a graph and then you generate the matrix that corresponds to the graph you&#8217;re looking at, but also maybe you&#8217;re presented with a matrix and you would draw the graph that the matrix represents.</p>



<p class="wp-block-paragraph">Try to remember that your computer, in almost every program, it doesn&#8217;t really know where these nodes are unless it&#8217;s a drawing program or something.</p>



<p class="wp-block-paragraph">if we&#8217;re just talking about relationships which is what graphs are kind of good at um then your</p>



<p class="wp-block-paragraph">computer</p>



<p class="wp-block-paragraph">um then your computer doesn&#8217;t really care that the three is on the top it doesn&#8217;t really know that</p>



<p class="wp-block-paragraph">definitely not with this adjacency matrix representation uh the three in the computer&#8217;s</p>



<p class="wp-block-paragraph">mind could just be anywhere it doesn&#8217;t really even think of where the nodes are it&#8217;s just</p>



<p class="wp-block-paragraph">this node is connected to that node and that node is connected to that node and so forth</p>



<p class="wp-block-paragraph">we just position the nodes somewhere because we&#8217;re humans and it&#8217;s fun to look at diagrams</p>



<p class="wp-block-paragraph">but really this is all your computer knows just all these you know little connection numbers here</p>



<p class="wp-block-paragraph">So, let me duplicate this and I&#8217;ll show you something funny about an undirected graph real quick.</p>



<p class="wp-block-paragraph">Let&#8217;s see, how much time? 12? That&#8217;s not too bad.</p>



<p class="wp-block-paragraph">So, if I do, let&#8217;s see, I want to do a little highlighter here.</p>



<p class="wp-block-paragraph">I don&#8217;t get a chance to do that very often.</p>



<p class="wp-block-paragraph">I&#8217;m going to do a highlighter across this identity line, you know, the little diagonal.</p>



<p class="wp-block-paragraph">It&#8217;s all zeros for self-connects.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll change that in a second.</p>



<p class="wp-block-paragraph">I&#8217;ll make one of the nodes connect to itself.</p>



<p class="wp-block-paragraph">But notice how if I do this.</p>



<p class="wp-block-paragraph">notice how if i do this in green</p>



<p class="wp-block-paragraph">notice oh is the highlighter going to be green now keep screwing that up notice how we have</p>



<p class="wp-block-paragraph">a mirror happening along the identity line so we have like some some ones here right uh so we have</p>



<p class="wp-block-paragraph">like two three four five six in the one row if we look at the one column we&#8217;ll also see two three</p>



<p class="wp-block-paragraph">four five six it&#8217;s a mirror uh pick you know any other numbers you want let&#8217;s look at the uh the</p>



<p class="wp-block-paragraph">The three column.</p>



<p class="wp-block-paragraph">at the uh the three column the three column has a one there and then it&#8217;s got another one and a one</p>



<p class="wp-block-paragraph">down below at the five and the six so three is hitting two and five and six uh let me look at</p>



<p class="wp-block-paragraph">the diagram just to make sure i&#8217;m doing this right three is hitting uh two and five and six</p>



<p class="wp-block-paragraph">it should be hitting one also oh right i didn&#8217;t highlight that because it was already highlighted</p>



<p class="wp-block-paragraph">by that other thing okay so then let&#8217;s look at the three row and see if we see a mirror also so</p>



<p class="wp-block-paragraph">two and then the five and the six notice how it&#8217;s a mirror you just tilt your head uh and it really</p>



<p class="wp-block-paragraph">looks like a mirror and sometimes i like to make a joke when i&#8217;m explaining this to people uh you</p>



<p class="wp-block-paragraph">know if you just kind of like tilt your head a little bit it looks like some cheesy broccoli</p>



<p class="wp-block-paragraph">i&#8217;m personally not a fan of cheesy broccoli i mean i love cheese and if you put cheese on my</p>



<p class="wp-block-paragraph">broccoli i&#8217;m gonna be happy but it turns what&#8217;s what was healthy food into junk food it&#8217;s like</p>



<p class="wp-block-paragraph">I&#8217;m going to be healthy.</p>



<p class="wp-block-paragraph">I&#8217;m going to have broccoli today.</p>



<p class="wp-block-paragraph">be healthy i&#8217;m gonna have broccoli today good for me yay i&#8217;ve earned a double bacon cheeseburger</p>



<p class="wp-block-paragraph">later but then i put cheese all over the broccoli and suddenly it&#8217;s junk food again and it&#8217;s like i</p>



<p class="wp-block-paragraph">do get a little fiber and everything but it&#8217;s like not really being that healthy anymore so what</p>



<p class="wp-block-paragraph">should i do i should just get some more healthy food to make up for the junk food broccoli and</p>



<p class="wp-block-paragraph">then i&#8217;m gonna end up putting cheese on the other healthy food and then i just it&#8217;s like an endless</p>



<p class="wp-block-paragraph">cycle and i just keep eating and eating and eating pretty soon there&#8217;s no room for a cheeseburger</p>



<p class="wp-block-paragraph">pretty soon there&#8217;s no room for a cheeseburger i don&#8217;t know what to tell you anyway um so this</p>



<p class="wp-block-paragraph">is how you make an undirected unweighted graph uh with an adjacency matrix we&#8217;ll talk about time</p>



<p class="wp-block-paragraph">complexities and other stuff in the future um uh oh i should talk about how to modify edges okay</p>



<p class="wp-block-paragraph">so first off let me let me create a self loop real fast i&#8217;m going to create a self connect</p>



<p class="wp-block-paragraph">but let&#8217;s say that this four is actually connecting to itself uh with like a little</p>



<p class="wp-block-paragraph">self-loop. Okay. So, oh shoot.</p>



<p class="wp-block-paragraph">so oh shoot how can i get rid of all those is that going to work yes it&#8217;s going to work yes</p>



<p class="wp-block-paragraph">i should have duplicated this and drawn on the duplicate maybe i actually did that forgot about</p>



<p class="wp-block-paragraph">it already i don&#8217;t even know okay sometimes i have clever ideas and then i forget what i was</p>



<p class="wp-block-paragraph">doing then the ideas are just not that clever anymore yes okay what about that highlighter</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">i seem to have screwed up the graph somehow</p>



<p class="wp-block-paragraph">nope okay forget it um we&#8217;ll just pretend that it&#8217;s fine so i added that four connection</p>



<p class="wp-block-paragraph">so how do i modify the adjacency matrix well the four uh row starting node with the four column</p>



<p class="wp-block-paragraph">ending node was a zero indicating no self-connection now that i do have a self-connection</p>



<p class="wp-block-paragraph">And I&#8217;ll just put a one there, four and.</p>



<p class="wp-block-paragraph">connection i&#8217;ll just put a one there four and four and that&#8217;s it pretty easy right let me duplicate</p>



<p class="wp-block-paragraph">this other one so i don&#8217;t have to erase that stuff a second time a second time and um what</p>



<p class="wp-block-paragraph">will we do if we wanted to uh well let me actually sorry everybody let me just do that four one more</p>



<p class="wp-block-paragraph">time so i think i just erased the wrong thing we&#8217;ll say four and four is a one now and so how</p>



<p class="wp-block-paragraph">can we say that some new edge has been added?</p>



<p class="wp-block-paragraph">some new edge has been added let&#8217;s add an edge between one and seven pretty easy we just go to</p>



<p class="wp-block-paragraph">the right spot in the adjacency matrix let me add a little orange line here adjacency matrix</p>



<p class="wp-block-paragraph">to connect number one and number seven that would be uh we could do row one and column seven</p>



<p class="wp-block-paragraph">so that&#8217;s going to be a one and then remember this graph is undirected so it has to be a mirror</p>



<p class="wp-block-paragraph">so that means uh row seven and column one also has to be a one so it&#8217;s still a mirror</p>



<p class="wp-block-paragraph">so it&#8217;s still a mirror that&#8217;s pretty much it and remember you can access these cells</p>



<p class="wp-block-paragraph">in constant time which we&#8217;ll talk about more in a future video pretty nice how do you delete</p>



<p class="wp-block-paragraph">uh an edge let&#8217;s pretend that we wanted to delete uh the connection between the five and the three</p>



<p class="wp-block-paragraph">so i&#8217;m going to put maybe like a little squiggly line right here squiggly line saying that that</p>



<p class="wp-block-paragraph">edge is gone i can&#8217;t actually erase that because this is a i guess i could draw white over it but</p>



<p class="wp-block-paragraph">you would still see that the blue lines are covered so the five and three connection is</p>



<p class="wp-block-paragraph">gone now how do</p>



<p class="wp-block-paragraph">and three connection is gone now how do we do that in inside the adjacency matrix again just look at</p>



<p class="wp-block-paragraph">the uh row five column three change that one to a zero and then row three column five change that</p>



<p class="wp-block-paragraph">also to a zero oops not a nine that&#8217;s how you get rid of something so you add something uh by just</p>



<p class="wp-block-paragraph">changing a number you get rid of something by just changing a number self connects are pretty easy</p>



<p class="wp-block-paragraph">um and then of course after you make the matrix you want to just double check that you did it</p>



<p class="wp-block-paragraph">correctly I&#8217;m not going to do that right now</p>



<p class="wp-block-paragraph">check that you did it correctly i&#8217;m not going to do that right now maybe this is a good exercise</p>



<p class="wp-block-paragraph">for you at home you can just kind of like look and try to find my mistakes because that&#8217;s hilarious</p>



<p class="wp-block-paragraph">right um what else can i tell you uh this particular scheme does not support um parallel</p>



<p class="wp-block-paragraph">edges or edges that start at the same start node and end at the same end node as well i&#8217;m not</p>



<p class="wp-block-paragraph">really describing that very well so for example what if i had this three node that is connected</p>



<p class="wp-block-paragraph">to the 2 node and I want it</p>



<p class="wp-block-paragraph">that is connected to the two node and I wanted to add a second connection for some reason like</p>



<p class="wp-block-paragraph">there are reasons to do that I want to have another edge going from three to two and from</p>



<p class="wp-block-paragraph">two to three so now this is a parallel edge it&#8217;s the same it&#8217;s an edge that connects the same two</p>



<p class="wp-block-paragraph">nodes as some other edge how can I represent that inside of this matrix right now I can&#8217;t</p>



<p class="wp-block-paragraph">but one way to do this is to say that every cell where&#8217;s the three and the two there it is every</p>



<p class="wp-block-paragraph">cell in your matrix is not a one or a zero integer but every cell</p>



<p class="wp-block-paragraph">or a zero integer but every cell is its own uh individual linked list or array or vector or</p>



<p class="wp-block-paragraph">something that can hold multiple numbers so just to add a little notation here if if that&#8217;s what</p>



<p class="wp-block-paragraph">i mean then i can say well we&#8217;ll just say that there are two edges by saying that cell has an</p>



<p class="wp-block-paragraph">array of two numbers each number representing a connection not the not the greatest way to</p>



<p class="wp-block-paragraph">to represent it, but in our future</p>



<p class="wp-block-paragraph">greatest way to represent it. But in our future videos, we&#8217;re going to do like directed graphs</p>



<p class="wp-block-paragraph">and weighted graphs. It&#8217;ll make a little bit more sense. But long story short, this is how you do it.</p>



<p class="wp-block-paragraph">Let&#8217;s see. We did 20 minutes for this video. I think I&#8217;m feeling okay. There&#8217;s lots of properties</p>



<p class="wp-block-paragraph">and other stuff that we can talk about with graphs. But for now, I&#8217;m just going to stop right</p>



<p class="wp-block-paragraph">here. Thank you so much for watching this video. I hope you learned a little bit of stuff and had</p>



<p class="wp-block-paragraph">a little bit of fun. Tell your friends and I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">next video how do i stop the recording hey everybody thanks for watching this video again</p>



<p class="wp-block-paragraph">from the bottom of my heart i really appreciate it i do hope you did learn something and have some</p>



<p class="wp-block-paragraph">fun if you could do me a please a small little favor could you please subscribe and follow this</p>



<p class="wp-block-paragraph">channel or these videos or whatever it is you do on the current social media website that you&#8217;re</p>



<p class="wp-block-paragraph">looking at right now it would really mean the world to me and it&#8217;ll help make more videos</p>



<p class="wp-block-paragraph">and</p>



<p class="wp-block-paragraph">help make more videos and grow this community so we&#8217;ll be able to do more videos longer videos</p>



<p class="wp-block-paragraph">better videos or just i&#8217;ll be able to keep making videos in general so please do do me a kindness</p>



<p class="wp-block-paragraph">and uh and subscribe you know sometimes i&#8217;m sleeping in the middle of the night and i just</p>



<p class="wp-block-paragraph">wake up because i know somebody subscribed or followed it just wakes me up and i get filled</p>



<p class="wp-block-paragraph">with joy that&#8217;s exactly what happens every single time so you could do it as a nice favor to me or</p>



<p class="wp-block-paragraph">you could you could troll me if you want to just wake me up in the middle of the night just</p>



<p class="wp-block-paragraph">just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s what will happen also uh if you look at the middle</p>



<p class="wp-block-paragraph">of the screen right now you should see a qr code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which i think is also named somewhere at the bottom of this video and it&#8217;ll take you to my</p>



<p class="wp-block-paragraph">main website where you can just kind of like see all the videos i published and the services and</p>



<p class="wp-block-paragraph">tutorials and things that i offer and all that good stuff and uh if you have a suggestion for uh</p>



<p class="wp-block-paragraph">clarifications or erratics</p>



<p class="wp-block-paragraph">uh, clarifications or errata or just future videos that you want to see, please leave a comment. Or</p>



<p class="wp-block-paragraph">if you just want to say, Hey, what&#8217;s up, what&#8217;s going on? You know, just send me a comment,</p>



<p class="wp-block-paragraph">whatever. I also wake up for those in the middle of the night. I get, I wake up in a cold sweat</p>



<p class="wp-block-paragraph">and I&#8217;m like, it would really, it would really mean the world to me. I would really appreciate</p>



<p class="wp-block-paragraph">it. So again, thank you so much for watching this video and, um, enjoy the cool music as,</p>



<p class="wp-block-paragraph">coming for us all.</p>



<p class="wp-block-paragraph">Thanks for watching!</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-represent-an-undirected-unweighted-graph-with-an-adjacency-matrix/">How to Represent an Undirected Unweighted Graph with an Adjacency Matrix</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-to-represent-an-undirected-unweighted-graph-with-an-adjacency-matrix/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Represent an Unweighted Undirected Graph with an Edge List</title>
		<link>https://www.NeuralLantern.com/how-to-represent-an-unweighted-undirected-graph-with-an-edge-list/</link>
					<comments>https://www.NeuralLantern.com/how-to-represent-an-unweighted-undirected-graph-with-an-edge-list/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 15 Aug 2026 13:59:02 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[adjacency alternative]]></category>
		<category><![CDATA[coding graphs]]></category>
		<category><![CDATA[constant time lookup]]></category>
		<category><![CDATA[edge list]]></category>
		<category><![CDATA[edge tuples]]></category>
		<category><![CDATA[graph algorithms]]></category>
		<category><![CDATA[graph data structure]]></category>
		<category><![CDATA[graph representation]]></category>
		<category><![CDATA[graph theory basics]]></category>
		<category><![CDATA[index based edges]]></category>
		<category><![CDATA[node list]]></category>
		<category><![CDATA[undirected graph]]></category>
		<category><![CDATA[undirected unweighted]]></category>
		<category><![CDATA[unweighted graph]]></category>
		<category><![CDATA[vertex list]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=424</guid>

					<description><![CDATA[<p>Represent an unweighted undirected graph as a tuple of a vertex list and an edge list. Store nodes as indexable objects and list each edge once as a pair of indexes so you can reach any vertex in constant time.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-represent-an-unweighted-undirected-graph-with-an-edge-list/">How to Represent an Unweighted Undirected Graph with an Edge List</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How to Represent an Unweighted Undirected Graph with an Edge List" width="1380" height="776" src="https://www.youtube.com/embed/eIBfYgU1QIk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Learn how to represent an unweighted undirected graph using an edge list. We build a sample graph with nodes and edges, then show the vertex list and edge list as tuples. See why storing indexes instead of node values makes lookups faster in constant time. Follow along as we list every connection without duplicates. This is the first in a series covering all four combinations of weighted and directed graphs with edge lists.</p>



<p class="wp-block-paragraph">00:00 Introduction to Edge List Representation<br>00:56 Drawing a Sample Graph with Nodes<br>02:05 Adding Undirected Unweighted Edges<br>03:10 Graph as a Tuple of Vertex and Edge Lists<br>03:40 Building the Vertex List<br>04:24 Storing Nodes as Objects with Indexes<br>06:13 Creating the Edge List of Tuples<br>07:00 Listing Edges by Node Values<br>11:36 Limitations of Storing Node Values<br>12:30 Switching to Index-Based Edge List<br>14:08 Constant-Time Lookups with Indexes<br>16:54 Summary of the Edge List Method<br>17:16 Preview of Next Videos in the Series<br>17:44 Closing Remarks and Subscribe Request</p>



<p class="wp-block-paragraph">=-=-=-=-=-=-=-=-=</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>



<li>Twitter / X: https://x.com/NeuralLantern</li>



<li>Rumble: https://rumble.com/c/c-3696939</li>



<li>BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt</li>



<li>Daily Motion: https://www.dailymotion.com/neurallantern</li>



<li>Minds: https://www.minds.com/neurallantern/</li>



<li>Odysee: https://odysee.com/@NeuralLantern:5</li>
</ul>



<p class="wp-block-paragraph">Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: https://ko-fi.com/neurallantern</li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to the Blog: https://www.NeuralLantern.com</li>



<li>Watch the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there! Let&#8217;s talk about representing an unweighted,</p>



<p class="wp-block-paragraph">undirected graph in your machine using an edge list representation.</p>



<p class="wp-block-paragraph">Okay, so hopefully you watched my previous videos. If you haven&#8217;t, you might want to take a step back</p>



<p class="wp-block-paragraph">and check them out. We talked about, you know, what is a graph? What are some basic rules and</p>



<p class="wp-block-paragraph">terminology of a graph? Not graph and paper, but a graph. And we talked about representing paths</p>



<p class="wp-block-paragraph">in graphs.</p>



<p class="wp-block-paragraph">representing paths in graphs using either a list of nodes or a list of edges and we&#8217;re going to</p>



<p class="wp-block-paragraph">take the edge list concept one step further and we&#8217;re going to actually just say this whole graph</p>



<p class="wp-block-paragraph">is being represented as an edge list it&#8217;ll make sense in a little bit but uh so the first thing</p>



<p class="wp-block-paragraph">i&#8217;m going to do is try to set up my stuff which is always set up wrong because i&#8217;m the one setting it</p>



<p class="wp-block-paragraph">up and it always gets messed up okay so i got a graph paper and uh oh i got to make this other</p>



<p class="wp-block-paragraph">thing full screen. Sorry.</p>



<p class="wp-block-paragraph">um i&#8217;m going to draw a random graph just real fast so i&#8217;m going to do i don&#8217;t know just some random</p>



<p class="wp-block-paragraph">nodes so remember a graph is a collection of nodes and edges doesn&#8217;t even have to have edges but you</p>



<p class="wp-block-paragraph">know we&#8217;ll just say so we&#8217;re going to do that&#8217;s bad let me try one more time we&#8217;ll get that okay</p>



<p class="wp-block-paragraph">so we get i&#8217;m trying to get this circle perfect because i&#8217;m gonna have to duplicate it rare okay</p>



<p class="wp-block-paragraph">i&#8217;ve got a node here and i&#8217;m just going to give it an arbitrary value i&#8217;m going to say it&#8217;s got a 3</p>



<p class="wp-block-paragraph">and then i&#8217;m going to duplicate it a few times just to make a graph that is a little bit</p>



<p class="wp-block-paragraph">interesting so we have something uh something to kind of challenge us i guess so it&#8217;s not</p>



<p class="wp-block-paragraph">incredibly boring um and then i&#8217;m going to change some of the values here and then well i&#8217;ll change</p>



<p class="wp-block-paragraph">the next ones and then we&#8217;ll start looking at edges which edges do we want to make okay so</p>



<p class="wp-block-paragraph">right now we&#8217;re just making a graph make this graph along with me if you want to or uh you</p>



<p class="wp-block-paragraph">you know, after you.</p>



<p class="wp-block-paragraph">to or uh you know after you think you understand do another graph on your own</p>



<p class="wp-block-paragraph">okay so i&#8217;m gonna make some edges right now remember this is going to be an undirected</p>



<p class="wp-block-paragraph">unweighted graph so the edges are just going to be lines they&#8217;re not going to have direction on</p>



<p class="wp-block-paragraph">them and they&#8217;re not going to have weights on them i&#8217;m going to do a line over here i&#8217;m just</p>



<p class="wp-block-paragraph">randomly doing lines doesn&#8217;t really matter um what we do exactly the point is going to be let&#8217;s</p>



<p class="wp-block-paragraph">practice represented</p>



<p class="wp-block-paragraph">be let&#8217;s practice representing this graph okay so i&#8217;m just making a random graph it&#8217;s kind of like</p>



<p class="wp-block-paragraph">a little bit dense i don&#8217;t know um maybe i&#8217;ll just stop there and then i&#8217;ll add a wonky line just</p>



<p class="wp-block-paragraph">just to prove we can be cool about this i don&#8217;t know we&#8217;ll do another one right here so it&#8217;s a</p>



<p class="wp-block-paragraph">slightly more interesting graph okay so um that&#8217;s just a graph and uh what i&#8217;m going to do is i&#8217;m</p>



<p class="wp-block-paragraph">going to say this is a, you know, an unweighted, oops, weighted.</p>



<p class="wp-block-paragraph">oops waited undirected uh graph and we&#8217;re going to use the edge list of representation</p>



<p class="wp-block-paragraph">i have spell check on this i really hope i do nope okay i guess i forgot to fix that months ago</p>



<p class="wp-block-paragraph">all right so then the next thing we&#8217;re going to do is uh we&#8217;re going to look at the idea of like</p>



<p class="wp-block-paragraph">how do we start with the edge list representation okay um the first thing i&#8217;m going to say is that</p>



<p class="wp-block-paragraph">our graph</p>



<p class="wp-block-paragraph">that the our graph in an edge list representation is a tuple just meaning it&#8217;s you know some things</p>



<p class="wp-block-paragraph">put together if you know tuples encoding already uh the tuple is going to consist of a collection</p>



<p class="wp-block-paragraph">of vertices and edges what&#8217;s going to be an edge list don&#8217;t make fun of my ease please</p>



<p class="wp-block-paragraph">anyway so uh let&#8217;s do the first thing is going to be the vertex list so how do we represent the</p>



<p class="wp-block-paragraph">vertex list or the node list well i&#8217;m just going to say that my vertex list v</p>



<p class="wp-block-paragraph">to say that my vertex list v is equal to something and we&#8217;ll just put inside of this</p>



<p class="wp-block-paragraph">some vertices so the easiest way when you&#8217;re kind of drawing this right now is i&#8217;m just going to</p>



<p class="wp-block-paragraph">start putting the values of the node i&#8217;m going to say well here&#8217;s a three and uh i guess i could</p>



<p class="wp-block-paragraph">sort them for whatever reason uh if we&#8217;re going to do binary search on them later but we&#8217;re not</p>



<p class="wp-block-paragraph">going to i&#8217;m just going to maybe you know what i&#8217;ll go from left to right so that&#8217;ll make more</p>



<p class="wp-block-paragraph">sense, just visually. So I&#8217;ll go from left to right. 3, 13, 6, 12.</p>



<p class="wp-block-paragraph">3, 13, 6, 12, and a 15, and an 18.</p>



<p class="wp-block-paragraph">You can see all of those are nodes, right?</p>



<p class="wp-block-paragraph">Somebody stop me if I forgot a node.</p>



<p class="wp-block-paragraph">Okay, here&#8217;s the thing though.</p>



<p class="wp-block-paragraph">What are we actually storing in this vertex list?</p>



<p class="wp-block-paragraph">You probably don&#8217;t want to store the node values.</p>



<p class="wp-block-paragraph">I mean, you could be a little slow and dumb though,</p>



<p class="wp-block-paragraph">but we want the option to be a little bit faster later</p>



<p class="wp-block-paragraph">and also the option to turn these vertices into full classes,</p>



<p class="wp-block-paragraph">like give them extra properties and whatever.</p>



<p class="wp-block-paragraph">So what I&#8217;m going to say is that…</p>



<p class="wp-block-paragraph">So what I&#8217;m going to say is that I&#8217;m writing down the number 3 and the number 13 here for you, but you should imagine in your code you would have an object of type vertex or node, like a full class, and you would basically be stuffing pointers inside of that vector, inside of that list.</p>



<p class="wp-block-paragraph">I keep saying list. It is called an edge list representation, but you can probably imagine</p>



<p class="wp-block-paragraph">that this could just as easily be a vector. If you&#8217;ve seen my other videos, you know what that is.</p>



<p class="wp-block-paragraph">but uh so i want to be able to index this uh faster so for me personally i make this a vector</p>



<p class="wp-block-paragraph">and not an actual list but we&#8217;re going to call it a list anyway so three should be a pointer</p>



<p class="wp-block-paragraph">uh to a full node object uh smart pointer raw pointer whatever you want 13 should be a full</p>



<p class="wp-block-paragraph">pointer to an entire uh entirely different node object with just 13 assigned as its uh template</p>



<p class="wp-block-paragraph">type value because we&#8217;re making this a vector we can actually index</p>



<p class="wp-block-paragraph">can actually index uh the nodes right so like this is like index 0 for the 3 node index 1 for the 13</p>



<p class="wp-block-paragraph">node so i&#8217;m just going to put the indexes here whoops just to drive the point home a little</p>



<p class="wp-block-paragraph">bit further so if i told you hey let&#8217;s do uh the node at index 2 you would know that is the node</p>



<p class="wp-block-paragraph">that is in the very middle with the value of 6 because index 0 and 1 and 2 brings you to this</p>



<p class="wp-block-paragraph">node right here um which is a 6 so this is going to this is going to help us later let me save this</p>



<p class="wp-block-paragraph">Real fast, by the way.</p>



<p class="wp-block-paragraph">let me save this real fast by the way i&#8217;m just going to do that okay so uh the next thing that</p>



<p class="wp-block-paragraph">we need to do is uh make an edge list the edge list is really where it&#8217;s all at that&#8217;s really</p>



<p class="wp-block-paragraph">where all the data is it&#8217;s going to tell us exactly where everything is or it&#8217;s going to</p>



<p class="wp-block-paragraph">describe the whole graph pretty much so the edge list is another we&#8217;ll say that&#8217;s a list this could</p>



<p class="wp-block-paragraph">be like a linked list or vector or whatever you want i&#8217;m just going to say it&#8217;s a linked list</p>



<p class="wp-block-paragraph">and every item in the list is going to be another tuple so remember above the graph itself was a</p>



<p class="wp-block-paragraph">tuple containing a vertex list and an edge list so the edge list is a list of tuples</p>



<p class="wp-block-paragraph">meaning you know items bundled together for one tuple and then just like a list of those</p>



<p class="wp-block-paragraph">so what i&#8217;m going to try to do is describe every single edge uh one by one using one tuple each</p>



<p class="wp-block-paragraph">inside of the edge list so the first thing i&#8217;m going to do just you know to make this a little</p>



<p class="wp-block-paragraph">little bit easier.</p>



<p class="wp-block-paragraph">thing I want to do just you know to make this a little bit easier is I&#8217;m going to ignore the</p>



<p class="wp-block-paragraph">indexes for the vertex list and I&#8217;m going to say let&#8217;s describe everything happening from the three</p>



<p class="wp-block-paragraph">node outwards or just to every other node so the three node itself I&#8217;m going to look at its</p>



<p class="wp-block-paragraph">connections from left to right so the three node let&#8217;s just start by putting a three here</p>



<p class="wp-block-paragraph">maybe I should describe the legend real fast the tuples will basically be the start node</p>



<p class="wp-block-paragraph">and then the end node</p>



<p class="wp-block-paragraph">and then the end node and then the uh well the weight if there was a weight but we&#8217;re doing an</p>



<p class="wp-block-paragraph">unweighted graph so it&#8217;s really just going to be a tuple of two items the other thing to keep</p>



<p class="wp-block-paragraph">in mind is that because this is an undirected graph it really doesn&#8217;t make a difference what</p>



<p class="wp-block-paragraph">node is the start node and what node is the end node you can just swap them and it&#8217;s totally fine</p>



<p class="wp-block-paragraph">for me personally i&#8217;d rather you know sort before assigning the start node and end node that way</p>



<p class="wp-block-paragraph">when i read the graph later it&#8217;s a little bit faster because i wouldn&#8217;t have to check in both</p>



<p class="wp-block-paragraph">directions but</p>



<p class="wp-block-paragraph">wouldn&#8217;t have to check in both directions but it really honestly doesn&#8217;t matter right now so</p>



<p class="wp-block-paragraph">start node and end node so the start node here is 3 and the end node is going to be 13 so that&#8217;s the</p>



<p class="wp-block-paragraph">first thing that we&#8217;re doing that&#8217;s the first tuple and then i&#8217;m going to say what else does</p>



<p class="wp-block-paragraph">the 3 connect to it connects to the not the 6 it connects to the 12. okay so the 3 connects to the</p>



<ol start="12" class="wp-block-list">
<li>again we could have said 12 comma 3 wouldn&#8217;t have mattered but i&#8217;m just going to try to keep</li>
</ol>



<p class="wp-block-paragraph">it sorted so then</p>



<p class="wp-block-paragraph">keep it sorted so then what else does the three connect to it connects to the uh the 18 doesn&#8217;t</p>



<p class="wp-block-paragraph">connect to the 15 and just confirm that if i&#8217;m looking at the three i can see three lines</p>



<p class="wp-block-paragraph">touching it so that means okay there&#8217;s got to be three tuples for the for the e for the three so</p>



<p class="wp-block-paragraph">i&#8217;m going to say three connects to the 18. and now i&#8217;ve described everything happened to do with the</p>



<p class="wp-block-paragraph">three note i will simply continue let&#8217;s see should i do like a new line maybe i should try to do a</p>



<p class="wp-block-paragraph">new line for every</p>



<p class="wp-block-paragraph">try to do a new line for every start node so this is easier to look at okay so i&#8217;m going to do that</p>



<p class="wp-block-paragraph">and i&#8217;m going to say the next line is we&#8217;ll start at the 13 this time so the 13 the 13 is also</p>



<p class="wp-block-paragraph">connected to the 3 because it goes in both directions with an undirected graph but we</p>



<p class="wp-block-paragraph">already described that connection with that first row so 3 comma 13 describes 13 comma 3 i don&#8217;t</p>



<p class="wp-block-paragraph">want to duplicate edges so forget about that let&#8217;s look at what else 13 is connected to it&#8217;s connected</p>



<p class="wp-block-paragraph">it to the six</p>



<p class="wp-block-paragraph">connected to it&#8217;s connected to the six so I&#8217;m just going to put 13 comma 6 and then that&#8217;s the end of</p>



<p class="wp-block-paragraph">the 13&#8217;s connections oh I could have used tabs for that hang on let me do that okay so now let&#8217;s look</p>



<p class="wp-block-paragraph">at the six node six is not connected to the three it is connected to the 13 but we already described</p>



<p class="wp-block-paragraph">the 13 6 connection in the previous row so forget that and then I&#8217;m just going to look to the right</p>



<p class="wp-block-paragraph">So the 6 is connected to the 12 and the 15.</p>



<p class="wp-block-paragraph">the 12 and the 15 12 and the 15 and also the 18 so i&#8217;m going to do 6 comma 12 maybe i&#8217;m going to</p>



<p class="wp-block-paragraph">do a copy paste here real fast just to make it easier 6 12 and 6 15 and 6 18 so again all i&#8217;m</p>



<p class="wp-block-paragraph">doing is describing you know what other nodes the current node is touching and i&#8217;m going to do that</p>



<p class="wp-block-paragraph">using a tuple that just has one node and has another node and that&#8217;s pretty much it so when</p>



<p class="wp-block-paragraph">we&#8217;re done with this</p>



<p class="wp-block-paragraph">it so when we&#8217;re done with this uh we&#8217;re going to look at the 12 node 12 node it&#8217;s connected to</p>



<p class="wp-block-paragraph">the six already handled it&#8217;s connected to the three it&#8217;s already handled and it&#8217;s connected</p>



<p class="wp-block-paragraph">to the 18 not handled yet so i&#8217;m going to say 12 goes out to 18. okay then we&#8217;re going to look at</p>



<p class="wp-block-paragraph">the 15 node 15 and 6 that&#8217;s already handled in that third row so forget that 15 and 18 that is</p>



<p class="wp-block-paragraph">is not</p>



<p class="wp-block-paragraph">15 and 18 that is not handled yet so we&#8217;re going to do 15.18 by the way this is one benefit of</p>



<p class="wp-block-paragraph">going from left to right visually all i really have to do is just look my eyes to the right and</p>



<p class="wp-block-paragraph">i&#8217;ll see nodes that i need to take care of and if i look my eyes to the left i&#8217;ll see nodes that i</p>



<p class="wp-block-paragraph">already took care of if that makes sense so now that we&#8217;re done with the 15 let&#8217;s see we did 3 13</p>



<p class="wp-block-paragraph">6 12 15 let&#8217;s just take care of the 18 if there&#8217;s anything left to take care of i can guarantee</p>



<p class="wp-block-paragraph">there&#8217;s not going to be.</p>



<p class="wp-block-paragraph">there&#8217;s not going to be because every node the 18 is the node on the farthest you know the furthest</p>



<p class="wp-block-paragraph">to the right so everything on the left is already handled so we don&#8217;t even have to put anything for</p>



<p class="wp-block-paragraph">the 18 node okay give me a second to clean up this graph real fast i think i want to maybe</p>



<p class="wp-block-paragraph">move this up a little bit okay uh now here&#8217;s the thing though we&#8217;ve only named node values so if</p>



<p class="wp-block-paragraph">we wanted to i don&#8217;t know let&#8217;s say check to see if the uh let&#8217;s say we have an edge we&#8217;re looking</p>



<p class="wp-block-paragraph">Thank you.</p>



<p class="wp-block-paragraph">let&#8217;s say we have an edge we&#8217;re looking at the 3 comma 13 edge and we&#8217;re asking now do both of</p>



<p class="wp-block-paragraph">those nodes exist the edge describes these two nodes do they exist or uh maybe let&#8217;s look at</p>



<p class="wp-block-paragraph">the three here and we want to figure out just you know what other nodes does three touch so we start</p>



<p class="wp-block-paragraph">iterating through all the edges here how can we actually get a pointer to that node to manipulate</p>



<p class="wp-block-paragraph">it in the code right now it&#8217;s okay because it&#8217;s a diagram but you know this is not very</p>



<p class="wp-block-paragraph">diagram but you know this is not very good storing values directly in this notation in your code you</p>



<p class="wp-block-paragraph">probably want to store pointer uh pointers there but maybe not necessarily smart pointers they take</p>



<p class="wp-block-paragraph">a little bit of extra memory and it&#8217;s kind of cumbersome but um we could store an index into</p>



<p class="wp-block-paragraph">this vertex list to make things a little bit faster let me show you what i mean but first i&#8217;m</p>



<p class="wp-block-paragraph">going to duplicate this list that we just made already, duplicate it over here, and</p>



<p class="wp-block-paragraph">over here and maybe i&#8217;ll label the first one and i&#8217;ll say so we already have start node and end</p>



<p class="wp-block-paragraph">node i&#8217;m going to say e underscore by value so we&#8217;re storing the edge list by node values and</p>



<p class="wp-block-paragraph">then here we&#8217;re going to store nodes by their index in the vertex list so what do i mean by</p>



<p class="wp-block-paragraph">index well okay right here the first node that we&#8217;re mentioning is the three well look at the</p>



<p class="wp-block-paragraph">three node in the vertex list it&#8217;s at index zero right so i&#8217;m just going to put a zero</p>



<p class="wp-block-paragraph">zero right so i&#8217;m just gonna put a zero that&#8217;s it change it to an index then i look at the 13</p>



<p class="wp-block-paragraph">that&#8217;s index one and then i look at the three again that&#8217;s index zero um and then the 12 is</p>



<p class="wp-block-paragraph">index three and then the three again is index zero and the 18 is index five um if that was too fast</p>



<p class="wp-block-paragraph">i&#8217;m sorry just rewind and play it back in slow motion i think this video is already getting way</p>



<p class="wp-block-paragraph">too long so then i do the same thing for every single other tuple so the 13 node um that is</p>



<p class="wp-block-paragraph">node um that is index one so i&#8217;m going to put a one there the sixth node is index two go on to</p>



<p class="wp-block-paragraph">the next node so the sixth node is index two and then the 12 is index three and the six is two and</p>



<p class="wp-block-paragraph">the 15 is actually four the six again is two the 18 is five move on to the 12 node here uh that&#8217;s</p>



<p class="wp-block-paragraph">index 3, 18 node is index 5, and then</p>



<p class="wp-block-paragraph">the 15</p>



<p class="wp-block-paragraph">and then uh the 15 is index 4 and then 18 again is index 5 so now on you know on both sides like</p>



<p class="wp-block-paragraph">in both of these edge lists uh i&#8217;m representing the graph it&#8217;s just that one can be a little bit</p>



<p class="wp-block-paragraph">more efficient than the other uh for example if i was going to let&#8217;s just say i wanted to scan</p>



<p class="wp-block-paragraph">every single edge in the graph well i could scan this list right here in linear time so linear time</p>



<p class="wp-block-paragraph">based on the number of edges and every single time i see an edge i can jump directly to the</p>



<p class="wp-block-paragraph">Corresponding.</p>



<p class="wp-block-paragraph">jump directly to the corresponding vertex or node in constant time because i have an index</p>



<p class="wp-block-paragraph">so for example let&#8217;s say uh you know this uh the sixth node um touching the 15 node so that</p>



<p class="wp-block-paragraph">particular edge right there let me i want to be more interactive here how can i do this okay</p>



<p class="wp-block-paragraph">uh suppose i want to do</p>



<p class="wp-block-paragraph">612 node and so that&#8217;s going to be pointing to this edge right up here i want to see you know</p>



<p class="wp-block-paragraph">what&#8217;s going on with both of those nodes well if i was looking at the value-based edge list</p>



<p class="wp-block-paragraph">and i wanted to get a hold of let&#8217;s say the sixth node itself so i can like do something with that</p>



<p class="wp-block-paragraph">vertex like delete it or move it or just whatever i would have to then scan the entire vertex list</p>



<p class="wp-block-paragraph">i&#8217;d have to go you know this one this one this one this one this one until i eventually found</p>



<p class="wp-block-paragraph">the corresponding value.</p>



<p class="wp-block-paragraph">uh the corresponding value this wouldn&#8217;t really support duplicate values either</p>



<p class="wp-block-paragraph">uh it would be kind of hard to do that but uh i&#8217;ve i&#8217;ve slowed down the program it&#8217;s linear</p>



<p class="wp-block-paragraph">time based on the number of vertexes and if you&#8217;re already doing linear time based on the number of</p>



<p class="wp-block-paragraph">edges this is like it&#8217;s technically still a scalable data structure but it&#8217;s not super fast</p>



<p class="wp-block-paragraph">it could be faster on the other hand uh so like i just said uh sorry for repeating myself if we did</p>



<p class="wp-block-paragraph">the index</p>



<p class="wp-block-paragraph">the index based uh edge list it says two three here which is the 612 how can i find the sixth</p>



<p class="wp-block-paragraph">node well i just look at index two and instead of scanning oh gosh hang on</p>



<p class="wp-block-paragraph">i&#8217;m not as fast as i used to be okay dude there&#8217;s like did you see that uh</p>



<p class="wp-block-paragraph">a whole bunch of pink dots everywhere now what have i done okay</p>



<p class="wp-block-paragraph">So, uh…</p>



<p class="wp-block-paragraph">so uh i&#8217;m looking at the 612 edge i see that the indexes are two and three that means in constant</p>



<p class="wp-block-paragraph">time i can just jump directly to i guess i&#8217;ll put it in red in constant time index two right there</p>



<p class="wp-block-paragraph">and index three right there i do not have to scan the vertex list or the vector i guess if it was a</p>



<p class="wp-block-paragraph">vertex list like an actual linked list then i&#8217;d still have to scan because it&#8217;s linear time to do</p>



<p class="wp-block-paragraph">it but if it&#8217;s a vector</p>



<p class="wp-block-paragraph">But if it&#8217;s a vector or an array, I can just jump to an index in constant time, so it&#8217;s way faster.</p>



<p class="wp-block-paragraph">So what I&#8217;m trying to say is that this representation is what you want to do in the code when it comes to, I don&#8217;t know, representing diagrams and stuff.</p>



<p class="wp-block-paragraph">I don&#8217;t know. The one on the left is more human friendly.</p>



<p class="wp-block-paragraph">So this is the basic idea for how to represent an unweighted and also undirected graph in the machine using the edge list method of representation.</p>



<p class="wp-block-paragraph">i guess i&#8217;m going to cut the video i hope you learned a little bit of stuff and had</p>



<p class="wp-block-paragraph">a little bit of fun in the next video i think i&#8217;m going to do uh weighted uh undirected graphs</p>



<p class="wp-block-paragraph">and this i&#8217;m going to do four videos for this one representation type i&#8217;m going to do unweighted</p>



<p class="wp-block-paragraph">undirected and then weighted and undirected and then unweighted and directed i&#8217;m gonna</p>



<p class="wp-block-paragraph">do all four combinations all right see you in the next video thanks for watching</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really appreciate it</p>



<p class="wp-block-paragraph">i do hope you did learn something and have some fun if you could do me a please a small little</p>



<p class="wp-block-paragraph">favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p class="wp-block-paragraph">world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



<p class="wp-block-paragraph">videos, longer videos, better videos, or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">just i&#8217;ll be able to keep making videos in general so please do do me a kindness and uh and subscribe</p>



<p class="wp-block-paragraph">you know sometimes i&#8217;m sleeping in the middle of the night and i just wake up because i know</p>



<p class="wp-block-paragraph">somebody subscribed or followed it just wakes me up and i get filled with joy that&#8217;s exactly what</p>



<p class="wp-block-paragraph">happens every single time so you could do it as a nice favor to me or you could you could troll me</p>



<p class="wp-block-paragraph">if you want to just wake me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just</p>



<p class="wp-block-paragraph">wake up i promise that&#8217;s what will happen also uh if you look at the middle of the screen right now</p>



<p class="wp-block-paragraph">you should see a QR code, which</p>



<p class="wp-block-paragraph">screen right now you should see a QR code which you can scan in order to go to the website which</p>



<p class="wp-block-paragraph">I think is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website</p>



<p class="wp-block-paragraph">where you can just kind of like see all the videos I published and the services and tutorials and</p>



<p class="wp-block-paragraph">things that I offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">errata or just future videos that you want to see please leave a comment or if you just want to say</p>



<p class="wp-block-paragraph">hey what&#8217;s up what&#8217;s going on you know just send</p>



<p class="wp-block-paragraph">what&#8217;s going on? You know, just send me a comment, whatever. I also wake up for those in the middle</p>



<p class="wp-block-paragraph">of the night. I get, I wake up in a cold sweat and I&#8217;m like, it would really, it really mean</p>



<p class="wp-block-paragraph">the world to me. I would really appreciate it. So again, thank you so much for watching this video</p>



<p class="wp-block-paragraph">and, um, enjoy the cool music as, as I fade into the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Thanks for watching!</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-represent-an-unweighted-undirected-graph-with-an-edge-list/">How to Represent an Unweighted Undirected Graph with an Edge List</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-to-represent-an-unweighted-undirected-graph-with-an-edge-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>4 Graph Types: Undirected vs Directed, Weighted vs Unweighted</title>
		<link>https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/</link>
					<comments>https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 06 Jul 2026 10:05:07 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[directed graph]]></category>
		<category><![CDATA[edges]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[graph types]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[network topology]]></category>
		<category><![CDATA[nodes]]></category>
		<category><![CDATA[pathfinding]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[undirected graph]]></category>
		<category><![CDATA[unweighted graph]]></category>
		<category><![CDATA[vertices]]></category>
		<category><![CDATA[weighted graph]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=407</guid>

					<description><![CDATA[<p>A graph is basically a collection of nodes, also known as vertices, and edges, which are the lines that connect nodes to each other. The four types of graphs are undirected unweighted, undirected weighted, directed unweighted, and directed weighted. Graphs help represent relationships between things like computers in a network or cities and airports.</p>
<p>The post <a href="https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/">4 Graph Types: Undirected vs Directed, Weighted vs Unweighted</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="4 Graph Types: Undirected vs Directed, Weighted vs Unweighted" width="1380" height="776" src="https://www.youtube.com/embed/8Ml20VhpdrI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">In this video we break down the four main types of graphs used in computer science: undirected unweighted, undirected weighted, directed unweighted, and directed weighted.</p>



<p class="wp-block-paragraph">We start with the basic idea of graphs &#8211; collections of nodes (vertices) and edges &#8211; and then explore each type with clear examples. Learn how these graphs represent real-world relationships like computer networks, airport routes, road maps, and game maps.</p>



<p class="wp-block-paragraph">Perfect for anyone learning data structures, algorithms, or preparing for coding interviews.</p>



<p class="wp-block-paragraph">00:00 Introduction to Graphs<br>00:19 Basic Graph Definition<br>00:48 Nodes and Vertices<br>01:01 Empty Graph Example<br>01:17 Graph Implementation Concepts<br>02:02 Node Data and Templates<br>03:22 Adding Nodes<br>04:00 Adding Edges<br>04:44 What Graphs Represent<br>05:36 Graph Use Cases<br>06:56 Real-World Examples<br>08:35 Four Types of Graphs<br>08:52 Undirected Unweighted Graph<br>10:40 Unweighted as Unit Weights<br>11:40 Undirected Weighted Graph<br>13:32 Weighted Graph Benefits<br>15:52 Directed Weighted Graph<br>19:50 Directed Unweighted Graph<br>20:32 Summary of Four Graph Types<br>21:19 Closing and Future Videos</p>



<p class="wp-block-paragraph">=-=-=-=-=-=-=-=-=</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>



<li>Twitter / X: https://x.com/NeuralLantern</li>



<li>Rumble: https://rumble.com/c/c-3696939</li>



<li>BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt</li>



<li>Daily Motion: https://www.dailymotion.com/neurallantern</li>



<li>Minds: https://www.minds.com/neurallantern/</li>



<li>Odysee: https://odysee.com/@NeuralLantern:5</li>
</ul>



<p class="wp-block-paragraph">Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: https://ko-fi.com/neurallantern</li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to the Blog: https://www.NeuralLantern.com</li>



<li>Watch the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there! Let&#8217;s talk about four different types of graphs that you can use and how they relate to computer science.</p>



<p class="wp-block-paragraph">Okay, so you can see like I&#8217;ve got like a blank little graph paper up here.</p>



<p class="wp-block-paragraph">I&#8217;m going to talk about graphs and just the very basic idea of graphs in general</p>



<p class="wp-block-paragraph">and then show you the four different types of graphs that we have.</p>



<p class="wp-block-paragraph">about how to implement graphs inside the machine, time complexities, maybe graph algorithms,</p>



<p class="wp-block-paragraph">and a whole bunch of stuff, terminology, everything. Okay, so the first thing is, I guess I&#8217;m going to</p>



<p class="wp-block-paragraph">assume probably most of you have sort of seen a graph before and you kind of understand a little</p>



<p class="wp-block-paragraph">bit about it already, but I&#8217;ll say that a graph is basically a collection of nodes, also known as</p>



<p class="wp-block-paragraph">vertices or vertexes, and edges, which are the lines that connect nodes to each other. This screen</p>



<p class="wp-block-paragraph">See, this is a valid graph.</p>



<p class="wp-block-paragraph">I&#8217;m not talking about the graphing paper.</p>



<p class="wp-block-paragraph">It&#8217;s just an empty graph.</p>



<p class="wp-block-paragraph">There&#8217;s nothing there.</p>



<p class="wp-block-paragraph">So it&#8217;s still valid.</p>



<p class="wp-block-paragraph">It&#8217;s just blank.</p>



<p class="wp-block-paragraph">Okay, so then what I want to do is start drawing some nodes.</p>



<p class="wp-block-paragraph">What are the nodes again?</p>



<p class="wp-block-paragraph">Those are just vertices.</p>



<p class="wp-block-paragraph">Those are just like little data structure objects you can imagine in the code.</p>



<p class="wp-block-paragraph">I don&#8217;t want to get too far ahead of myself, but imagine that you have a class called graph.</p>



<p class="wp-block-paragraph">This is just one way to imagine.</p>



<p class="wp-block-paragraph">We have a class called graph and then a nested class inside of a graph called a node or a vertex</p>



<p class="wp-block-paragraph">If you want to be more fancy</p>



<p class="wp-block-paragraph">So the vertex class itself by the way</p>



<p class="wp-block-paragraph">This is not always going to be the way that you actually do this in your code the other representations that we&#8217;ll talk about sooner a little bit easier, but</p>



<p class="wp-block-paragraph">The vertex class itself needs to basically hold some data</p>



<p class="wp-block-paragraph">Depending on your implementation it might know about who it&#8217;s connected to maybe the graph knows that instead</p>



<p class="wp-block-paragraph">instead. In my implementations, the graph is going to know everything, but the vertex or the node</p>



<p class="wp-block-paragraph">itself needs to hold one piece of data. That&#8217;s kind of the whole point. So I&#8217;m going to say that</p>



<p class="wp-block-paragraph">the data type that these nodes hold are just integers. So I&#8217;m just going to put like a six in</p>



<p class="wp-block-paragraph">here just to indicate we have one node and the templated data type that it holds is an integer.</p>



<p class="wp-block-paragraph">And the specific integer for this specific node is just the number six. You can have any template</p>



<p class="wp-block-paragraph">any template type if you really want to you can people put floats in there you could put a custom</p>



<p class="wp-block-paragraph">custom class in there whatever you want but i just want to show you that we have a class called</p>



<p class="wp-block-paragraph">vertex or node and inside of it&#8217;s got a template type maybe just to make this a little bit more</p>



<p class="wp-block-paragraph">clear i&#8217;ll say you can imagine inside the vertex class uh there is a template type and we&#8217;ll call</p>



<p class="wp-block-paragraph">it uh i don&#8217;t know node node value type or something and we&#8217;ll call it data and then up</p>



<p class="wp-block-paragraph">I&#8217;m doing C++ up here.</p>



<p class="wp-block-paragraph">We have to kind of define the whole graph class as a template class.</p>



<p class="wp-block-paragraph">Now, of course, you could define the vertex class as the template class,</p>



<p class="wp-block-paragraph">but if you define the graph class as a template, then it all kind of falls through.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to say class node value type.</p>



<p class="wp-block-paragraph">And so if you&#8217;ve written template classes before in C++,</p>



<p class="wp-block-paragraph">now you know that the user can instance the graph and at the same time,</p>



<p class="wp-block-paragraph">specify what is the data type of the stuff that the nodes hold.</p>



<p class="wp-block-paragraph">the stuff that the nodes hold.</p>



<p class="wp-block-paragraph">We do the same thing for edges too,</p>



<p class="wp-block-paragraph">but notice how there are no nodes that are connected to each other.</p>



<p class="wp-block-paragraph">So we have no edges in this graph.</p>



<p class="wp-block-paragraph">This is still a valid graph,</p>



<p class="wp-block-paragraph">but we could just sort of copy a node just for fun and say,</p>



<p class="wp-block-paragraph">all right, we&#8217;ve got two nodes now, two vertices.</p>



<p class="wp-block-paragraph">They could have the same value if you want.</p>



<p class="wp-block-paragraph">Graphs are supposed to, you know, support duplicate values in the nodes,</p>



<p class="wp-block-paragraph">but I&#8217;m just going to change the value here.</p>



<p class="wp-block-paragraph">This is also a valid graph.</p>



<p class="wp-block-paragraph">You don&#8217;t really need edges to have a valid graph.</p>



<p class="wp-block-paragraph">edges to have a valid graph. This is just something called a something called a graph that is not</p>



<p class="wp-block-paragraph">connected. We&#8217;ll talk about all that terminology and how to detect it in a future video. For now,</p>



<p class="wp-block-paragraph">I&#8217;m just going to say we have like a little graph here, which is kind of boring, but I&#8217;m going to</p>



<p class="wp-block-paragraph">add an edge. An edge is basically just, you know, a little mini data structure that connects two</p>



<p class="wp-block-paragraph">nodes. Depending on the way you represent this in the machine, which we&#8217;ll talk about in future</p>



<p class="wp-block-paragraph">well, a whole bunch of different ways.</p>



<p class="wp-block-paragraph">You could imagine this as a full-fledged class,</p>



<p class="wp-block-paragraph">although that&#8217;s not always going to be the way that we represent an actual edge.</p>



<p class="wp-block-paragraph">So imagine that we have a nested class called edge.</p>



<p class="wp-block-paragraph">And inside the edge class, we&#8217;ve got, you know, some stuff.</p>



<p class="wp-block-paragraph">We could have a weight, which means the cost of traveling against the edge.</p>



<p class="wp-block-paragraph">We could have many other properties.</p>



<p class="wp-block-paragraph">For now, I&#8217;ll just try to keep it simple.</p>



<p class="wp-block-paragraph">is pretty much a collection of vertices and edges and some sort of connection.</p>



<p class="wp-block-paragraph">What is a graph really for?</p>



<p class="wp-block-paragraph">Some people at first think that a graph is another way to represent a database.</p>



<p class="wp-block-paragraph">I&#8217;m going to erase this thing over here.</p>



<p class="wp-block-paragraph">Graphs, you could sort of use them as databases,</p>



<p class="wp-block-paragraph">but they&#8217;re not very good as databases because</p>



<p class="wp-block-paragraph">it would be really, really slow to search through the graph</p>



<p class="wp-block-paragraph">to find some piece of data that you&#8217;re looking for.</p>



<p class="wp-block-paragraph">It could be like a linear time database.</p>



<p class="wp-block-paragraph">better would be to take this graph and add a bunch of rules as you probably have found</p>



<p class="wp-block-paragraph">in my other videos by now and turn it into a binary search tree.</p>



<p class="wp-block-paragraph">A binary search tree is lightning fast.</p>



<p class="wp-block-paragraph">It runs in log time.</p>



<p class="wp-block-paragraph">Hash tables are faster than binary search trees, but basically a graph is always going</p>



<p class="wp-block-paragraph">to be way slower than a binary search tree unless the binary search tree is severely</p>



<p class="wp-block-paragraph">imbalanced.</p>



<p class="wp-block-paragraph">But that&#8217;s something for another video.</p>



<p class="wp-block-paragraph">Anyway, so we have a graph and it&#8217;s not a good database.</p>



<p class="wp-block-paragraph">What would a graph be good for?</p>



<p class="wp-block-paragraph">would a graph be good for? Well, graphs are usually pretty good to help you represent</p>



<p class="wp-block-paragraph">relationships between things. For example, the six and the one, imagine the six is something,</p>



<p class="wp-block-paragraph">maybe it&#8217;s a computer, maybe it&#8217;s a city, maybe it&#8217;s, I don&#8217;t know, like a train station,</p>



<p class="wp-block-paragraph">and the edges could represent connections. So I&#8217;m just going to start changing these values</p>



<p class="wp-block-paragraph">have some nodes just kind of hanging out off to the side, not really connected to anything.</p>



<p class="wp-block-paragraph">Maybe not great for your particular use case, but like it&#8217;s a valid graph. So I&#8217;m just going to,</p>



<p class="wp-block-paragraph">I&#8217;m just going to connect this and try to make this into a better graph.</p>



<p class="wp-block-paragraph">That&#8217;s a little bit more interesting. So we&#8217;ve got graphs that do a whole bunch of different</p>



<p class="wp-block-paragraph">things. Let me change these values real fast. I&#8217;ll maybe turn that into a 13 and turn that</p>



<p class="wp-block-paragraph">So imagine that we have like a little connection here, a little connection here, maybe another</p>



<p class="wp-block-paragraph">connection here and another one there.</p>



<p class="wp-block-paragraph">And you know, you are allowed to have connections that sort of look weird, like going from this</p>



<p class="wp-block-paragraph">six all the way around to this 13.</p>



<p class="wp-block-paragraph">That&#8217;s totally valid also.</p>



<p class="wp-block-paragraph">So I&#8217;ve basically just drawn a random graph, random nodes and random edges.</p>



<p class="wp-block-paragraph">Imagine that every single node here is a computer in a computer network and imagine every edge</p>



<p class="wp-block-paragraph">every edge which connects the nodes is just some sort of a connection let&#8217;s say a network cable</p>



<p class="wp-block-paragraph">or a wi-fi signal or something like that so if you imagine it that way then this graph could</p>



<p class="wp-block-paragraph">represent a network topology a bunch of computers connected together if these were cities and this</p>



<p class="wp-block-paragraph">is like actually maybe these are airports in cities you could imagine a graph could represent</p>



<p class="wp-block-paragraph">the relationship between different airports in which planes will fly notice on this graph just</p>



<p class="wp-block-paragraph">that the uh you know the uh the city number one uh there are no flights connecting it directly to</p>



<p class="wp-block-paragraph">city 44 but you could probably imagine well if we take a flight to uh from city one to city 10 and</p>



<p class="wp-block-paragraph">then from city 10 to 44 then we can get from one to 44 we just have to be clever about our connecting</p>



<p class="wp-block-paragraph">flights um let&#8217;s see so we could do like road maps airport maps the worldwide web is basically a graph</p>



<p class="wp-block-paragraph">at least from a certain perspective electrical circuits that are connected to each other</p>



<p class="wp-block-paragraph">are connected to each other even game maps what if your character is allowed to stand here in</p>



<p class="wp-block-paragraph">in space number three on some map and the character is only allowed to travel to space 13 or</p>



<p class="wp-block-paragraph">space 6 but not directly to space 1 well it could be a map that helps you understand where your</p>



<p class="wp-block-paragraph">character can go in a game okay so that&#8217;s like the basic idea of of what a graph is and uh how it</p>



<p class="wp-block-paragraph">actual four types of graphs that I&#8217;m going to go over in more detail in future videos. Let&#8217;s see,</p>



<p class="wp-block-paragraph">what time is it right now? We got like 10 minutes. Okay, so I can still kind of make this fast.</p>



<p class="wp-block-paragraph">So the first type of graph that we&#8217;re looking at right now is actually something called an</p>



<p class="wp-block-paragraph">undirected, unweighted graph. Why is it, let&#8217;s see, let me write this down first. It&#8217;s an undirected,</p>



<p class="wp-block-paragraph">undirected, unweighted graph. So why is this undirected? Because the edges don&#8217;t have direction.</p>



<p class="wp-block-paragraph">If I was standing in, you know, city six and I wanted to like drive or fly or whatever</p>



<p class="wp-block-paragraph">from city six to city three, then I should be able to do it because this edge that connects</p>



<p class="wp-block-paragraph">them doesn&#8217;t really say that I have to go in one direction or the other. I could also go to city</p>



<p class="wp-block-paragraph">three and then just walk right back or fly right back to city six. There&#8217;s no direction. So there&#8217;s</p>



<p class="wp-block-paragraph">no direction. So there&#8217;s an this that&#8217;s that&#8217;s why this is an undirected graph. This is an</p>



<p class="wp-block-paragraph">unweighted graph because we haven&#8217;t specified a cost for traveling along an edge. For example,</p>



<p class="wp-block-paragraph">if you know, if you&#8217;re at city three here, and you want to fly to city 13, how much jet fuel</p>



<p class="wp-block-paragraph">does it cost? How much time does it cost? If three is a computer and 13 is a computer,</p>



<p class="wp-block-paragraph">and the edges like a network cable, like how much money does it cost to transmit the data?</p>



<p class="wp-block-paragraph">transmit the data or what is the lag in milliseconds.</p>



<p class="wp-block-paragraph">You know, you can represent all sorts of things with these edges,</p>



<p class="wp-block-paragraph">but there&#8217;s no value on these edges,</p>



<p class="wp-block-paragraph">which means there are no weights to these edges.</p>



<p class="wp-block-paragraph">So that&#8217;s why this is an undirected and also unweighted graph.</p>



<p class="wp-block-paragraph">Uh, the first upgrade that I want to do is just kind of show you what you can</p>



<p class="wp-block-paragraph">sort of assume about an unweighted graph. This is not always true.</p>



<p class="wp-block-paragraph">It just depends on who you talk to and what your application implementations are.</p>



<p class="wp-block-paragraph">So imagine the node that goes from six, sorry, the edge that goes from six to one.</p>



<p class="wp-block-paragraph">If it&#8217;s an unweighted graph, you could just probably imagine that every weight is just a one.</p>



<p class="wp-block-paragraph">The point being that it always costs the same amount to travel along every edge,</p>



<p class="wp-block-paragraph">because in an unweighted graph, we don&#8217;t differentiate between the different edges</p>



<p class="wp-block-paragraph">in terms of their costs.</p>



<p class="wp-block-paragraph">We could just put a bunch of ones on all these edges.</p>



<p class="wp-block-paragraph">And it would still, you know, basically be considered an unweighted graph.</p>



<p class="wp-block-paragraph">It depends on who you talk to.</p>



<p class="wp-block-paragraph">maybe all the weights are zero, maybe all the weights are 10 or whatever.</p>



<p class="wp-block-paragraph">But, you know, usually I put a one there because I&#8217;d like to imagine the cost could just be the number of hops.</p>



<p class="wp-block-paragraph">So, for example, if I wanted to go from city six to city 10,</p>



<p class="wp-block-paragraph">I could probably, you know, start at city six and then go to city one and then hop to city 10.</p>



<p class="wp-block-paragraph">How many actual hops did I do? I did two.</p>



<p class="wp-block-paragraph">I could also come up with that number by just looking at the sum of all the weights of all the edges.</p>



<p class="wp-block-paragraph">all the edges. So notice how when I go from six to one, that costs me one weight or one hop. And</p>



<p class="wp-block-paragraph">then when I go from one to 10, that&#8217;s another one. So if you put ones on all the edges in an</p>



<p class="wp-block-paragraph">unweighted graph, then you&#8217;re kind of saying the total cost of some path is really just the number</p>



<p class="wp-block-paragraph">of hops. So it&#8217;s up to you. Anyway, that&#8217;s unweighted and undirected. Let&#8217;s upgrade this</p>



<p class="wp-block-paragraph">see we have an undirected and unweighted and i&#8217;m just going to duplicate this real fast and change</p>



<p class="wp-block-paragraph">this to a weighted graph so undirected but also weighted and the thing is as soon as you start</p>



<p class="wp-block-paragraph">putting numbers on a graph on the edges of a graph well then it&#8217;s considered weighted so even even a</p>



<p class="wp-block-paragraph">graph that has all ones on all the edges you could also call that weighted but now you have the</p>



<p class="wp-block-paragraph">freedom since it is considered a weighted graph to just assign different values to all the edges</p>



<p class="wp-block-paragraph">to all the edges. Again, these edges are a class sometimes, or you can think of them that way</p>



<p class="wp-block-paragraph">inside the graph. And the edge weights themselves are definitely considered a T type, a templated</p>



<p class="wp-block-paragraph">type, which means, you know, right now I&#8217;m clearly typing integers, but you could type some other</p>



<p class="wp-block-paragraph">data type. You could type floats. You could type some weird data type, like a string.</p>



<p class="wp-block-paragraph">Whether or not that&#8217;s going to be useful depends on your program, you know, what you&#8217;re trying to</p>



<p class="wp-block-paragraph">you know, what you&#8217;re trying to do with the graph. But let&#8217;s see, I think I&#8217;ve added custom numbers</p>



<p class="wp-block-paragraph">to every single edge. So now this is definitely an undirected, but weighted graph. That&#8217;s the</p>



<p class="wp-block-paragraph">second type of graph that we&#8217;re talking about. Okay, what&#8217;s what&#8217;s cool about a weighted graph?</p>



<p class="wp-block-paragraph">Well, imagine again, that this is an airport map, where we&#8217;re representing relationships between,</p>



<p class="wp-block-paragraph">you know, cities, like where can we fly and stuff. We&#8217;re basically saying at this point,</p>



<p class="wp-block-paragraph">it&#8217;s going to cost you 44 of something.</p>



<p class="wp-block-paragraph">Maybe this is a graph representing jet fuel or time or frequent flyer points or something like that.</p>



<p class="wp-block-paragraph">If you consider your edges to be custom classes,</p>



<p class="wp-block-paragraph">you could even put a whole bunch of different types of values in your graph at the same time</p>



<p class="wp-block-paragraph">to make it a little bit more flexible.</p>



<p class="wp-block-paragraph">But for now, we&#8217;ll just say there&#8217;s one templated type,</p>



<p class="wp-block-paragraph">which means if we go back up to this code real fast, where was that code at?</p>



<p class="wp-block-paragraph">Where was that code at?</p>



<p class="wp-block-paragraph">And we had, you know, our rough idea of, you know, what the, what the graph holds, you</p>



<p class="wp-block-paragraph">know, it holds like vertices and edges.</p>



<p class="wp-block-paragraph">We could upgrade this just a little bit to say that there is a, an edge value type.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say class edge value, edge weight type, something like that.</p>



<p class="wp-block-paragraph">for the edge so that I can save characters. And then here, I&#8217;ll change this to a type for the</p>



<p class="wp-block-paragraph">node. This is why we call it T type. There&#8217;s like, we put the keyword template here in C++.</p>



<p class="wp-block-paragraph">And then sometimes people just use T&#8217;s here for these tokens. So I&#8217;m just going to say</p>



<p class="wp-block-paragraph">the type of data that a node can hold is going to be the T node. And then the type of data that</p>



<p class="wp-block-paragraph">the edge could hold would be the T edge. We&#8217;ll call that data. Or we could call that weight,</p>



<p class="wp-block-paragraph">because usually that data comes into play when you&#8217;re traveling along an edge, right? So there&#8217;s</p>



<p class="wp-block-paragraph">traveling along an edge, right? So there&#8217;s like two different types here. Anyway, so we got an</p>



<p class="wp-block-paragraph">undirected and unweighted graph. If we traveled from city six to city one, that costs us 44. But</p>



<p class="wp-block-paragraph">if you look at the graph a little bit more closely, we could take the longer way around. We could say</p>



<p class="wp-block-paragraph">go from six to three, and then go from three to 13. And then actually, let me change the color</p>



<p class="wp-block-paragraph">to orange so that you can see there&#8217;s different paths, six to three, and then three to 13,</p>



<p class="wp-block-paragraph">and then 13 to one, even though we took more hops,</p>



<p class="wp-block-paragraph">and that might have been considered more expensive</p>



<p class="wp-block-paragraph">in an unweighted graph,</p>



<p class="wp-block-paragraph">you can see that the cost of the first path</p>



<p class="wp-block-paragraph">from six to one, that&#8217;s 44.</p>



<p class="wp-block-paragraph">And the cost of the second path is seven plus three,</p>



<p class="wp-block-paragraph">that&#8217;s 10, and then plus nine, so that&#8217;s 19.</p>



<p class="wp-block-paragraph">So if we take the long way,</p>



<p class="wp-block-paragraph">it actually costs us less</p>



<p class="wp-block-paragraph">of whatever we&#8217;ve determined this unit is.</p>



<p class="wp-block-paragraph">You know, less jet fuel, less time, less whatever.</p>



<p class="wp-block-paragraph">less whatever these graphs in the machine are not necessarily going to be to scale because the</p>



<p class="wp-block-paragraph">machine in your computer your computer doesn&#8217;t really keep track of like the physical positioning</p>



<p class="wp-block-paragraph">of all these nodes and edges it just can keeps track of the relationship between the nodes and</p>



<p class="wp-block-paragraph">the edges and the weights and all that stuff so two different paths that we could take to get</p>



<p class="wp-block-paragraph">from six to one one of the paths is less expensive um or less time costly or just whatever and a graph</p>



<p class="wp-block-paragraph">data structure can kind of help us figure that out if we&#8217;re using an algorithm that understands</p>



<p class="wp-block-paragraph">weights okay so undirected and unweighted let&#8217;s add direction so um i&#8217;m going to erase this stuff</p>



<p class="wp-block-paragraph">right here real quick and in an undirected graph remember you can just kind of go in either</p>



<p class="wp-block-paragraph">direction along any edge but in a directed graph every single edge needs to have a direction so as</p>



<p class="wp-block-paragraph">I change one of the edges to have direction, then I must change all of the edges to have direction</p>



<p class="wp-block-paragraph">as well. So I&#8217;m just saying, okay, as soon as I did that, now this is an invalid graph</p>



<p class="wp-block-paragraph">because some of the edges don&#8217;t have direction. So now I need to fix everything. So I just,</p>



<p class="wp-block-paragraph">I&#8217;m going to arbitrarily and randomly choose a direction for every single edge like this.</p>



<p class="wp-block-paragraph">And then as soon as I&#8217;m done, I&#8217;m going to deal, I guess, with that giant edge</p>



<p class="wp-block-paragraph">that giant edge. So I&#8217;m going to go like that. So let&#8217;s see, all the edges seem to have direction.</p>



<p class="wp-block-paragraph">Now I&#8217;m just going to hand draw an arrow on one side of this giant edge. Okay. So this is directed</p>



<p class="wp-block-paragraph">and also weighted. What can we do with the directed graph? Well, it just basically tells</p>



<p class="wp-block-paragraph">you which direction you&#8217;re allowed to travel in. What if you have an airport where city six can</p>



<p class="wp-block-paragraph">only fly to city one, but city one, for some reason, never flies to city six. You got to take</p>



<p class="wp-block-paragraph">take like the long way you got to go from city one to 13 to three to six that&#8217;s something that</p>



<p class="wp-block-paragraph">a graph could help you represent what if your character in your game can only go in one direction</p>



<p class="wp-block-paragraph">but not the other direction okay no problem i mean that&#8217;s pretty much it you&#8217;re only allowed</p>



<p class="wp-block-paragraph">to travel in the same direction as the edge points but now we have a graph that is a lot less</p>



<p class="wp-block-paragraph">flexible because for example before we used to be able to go from city uh 10 to city 44 and then</p>



<p class="wp-block-paragraph">then come back again later if we wanted in the opposite direction. We can no longer do that</p>



<p class="wp-block-paragraph">because this edge only goes to 10. It doesn&#8217;t even go to 44. We can&#8217;t even ever actually get to 44.</p>



<p class="wp-block-paragraph">How do you sort of solve that? Well, just add another edge in the opposite direction.</p>



<p class="wp-block-paragraph">In graphs, you are allowed to do something called a parallel edge,</p>



<p class="wp-block-paragraph">which just basically means, you know, two edges between the same pair of nodes that just point</p>



<p class="wp-block-paragraph">in the same direction. You&#8217;re also allowed to do, you know, opposite facing edges. So</p>



<p class="wp-block-paragraph">edges so i just added a second edge there going from 10 to 44 and now if i was you know hanging</p>



<p class="wp-block-paragraph">out in city 10 i could just go back and forth between city 10 and 44 as much as i wanted to</p>



<p class="wp-block-paragraph">oh i forgot to add an edge weight for that new edge which means i wrote down an invalid graph</p>



<p class="wp-block-paragraph">so i&#8217;m just going to say two so uh maybe the wind is blowing in in your favor when you&#8217;re going from</p>



<p class="wp-block-paragraph">city 10 to city 44 maybe it&#8217;s blowing against you if you&#8217;re talking about city 44 to city 10 you</p>



<p class="wp-block-paragraph">you know whatever but you just have to have edge uh edge weight on every single edge</p>



<p class="wp-block-paragraph">okay so uh that&#8217;s directed and also weighted um and you can probably imagine previously when we</p>



<p class="wp-block-paragraph">had an undirected um graph when there was just like you know one edge going between uh two nodes</p>



<p class="wp-block-paragraph">and there was no direction on it like you know 44 to 10 if we just had like one edge with no</p>



<p class="wp-block-paragraph">have two edges each going in the opposite direction so we have directed and weighted i think the last</p>



<p class="wp-block-paragraph">thing that we didn&#8217;t do was directed and unweighted right so we have let me just double check real</p>



<p class="wp-block-paragraph">fast here we have undirected and unweighted and then we had undirected and weighted and then</p>



<p class="wp-block-paragraph">directed and weighted okay so now let&#8217;s do um i&#8217;m getting lost already oh my gosh i can&#8217;t believe i</p>



<p class="wp-block-paragraph">I saw undirected and unweighted so we did undirected twice already undirected so we&#8217;re</p>



<p class="wp-block-paragraph">going to do directed and unweighted next okay so the next graph a little bit less useful than</p>



<p class="wp-block-paragraph">what we&#8217;re looking at this this type of graph is a little bit more useful we&#8217;re going to do</p>



<p class="wp-block-paragraph">directed and unweighted oh my god okay directed and unweighted so directed and unweighted you</p>



<p class="wp-block-paragraph">Directed and unweighted, you can imagine, just means we get rid of all these weights.</p>



<p class="wp-block-paragraph">And then we keep the direction on all the edges.</p>



<p class="wp-block-paragraph">So this means we can keep track of where we&#8217;re allowed to go, if we&#8217;re pathfinding or just whatever.</p>



<p class="wp-block-paragraph">But we don&#8217;t really know what it costs to travel between the different graphs.</p>



<p class="wp-block-paragraph">So that&#8217;s directed and unweighted.</p>



<p class="wp-block-paragraph">Let&#8217;s see here.</p>



<p class="wp-block-paragraph">I&#8217;m going to just duplicate this or just make a new blank slide.</p>



<p class="wp-block-paragraph">Okay, undirected, oh gosh, I&#8217;ve got pink letters.</p>



<p class="wp-block-paragraph">Let&#8217;s see, undirected plus unweighted.</p>



<p class="wp-block-paragraph">And we&#8217;ve got undirected plus weighted.</p>



<p class="wp-block-paragraph">And then we&#8217;ve got directed plus unweighted.</p>



<p class="wp-block-paragraph">I don&#8217;t think I&#8217;m writing these down in the same order,</p>



<p class="wp-block-paragraph">but that&#8217;s okay.</p>



<p class="wp-block-paragraph">And then we&#8217;ve got directed plus weighted.</p>



<p class="wp-block-paragraph">So basically, you know, four types of graphs</p>



<p class="wp-block-paragraph">that we can talk about.</p>



<p class="wp-block-paragraph">In future videos, we&#8217;re going to go over graphs</p>



<p class="wp-block-paragraph">in more detail.</p>



<p class="wp-block-paragraph">We&#8217;ll talk about graph terminology,</p>



<p class="wp-block-paragraph">maybe some pathfinding algorithms.</p>



<p class="wp-block-paragraph">And yeah, so this is just a basic intro.</p>



<p class="wp-block-paragraph">How much time do we spend already?</p>



<p class="wp-block-paragraph">Oh God, we spent so much time.</p>



<p class="wp-block-paragraph">Spent like 22 minutes.</p>



<p class="wp-block-paragraph">Dang, man, even the smallest thing takes time.</p>



<p class="wp-block-paragraph">So I&#8217;ll see you in a future video</p>



<p class="wp-block-paragraph">when we talk more and more and more about graphs</p>



<p class="wp-block-paragraph">and other data structures concepts.</p>



<p class="wp-block-paragraph">Thanks for watching this video.</p>



<p class="wp-block-paragraph">I hope you learned a little bit of stuff</p>



<p class="wp-block-paragraph">I hope you learned a little bit of stuff and had a little bit of fun.</p>



<p class="wp-block-paragraph">I&#8217;m out of here.</p>



<p class="wp-block-paragraph">Go.</p>



<p class="wp-block-paragraph">Hey, everybody.</p>



<p class="wp-block-paragraph">Thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor,</p>



<p class="wp-block-paragraph">could you please subscribe and follow this channel or these videos</p>



<p class="wp-block-paragraph">or whatever it is you do on the current social media website that you&#8217;re looking at right now,</p>



<p class="wp-block-paragraph">it would really mean the world to me.</p>



<p class="wp-block-paragraph">And it&#8217;ll help make more videos and grow this community.</p>



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up because I know somebody subscribed or followed.</p>



<p class="wp-block-paragraph">It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could you control me if you want to just wake me up in the middle</p>



<p class="wp-block-paragraph">And I just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now</p>



<p class="wp-block-paragraph">You should see a QR code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video and</p>



<p class="wp-block-paragraph">It&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p class="wp-block-paragraph">I published and the services and tutorials and things that I offer and all that good stuff and</p>



<p class="wp-block-paragraph">and if you have a suggestion for clarifications or errata or just future</p>



<p class="wp-block-paragraph">videos that you want to see please leave a comment or if you just want to say hey</p>



<p class="wp-block-paragraph">what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake</p>



<p class="wp-block-paragraph">up for those in the middle of the night I get I wake up in a cold sweat I&#8217;m like</p>



<p class="wp-block-paragraph">it would really it really mean the world to me I would really appreciate it so</p>



<p class="wp-block-paragraph">enjoy the cool music as as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>



<p class="wp-block-paragraph">I&#8217;m going to go ahead and get started.</p>



<p class="wp-block-paragraph">Thank you.</p>



<p class="wp-block-paragraph">Hello there.</p>



<p class="wp-block-paragraph">Let&#8217;s talk about the four types of…</p>



<p class="wp-block-paragraph">Hello there.</p>
<p>The post <a href="https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/">4 Graph Types: Undirected vs Directed, Weighted vs Unweighted</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
