<?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>adjacency matrix Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/adjacency-matrix/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/adjacency-matrix/</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>adjacency matrix Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/adjacency-matrix/</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 Undirected Weighted Graphs Using an Adjacency Matrix</title>
		<link>https://www.NeuralLantern.com/how-to-represent-undirected-weighted-graphs-using-an-adjacency-matrix/</link>
					<comments>https://www.NeuralLantern.com/how-to-represent-undirected-weighted-graphs-using-an-adjacency-matrix/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 19 Oct 2026 05:40:19 +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[algorithms]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[constant time access]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[graph representation]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[infinity sentinel]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[self-loop]]></category>
		<category><![CDATA[undirected graph]]></category>
		<category><![CDATA[weighted graph]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=441</guid>

					<description><![CDATA[<p>Represent an undirected weighted graph with an adjacency matrix by placing each edge weight in the corresponding row and column. Use infinity for missing connections so a genuine zero weight remains possible. The matrix is symmetric across the identity line, making it simple to verify, and any cell can be read or written in constant time.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-represent-undirected-weighted-graphs-using-an-adjacency-matrix/">How to Represent Undirected Weighted Graphs Using 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 Undirected Weighted Graphs Using an Adjacency Matrix" width="1380" height="776" src="https://www.youtube.com/embed/QwPAJF50nlo?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 cover how to represent an undirected weighted graph with an adjacency matrix. You will see how to place edge weights into the matrix cells and why infinity is used for missing connections so that a real weight of zero stays available. Because the graph is undirected the finished matrix is symmetric across the identity line, which gives an easy way to check your work. We also look at self-connections and at practical ways to store infinity in code such as language sentinels, optionals, or null pointers. Accessing or updating any cell remains constant time, so adding or removing an edge is fast.</p>



<p class="wp-block-paragraph">00:00 Introduction to Undirected Weighted Graphs<br>00:41 What Undirected and Weighted Means<br>01:08 Matrix is Constant Time Under the Hood<br>02:28 Starting to Fill the Adjacency Matrix<br>04:12 Using Infinity for No Connection<br>06:05 Filling the Matrix and Noticing the Mirror<br>08:24 Using the Mirror to Speed Up Filling<br>11:21 How to Represent Infinity in Code<br>14:09 Adding Self-Connections<br>15:46 The Mirror Along the Identity Line<br>18:21 Adding and Removing Edges in Constant Time<br>19:49 Conclusion and What&#8217;s Next<br>20:02 Subscribe 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">Hey there! Let&#8217;s talk about how to represent undirected and weighted graphs</p>



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



<p class="wp-block-paragraph">A lot of words, right? Okay, so in the last video we talked about how to do an</p>



<p class="wp-block-paragraph">adjacency matrix for an undirected and unweighted graph. Now we&#8217;re doing another</p>



<p class="wp-block-paragraph">graph but it has weights on all the edges so it&#8217;s a weighted graph and we&#8217;re</p>



<p class="wp-block-paragraph">going to learn how to do that in an adjacency matrix</p>



<p class="wp-block-paragraph">learn how to do that in an adjacency matrix as well. If you haven&#8217;t watched the previous video</p>



<p class="wp-block-paragraph">you probably should although I&#8217;m going to kind of do this from scratch anyway so I think you&#8217;ll be</p>



<p class="wp-block-paragraph">okay if you don&#8217;t want to watch the other one. Okay so the first thing to understand is we have</p>



<p class="wp-block-paragraph">undirected and weighted which means undirected says there&#8217;s no direction on any of the edges</p>



<p class="wp-block-paragraph">you can see all the edges are just lines there&#8217;s no arrows. Weighted means there&#8217;s a cost to</p>



<p class="wp-block-paragraph">traveling along every single edge.</p>



<p class="wp-block-paragraph">So that&#8217;s why there are numbers on every single edge.</p>



<p class="wp-block-paragraph">And then,</p>



<p class="wp-block-paragraph">on every single edge and then we&#8217;re going to use a two-dimensional matrix to represent this graph</p>



<p class="wp-block-paragraph">inside your machine like this is kind of how you would code a graph the first thing to understand</p>



<p class="wp-block-paragraph">is that this two-dimensional matrix it&#8217;s really a one-dimensional matrix under the hood you know</p>



<p class="wp-block-paragraph">we have like a i&#8217;m going to put like a pound sign for a number imagine we have a whole bunch of</p>



<p class="wp-block-paragraph">numbers in a one-dimensional array we could reorganize those numbers if we wanted to</p>



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



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



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



<p class="wp-block-paragraph">to um with i should have had one less number there and we could just reorganize those if we wanted to</p>



<p class="wp-block-paragraph">to look two-dimensional but it still would be a you know what did i just do wrong i think oh i</p>



<p class="wp-block-paragraph">have to hit this 100 thing what is going on here uh f11 oh i forgot to hit the full screen okay</p>



<p class="wp-block-paragraph">so uh yeah we can represent this one-dimensional matrix sorry one-dimensional array as a</p>



<p class="wp-block-paragraph">two-dimensional matrix. You can do this with any number of dimensions.</p>



<p class="wp-block-paragraph">you can do this with any number of dimensions and what I&#8217;m really what I&#8217;m really trying to say is</p>



<p class="wp-block-paragraph">that accessing any particular cell within the matrix even though it&#8217;s like you got to go down</p>



<p class="wp-block-paragraph">you got to go to the right as a human the computer can still get there in constant time we&#8217;ll talk</p>



<p class="wp-block-paragraph">about time complexities in a different video but just understand it&#8217;s very fast to just reach one</p>



<p class="wp-block-paragraph">cell in the matrix and that&#8217;s true even for an n-dimensional matrix like 19 dimensions you can</p>



<p class="wp-block-paragraph">still reach one cell in constant time. Super, super fast. Okay, so now let&#8217;s&#8230;</p>



<p class="wp-block-paragraph">Okay, so now let&#8217;s try to figure out how we can fill out this matrix so that this graph is represented accurately in the machine.</p>



<p class="wp-block-paragraph">So I&#8217;m going to get rid of maybe this first.</p>



<p class="wp-block-paragraph">And so there&#8217;s no direction on this graph, which means it doesn&#8217;t really matter which node starts and which node ends.</p>



<p class="wp-block-paragraph">You know, what&#8217;s the source and what&#8217;s the sink?</p>



<p class="wp-block-paragraph">What&#8217;s the beginning and what&#8217;s the end or the finish or whatever you want to call it?</p>



<p class="wp-block-paragraph">and we&#8217;re going to end up seeing a mirror in this matrix along the</p>



<p class="wp-block-paragraph">mirror in this matrix along the identity line so just to let you know half of this matrix is kind</p>



<p class="wp-block-paragraph">of wasted memory that&#8217;s okay but I&#8217;ll show you what I mean so what I like to do when I&#8217;m filling</p>



<p class="wp-block-paragraph">these matrices out is I like to say that the start node is the row and the destination node is the</p>



<p class="wp-block-paragraph">column I know I just said that that doesn&#8217;t matter which way you start so you can do it you know your</p>



<p class="wp-block-paragraph">own way but for me I like to say that the row number starts because that helps me later when</p>



<p class="wp-block-paragraph">and we add a direction to all the edges.</p>



<p class="wp-block-paragraph">direction to all the edges so if i start at node one let&#8217;s uh here let me just highlight this real</p>



<p class="wp-block-paragraph">fast if i start at node one and i say how do we fill this out well i&#8217;m just going to go into the</p>



<p class="wp-block-paragraph">matrix and i&#8217;m going to say row one because that&#8217;s the start node and um column wherever it goes to</p>



<p class="wp-block-paragraph">uh the one node right now i&#8217;m going to say that the nodes don&#8217;t connect to themselves</p>



<p class="wp-block-paragraph">because i just want the option of a self-connect edge that you can see so right now there&#8217;s no loop</p>



<p class="wp-block-paragraph">coming out of the one and then going back into the one we can add that later but for now i&#8217;m just</p>



<p class="wp-block-paragraph">going to say by default there are no self-connects unless you see it in the diagram so the one node</p>



<p class="wp-block-paragraph">going to the two node you can see that it does connect to the two node so in our unweighted</p>



<p class="wp-block-paragraph">graph we just put a one to say there&#8217;s a connection or zero for no connection we have to upgrade this</p>



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



<p class="wp-block-paragraph">this now so because we can add a weight to every single edge that means it&#8217;s</p>



<p class="wp-block-paragraph">totally possible that you might have an edge that has a weight of zero which</p>



<p class="wp-block-paragraph">would mean representing no connection as zero doesn&#8217;t make as much sense anymore</p>



<p class="wp-block-paragraph">so instead of a zero to say no connection because we could we could</p>



<p class="wp-block-paragraph">have like negative numbers positive numbers we could say that an edge costs</p>



<p class="wp-block-paragraph">nothing like if you&#8217;re using a graph to make a game with like decisions or</p>



<p class="wp-block-paragraph">something maybe it doesn&#8217;t cost the character anything to go open the door</p>



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



<p class="wp-block-paragraph">open the door or whatever let&#8217;s say that zero cost actually is infinity i&#8217;m going to say inf</p>



<p class="wp-block-paragraph">maybe that&#8217;s going to get too big later infinity means no uh connection it means an infinity cost</p>



<p class="wp-block-paragraph">and usually i like to say have you ever like gone to google maps and you said like how do i how do i</p>



<p class="wp-block-paragraph">walk from florida to china and google maps is like well i don&#8217;t know if they do this now but a long</p>



<p class="wp-block-paragraph">time ago they would say jump into the ocean and swim so you know</p>



<p class="wp-block-paragraph">swim um so you know what&#8217;s going to happen you&#8217;re going to die so the cost is infinity you can&#8217;t get</p>



<p class="wp-block-paragraph">there so if the cost is infinity you&#8217;ll never get there so infinity cost means no connection</p>



<p class="wp-block-paragraph">is that a dumb joke uh leave a leave a comment anyway but uh the connection from one to two we</p>



<p class="wp-block-paragraph">can see that it exists and there&#8217;s a seven right there so it costs seven to go from one to two or</p>



<p class="wp-block-paragraph">from two to one um so i&#8217;m going to go uh to node number three so from one to three that is connected</p>



<p class="wp-block-paragraph">it&#8217;s going to cost us nine.</p>



<p class="wp-block-paragraph">connected it&#8217;s going to cost us nine from one to four um i see a connection it costs 12 can be</p>



<p class="wp-block-paragraph">embarrassing if i notice an edge that doesn&#8217;t have a weight on it we go from one to five uh that is</p>



<p class="wp-block-paragraph">connected and it seems to cost one and then if we go from one to six that also is connected it costs</p>



<p class="wp-block-paragraph">nine i made these graphs too dense we go from one to seven there&#8217;s no connection there so the cost</p>



<p class="wp-block-paragraph">is infinity because you can&#8217;t do it okay then we just repeat the process again and again and again</p>



<p class="wp-block-paragraph">And if you&#8217;re going to do that, you&#8217;re going to have to do it in a different way.</p>



<p class="wp-block-paragraph">the process again and again and again and eventually we&#8217;ll start to see a mirror show up</p>



<p class="wp-block-paragraph">i&#8217;ll show you in a sec so going from two to one um two to one cost seven notice how there&#8217;s also</p>



<p class="wp-block-paragraph">there&#8217;s already a little bit of a mirror happening right seven here and then seven down here</p>



<p class="wp-block-paragraph">two going to two we&#8217;re gonna say again by default uh there&#8217;s no connection two to three uh that&#8217;s</p>



<p class="wp-block-paragraph">a cost of two two to four no connection so infinity cost and then uh two to five</p>



<p class="wp-block-paragraph">and then uh two to five getting lost already uh no connection i don&#8217;t think i see the connection</p>



<p class="wp-block-paragraph">and then uh two to six uh nope so another infinity and then two to seven</p>



<p class="wp-block-paragraph">uh yeah there is a connection and it costs four okay almost screwed that one up so then we just</p>



<p class="wp-block-paragraph">say you know all the other nodes i&#8217;m going to continue from three to one uh that&#8217;s a cost of</p>



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



<p class="wp-block-paragraph">a cost of nine notice how from one to three was also a nine we&#8217;re starting to see the mirror the</p>



<p class="wp-block-paragraph">mirror is kind of good for you know debugging your your your matrix after you make it um we won&#8217;t be</p>



<p class="wp-block-paragraph">able to do that with directed graphs but for now we can three to two is a cost of two and uh three</p>



<p class="wp-block-paragraph">to three will say no connection by default uh three to four um there&#8217;s no connection i don&#8217;t</p>



<p class="wp-block-paragraph">think and then um three to five three to five there&#8217;s a</p>



<p class="wp-block-paragraph">three to five there&#8217;s a three cost there there&#8217;s a weight of three three to six um yes with the</p>



<p class="wp-block-paragraph">cost of seven and then three to seven um i don&#8217;t see a connection so i&#8217;m gonna put infinity cost</p>



<p class="wp-block-paragraph">okay uh going from four to one notice the mirror it should cost twelve and then from four to two</p>



<p class="wp-block-paragraph">four to four we&#8217;ll say no self connections by default infinity four to five</p>



<p class="wp-block-paragraph">nope four to six uh nope and then four to seven yes at a cost of thirteen and do the same thing</p>



<p class="wp-block-paragraph">all right for the five okay so the five um is connected to the one yes or no yes with the cost</p>



<p class="wp-block-paragraph">of one to five.</p>



<p class="wp-block-paragraph">I could just look at the mirror if I wanted to.</p>



<p class="wp-block-paragraph">look at the mirror if i wanted to like like by the time you get further down in the graph here&#8217;s a</p>



<p class="wp-block-paragraph">trick by the time i&#8217;m all the way down here at the five i can just start looking at the columns</p>



<p class="wp-block-paragraph">i can say well what&#8217;s going on with column five i could just say well column five has a one in the</p>



<p class="wp-block-paragraph">one row and then infinity in the next row and then a three in the next row after that and then</p>



<p class="wp-block-paragraph">another infinity and i can i could double check this right now just to make sure but the five is</p>



<p class="wp-block-paragraph">connected to the one at a cost of five, right? And then the five is not connected to the two.</p>



<p class="wp-block-paragraph">is not connected to the two and the five is connected to the three with the cost</p>



<p class="wp-block-paragraph">of three and it&#8217;s not connected to the four notice how that matches so the</p>



<p class="wp-block-paragraph">further down I go the further I can sort of just look back at the previous rows</p>



<p class="wp-block-paragraph">or the previous previously done columns so I don&#8217;t have to think which I just I</p>



<p class="wp-block-paragraph">really like not having to think sometimes five and six I do like to</p>



<p class="wp-block-paragraph">think it&#8217;s fun it&#8217;s gonna be five okay so then five to seven is going to be a</p>



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



<p class="wp-block-paragraph">going to be a two and then we&#8217;ll move on so i&#8217;m going to do that trick again i&#8217;m going to look</p>



<p class="wp-block-paragraph">at the six column and i&#8217;m just going to start copying stuff so we have like a nine and then</p>



<p class="wp-block-paragraph">infinity and then seven oops seven and then infinity and then uh five and then i&#8217;ll just</p>



<p class="wp-block-paragraph">double check it since this is supposed to be professional tutorial video um six going to nine</p>



<p class="wp-block-paragraph">what what what no no six going to one is nine yeah six going to one is nine and then six does not go</p>



<p class="wp-block-paragraph">to two and then six goes to three with seven yes and then six goes to does not go to four correct</p>



<p class="wp-block-paragraph">six does not six goes to five with the cost of five okay so then i have to think now uh we&#8217;ll</p>



<p class="wp-block-paragraph">say no self connections and then um uh six going to seven i see that there&#8217;s a cost of six there</p>



<p class="wp-block-paragraph">okay we&#8217;re making progress um i&#8217;m going to duplicate this in case i screw it up</p>



<p class="wp-block-paragraph">so now let&#8217;s look at the seven node so the seven node uh i&#8217;m just going to copy everything i&#8217;m</p>



<p class="wp-block-paragraph">actually allowed to do that at this point and then i&#8217;ll double check it so look at the seven</p>



<p class="wp-block-paragraph">column i&#8217;m going to put infinity and then four and then infinity and then 13 and then two</p>



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



<p class="wp-block-paragraph">and then six and then seven is not connected to itself then i&#8217;ll just double check this to make</p>



<p class="wp-block-paragraph">sure that i&#8217;m okay so uh seven uh to one nope um seven to two that should cost four</p>



<p class="wp-block-paragraph">yep seven to three nope correct seven to four thirteen seven to five costs two seven to six</p>



<p class="wp-block-paragraph">cost six and then seven uh self-connection by default we say they are not connected okay so</p>



<p class="wp-block-paragraph">we filled out an entire adjacency matrix maybe there&#8217;s something else i should mention too</p>



<p class="wp-block-paragraph">before i forget um how do you represent infinity if uh we have a double value here so like if we&#8217;re</p>



<p class="wp-block-paragraph">talking about actual code there&#8217;s a whole bunch of different ways to do it um like for instance</p>



<p class="wp-block-paragraph">in javascript you could put man not a number uh there&#8217;s other ways to do infinity there and also</p>



<p class="wp-block-paragraph">in C++ and Python.</p>



<p class="wp-block-paragraph">C++ and Python. So you&#8217;ll have to look up doubles on your programming language of choice and find</p>



<p class="wp-block-paragraph">out, is there a special value that represents infinity? The standards sometimes have special</p>



<p class="wp-block-paragraph">values for these kinds of things. We call them sentinels. And if you can&#8217;t figure out what is</p>



<p class="wp-block-paragraph">the sentinel for your particular language using doubles or integers or whatever, you could just</p>



<p class="wp-block-paragraph">make one up like for instance if I was stuck using integers and whatever system I was using</p>



<p class="wp-block-paragraph">and whatever system i was using there was no such thing as infinity for an integer a you know a</p>



<p class="wp-block-paragraph">assigned integer then for me i would just say all right what&#8217;s the most negative the the least</p>



<p class="wp-block-paragraph">possible value that i could ever represent in the negative number and i&#8217;ll call that infinity and</p>



<p class="wp-block-paragraph">then i&#8217;ll just tell myself don&#8217;t ever set that as the weight maybe in my code i&#8217;ll say if there&#8217;s</p>



<p class="wp-block-paragraph">no connection set it to that special sentinel value that special most negative value but</p>



<p class="wp-block-paragraph">But otherwise, if the user</p>



<p class="wp-block-paragraph">But otherwise, if the user of the code is trying to add an edge,</p>



<p class="wp-block-paragraph">my code will just check to see if I&#8217;m accidentally using that sentinel</p>



<p class="wp-block-paragraph">and then reject the edge if the user tries to do that.</p>



<p class="wp-block-paragraph">So then the user just loses one number that they can assign</p>



<p class="wp-block-paragraph">to the weight of an edge, but then you get the ability to do infinity.</p>



<p class="wp-block-paragraph">Another cool thing that you can do now with C++ is called,</p>



<p class="wp-block-paragraph">I think it&#8217;s called optionals.</p>



<p class="wp-block-paragraph">You can basically do, I&#8217;m not going to do a C++ tutorial right now,</p>



<p class="wp-block-paragraph">right now but you can look it up and you can say the template data type optional and then the token</p>



<p class="wp-block-paragraph">type is integer or or or double and then the optional allows the value to exist or not so we</p>



<p class="wp-block-paragraph">could say that there are optional integers or optional doubles all throughout the matrix and</p>



<p class="wp-block-paragraph">when an edge doesn&#8217;t exist the optional will be null or not on or you know null or whatever you</p>



<p class="wp-block-paragraph">You could also put pointers to integers or doubles.</p>



<p class="wp-block-paragraph">You could say every time we fill something</p>



<p class="wp-block-paragraph">you could say every time we fill something out in the matrix maybe this whole matrix is actually</p>



<p class="wp-block-paragraph">just a matrix of pointers of double pointers or integer pointers every time we fill out a number</p>



<p class="wp-block-paragraph">that particular pointer becomes like a real pointer to an actual you know integer or double</p>



<p class="wp-block-paragraph">and every time we take away an edge we&#8217;ll just set that pointer to null there&#8217;s a whole bunch</p>



<p class="wp-block-paragraph">of different ways you can do it but i just want you to know about a couple of them okay so before</p>



<p class="wp-block-paragraph">we continue any further, I want to, is that a perfect duplicate, BTW?</p>



<p class="wp-block-paragraph">duplicate but btw perfect why is it why is it like offset that&#8217;s so weird um i would like to</p>



<p class="wp-block-paragraph">show you a self-connect so how do we do self-connects in this type of matrix</p>



<p class="wp-block-paragraph">for starters we&#8217;re assuming that there are no self-connections by default in this particular</p>



<p class="wp-block-paragraph">matrix in this particular diagram so that&#8217;s why i put infinity all along the identity line we&#8217;ll</p>



<p class="wp-block-paragraph">talk about that in a second but um what if i wanted to suddenly</p>



<p class="wp-block-paragraph">what if i wanted to suddenly add an edge i&#8217;m going to say let&#8217;s do uh seven connects to itself</p>



<p class="wp-block-paragraph">and so now we&#8217;ll drop the assumption that all of the uh well we&#8217;ll keep the assumption we&#8217;re</p>



<p class="wp-block-paragraph">gonna have a different assumption in a different video we&#8217;ll keep the assumption that there&#8217;s no</p>



<p class="wp-block-paragraph">default self-connects but if i actually draw a self-connect now we could say that seven is</p>



<p class="wp-block-paragraph">connected to itself which means we can just go to row 7 column 7 and give it whatever</p>



<p class="wp-block-paragraph">and uh give it whatever weight we chose let&#8217;s do uh i don&#8217;t know let&#8217;s do like a four and then of</p>



<p class="wp-block-paragraph">course i have to actually draw four there for the weight and so that&#8217;s how you can just do self</p>



<p class="wp-block-paragraph">connects i&#8217;m going to duplicate this one more time and move it down um let&#8217;s see the other thing i</p>



<p class="wp-block-paragraph">wanted to say oh what happened there did you see that i lost like a whole row</p>



<p class="wp-block-paragraph">I gotta get rid of this</p>



<p class="wp-block-paragraph">how do I do it</p>



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



<p class="wp-block-paragraph">is that the rest of the no okay i&#8217;m not happy about this i&#8217;m not happy at all look at that</p>



<p class="wp-block-paragraph">oh because i duplicated i duplicated the slab before i finished it okay so i guess it&#8217;s okay</p>



<p class="wp-block-paragraph">so now we&#8217;re doing the fours okay um so i&#8217;m going to now</p>



<p class="wp-block-paragraph">lose my train of thought entirely um oh i wanted to show you that there&#8217;s a mirror along the</p>



<p class="wp-block-paragraph">Oh, I wanted to show you that there&#8217;s a mirror along the identity line.</p>



<p class="wp-block-paragraph">Okay, so weighted makes this a little bit more complicated,</p>



<p class="wp-block-paragraph">but undirected is what we did in the last video.</p>



<p class="wp-block-paragraph">That&#8217;s kind of easy and kind of fun.</p>



<p class="wp-block-paragraph">So watch your eyes real fast over the identity line here.</p>



<p class="wp-block-paragraph">And I just mean like this diagonal line.</p>



<p class="wp-block-paragraph">Is it going to highlight in green?</p>



<p class="wp-block-paragraph">How can I get yellow back?</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">So I&#8217;m going to highlight this diagonal, which is like the identity line,</p>



<p class="wp-block-paragraph">meaning 1 to 1 and 2 to 2 and 3 to 3 and so forth if you just kind of like stare at that line long</p>



<p class="wp-block-paragraph">enough you&#8217;ll realize that it&#8217;s a mirror because we have an undirected graph for example if you</p>



<p class="wp-block-paragraph">see oh gosh i&#8217;ll keep the highlighter that&#8217;s kind of fun you see 7 9 12 1 and 9 in the one column</p>



<p class="wp-block-paragraph">so like one is connected to 2 3 4 5 and 6 we could do the same thing by just flipping the rows in the</p>



<p class="wp-block-paragraph">columns. So instead of column one, we&#8217;ll do</p>



<p class="wp-block-paragraph">the columns so instead of column one we&#8217;ll do row one and then uh we&#8217;ll say that the the columns are</p>



<p class="wp-block-paragraph">two three four five and six so notice how here it&#8217;s kind of a little mirror um if we look at</p>



<p class="wp-block-paragraph">column three it&#8217;s got entries in nine and twelve and a whole bunch down here i guess well just</p>



<p class="wp-block-paragraph">these two down here then we do row three and do the same thing for the columns notice how this</p>



<p class="wp-block-paragraph">is also a mirror i&#8217;m drawing a mirror you can see right tilt your head it&#8217;s a mirror</p>



<p class="wp-block-paragraph">tilt your head it&#8217;s a mirror another joke that i like to make i&#8217;m so sorry if you just heard me say</p>



<p class="wp-block-paragraph">this it kind of looks like cheesy broccoli right and i hate cheesy broccoli because it tastes so</p>



<p class="wp-block-paragraph">good but it makes your broccoli into junk food again i&#8217;m not eating broccoli for fun okay i&#8217;m</p>



<p class="wp-block-paragraph">eating it to try and be healthy and i don&#8217;t want to turn it back into junk food and then i have</p>



<p class="wp-block-paragraph">to eat something else healthy i have it&#8217;s it&#8217;s because i have i have i have i have family members</p>



<p class="wp-block-paragraph">I&#8217;m not going to tell you who they are but I have family members</p>



<p class="wp-block-paragraph">family members who just push cheesy broccoli on everyone and then every time we go somewhere</p>



<p class="wp-block-paragraph">or we meet up or whatever it&#8217;s just like</p>



<p class="wp-block-paragraph">stop trying to convince me that cheesy broccoli is a cool thing i don&#8217;t agree</p>



<p class="wp-block-paragraph">give me plain broccoli all right anyway so we have an identity line there um we&#8217;ve done a</p>



<p class="wp-block-paragraph">two-dimensional matrix we&#8217;ve done uh undirected and weighted and we&#8217;re at about 20 minutes for</p>



<p class="wp-block-paragraph">this video already. So now</p>



<p class="wp-block-paragraph">you know how to make an undirected weighted graph.</p>



<p class="wp-block-paragraph">now you know how to make an undirected weighted graph and an undirected unweighted graph you watch</p>



<p class="wp-block-paragraph">the other video with an adjacency matrix maybe one final thing i want to say in this particular</p>



<p class="wp-block-paragraph">video before we&#8217;re finished this is lightning fast to add an edge or remove an edge remember</p>



<p class="wp-block-paragraph">i said before we could represent this uh this is really a one-dimensional array under the hood</p>



<p class="wp-block-paragraph">right but we can represent it to look like a two-dimensional array or an n-dimensional array</p>



<p class="wp-block-paragraph">that means this is just as fast to access a cell as it would be in a one-dimensional</p>



<p class="wp-block-paragraph">as it would be in a one-dimensional array which is constant time which is incredibly fast</p>



<p class="wp-block-paragraph">so if you want to add an edge or remove an edge you just have to change a cell i think we just</p>



<p class="wp-block-paragraph">added an edge going from seven to seven so we know how to add an edge we just go to the appropriate</p>



<p class="wp-block-paragraph">row and column but what if you want to remove an edge i guess i almost forgot that too let&#8217;s do</p>



<p class="wp-block-paragraph">remove the edge from the five to the six let&#8217;s kill this edge right what what do we actually do</p>



<p class="wp-block-paragraph">We go to row 5.</p>



<p class="wp-block-paragraph">we go to row 5 and column 6 and we change that 5 to an infinity to say that the edge no longer</p>



<p class="wp-block-paragraph">exists and then do the same thing for the column 5 column 5 uh row number 6</p>



<p class="wp-block-paragraph">uh is going to be infinity saying meaning there&#8217;s nothing there anymore so to add an edge we just</p>



<p class="wp-block-paragraph">went to a cell and modified a value to remove an edge we did the same thing that&#8217;s going to be</p>



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



<p class="wp-block-paragraph">that&#8217;s going to be incredibly fast it&#8217;s going to be constant time we&#8217;re going to talk all about</p>



<p class="wp-block-paragraph">like the pros and cons in terms of time complexity of adjacency matrices matrices in a future video</p>



<p class="wp-block-paragraph">but for now i think that&#8217;s pretty good thank you so much for watching this video i hope you learned</p>



<p class="wp-block-paragraph">a little bit of stuff and had a little bit of fun i&#8217;ll see you in the next video we&#8217;re going to do</p>



<p class="wp-block-paragraph">directed graphs unweighted and then weighted nice sorry</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">Really appreciate it.</p>



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



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



<p class="wp-block-paragraph">and follow this channel or these videos or whatever it is you do on the current social</p>



<p class="wp-block-paragraph">media website that you&#8217;re looking at right now it would really mean the world to me and it&#8217;ll</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 kind</p>



<p class="wp-block-paragraph">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</p>



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



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



<p class="wp-block-paragraph">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</p>



<p class="wp-block-paragraph">in order to go to the website which</p>



<p class="wp-block-paragraph">in order to go to the website which i think is also named somewhere at the bottom of this video</p>



<p class="wp-block-paragraph">and it&#8217;ll take you to my main website where you can just kind of like see all the videos i</p>



<p class="wp-block-paragraph">published and the services and tutorials and things that i offer and all that good stuff and</p>



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



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



<p class="wp-block-paragraph">me a comment whatever I also wake up for those in the</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 really mean the world to me. I would really appreciate it. So</p>



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-represent-undirected-weighted-graphs-using-an-adjacency-matrix/">How to Represent Undirected Weighted Graphs Using 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-undirected-weighted-graphs-using-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>Graph Basics in Data Structures: Nodes, Edges, and Representations</title>
		<link>https://www.NeuralLantern.com/graph-basics-in-data-structures-nodes-edges-and-representations/</link>
					<comments>https://www.NeuralLantern.com/graph-basics-in-data-structures-nodes-edges-and-representations/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Tue, 14 Jul 2026 22:43:47 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[adjacency list]]></category>
		<category><![CDATA[adjacency matrix]]></category>
		<category><![CDATA[C++ graph tutorial]]></category>
		<category><![CDATA[computer science basics]]></category>
		<category><![CDATA[data structures tutorial]]></category>
		<category><![CDATA[directed graph]]></category>
		<category><![CDATA[edge list]]></category>
		<category><![CDATA[graph data structure]]></category>
		<category><![CDATA[graph representations]]></category>
		<category><![CDATA[graph terminology]]></category>
		<category><![CDATA[graphs computer science]]></category>
		<category><![CDATA[nodes and edges]]></category>
		<category><![CDATA[undirected graph]]></category>
		<category><![CDATA[weighted graph]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=412</guid>

					<description><![CDATA[<p>Graphs are collections of nodes and edges, or vertices and edges. In this tutorial we implement them as template classes in C++ so you can use custom data types for nodes and edge weights. We cover undirected unweighted graphs, then add directions and weights to show path costs between cities or network nodes.</p>
<p>The post <a href="https://www.NeuralLantern.com/graph-basics-in-data-structures-nodes-edges-and-representations/">Graph Basics in Data Structures: Nodes, Edges, and Representations</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="Graph Basics in Data Structures: Nodes, Edges, and Representations" width="1380" height="776" src="https://www.youtube.com/embed/bz7VFYnTTQQ?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 graph basics: nodes, edges, neighbors, adjacency. Undirected vs directed, unweighted vs weighted. Representations including edge list, adjacency list, and matrix. Great intro for computer science students.</p>



<p class="wp-block-paragraph">00:00 Graph Basics Introduction<br>00:41 Nodes and Edges<br>01:20 Node and Edge Classes in C++<br>03:46 Simple Graph Examples<br>04:29 Adding Edges &#8211; Undirected Unweighted<br>05:26 Real World Uses of Graphs<br>07:08 Graph Terminology &#8211; Neighbors and Adjacency<br>08:32 Edges Incident on Nodes<br>09:20 Graph Representations &#8211; Edge List<br>09:59 Adjacency List<br>10:27 Adjacency Matrix<br>11:19 Directed Graphs<br>13:04 Weighted Graphs and Path Costs<br>15:24 Video Conclusion</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 graphs in the context of data structures and computer science.</p>



<p class="wp-block-paragraph">I just want to talk to you about some of the basics of graphs, some ways that we could</p>



<p class="wp-block-paragraph">implement them in the future, and some terminology. Okay, so for starters, we have a little</p>



<p class="wp-block-paragraph">For starters, we have a little blank graph sheet here.</p>



<p class="wp-block-paragraph">If you saw my previous video, you&#8217;ll know already that this is a valid graph.</p>



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



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



<p class="wp-block-paragraph">But let me draw some data in this graph.</p>



<p class="wp-block-paragraph">So graphs are collections of nodes and edges, or vertices and edges, or vertex and edges.</p>



<p class="wp-block-paragraph">The nodes themselves, they are custom classes sometimes, other times not.</p>



<p class="wp-block-paragraph">But you can imagine that they hold some sort of custom data.</p>



<p class="wp-block-paragraph">of custom data so i know i did this in my last video but i just want to emphasize that this graph</p>



<p class="wp-block-paragraph">class if we&#8217;re talking about c plus plus it should be a template class meaning we can specify a</p>



<p class="wp-block-paragraph">custom data type that the nodes will hold and also a custom data type that the edges will have as</p>



<p class="wp-block-paragraph">their weight you know typically when you see examples of this in the wild it&#8217;s just going to</p>



<p class="wp-block-paragraph">floats and strings exotic custom classes depending on your use case it may or may not be useful to do</p>



<p class="wp-block-paragraph">that but so we&#8217;ll have a data type for our nodes and i&#8217;ll call it like n type for like our node</p>



<p class="wp-block-paragraph">type and then we&#8217;ll do another one called e type for edge type i don&#8217;t know if that&#8217;s the best way</p>



<p class="wp-block-paragraph">to write those but i&#8217;m just going to do it anyway imagine that your glass your graph like we said</p>



<p class="wp-block-paragraph">So I&#8217;m going to put a node class here.</p>



<p class="wp-block-paragraph">You can imagine this as a vertex class.</p>



<p class="wp-block-paragraph">And I&#8217;m going to say that this node holds an n type data.</p>



<p class="wp-block-paragraph">And we&#8217;ll just call it data or node value or whatever you want.</p>



<p class="wp-block-paragraph">And then the same thing for the edges.</p>



<p class="wp-block-paragraph">We&#8217;ll say we have an edge class.</p>



<p class="wp-block-paragraph">I think in my last video, instead of doing a node class, I did a vertex class.</p>



<p class="wp-block-paragraph">It&#8217;s kind of all the same.</p>



<p class="wp-block-paragraph">We&#8217;ll say we have an e type and we&#8217;ll call it weight or value or data if you want.</p>



<p class="wp-block-paragraph">or value or data if you want but I think weight is a little bit closer to what we&#8217;re going to</p>



<p class="wp-block-paragraph">actually be doing with it and what do I mean by n type and e type like what are those data types</p>



<p class="wp-block-paragraph">there that just means these are placeholder tokens so when the user actually uses your graph by</p>



<p class="wp-block-paragraph">making an instance of your graph class like they create an actual graph off of your blueprint</p>



<p class="wp-block-paragraph">class here they might decide that they want integers inside of their nodes so that&#8217;s what</p>



<p class="wp-block-paragraph">They might decide that they want floats inside of your nodes, inside of their nodes, or some</p>



<p class="wp-block-paragraph">other data type.</p>



<p class="wp-block-paragraph">And so that means like at runtime or at, I think actually at compile time for C++, this</p>



<p class="wp-block-paragraph">end type would actually change to int if they chose to use integers on the inside.</p>



<p class="wp-block-paragraph">Same thing would happen for the edge, whatever they choose for the E-type token is just going</p>



<p class="wp-block-paragraph">to end up being used at compile time to replace that E-type.</p>



<p class="wp-block-paragraph">So I don&#8217;t know.</p>



<p class="wp-block-paragraph">Here&#8217;s an example.</p>



<p class="wp-block-paragraph">example, I got a fly in my room, it&#8217;s bothering me. Imagine the user says I want a graph.</p>



<p class="wp-block-paragraph">And I&#8217;ll call it G. And so they just have to kind of specify the two data types, maybe they want the</p>



<p class="wp-block-paragraph">graph to have integer values in the nodes. And maybe, you know, floating point double precision</p>



<p class="wp-block-paragraph">floating point values on the edges. In terms of weights, you know, you could do something like</p>



<p class="wp-block-paragraph">And we have edges and this graph right here is valid.</p>



<p class="wp-block-paragraph">It&#8217;s just one node kind of floating around by itself.</p>



<p class="wp-block-paragraph">This graph is also still valid, even though we have two nodes that are floating unconnected</p>



<p class="wp-block-paragraph">and also with the same value.</p>



<p class="wp-block-paragraph">I&#8217;m just going to change the value to be different.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll get rid of this extra thing here.</p>



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



<p class="wp-block-paragraph">We could have like a whole bunch of nodes all over the place and they don&#8217;t really have</p>



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



<p class="wp-block-paragraph">This is still a valid graph.</p>



<p class="wp-block-paragraph">change this to like a three, maybe change this to like an 11, change that to a six.</p>



<p class="wp-block-paragraph">What else can I change?</p>



<p class="wp-block-paragraph">How about like a 13?</p>



<p class="wp-block-paragraph">How about like a 17?</p>



<p class="wp-block-paragraph">Are there any duplicates?</p>



<p class="wp-block-paragraph">I don&#8217;t think I see any.</p>



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



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



<p class="wp-block-paragraph">The next thing that we could add to our graph is edges.</p>



<p class="wp-block-paragraph">So edges are, you know, little mini data structures that connect nodes.</p>



<p class="wp-block-paragraph">In this particular graph, I&#8217;m choosing to not have direction on my edges, which means this is a special type of graph.</p>



<p class="wp-block-paragraph">Or four that we talked about in the previous video.</p>



<p class="wp-block-paragraph">This is unweighted and also undirected, meaning there&#8217;s no weight assigned to the edges,</p>



<p class="wp-block-paragraph">which means that template weight value or the weight data type that we just talked about before.</p>



<p class="wp-block-paragraph">It&#8217;s kind of useless for this particular graph because I&#8217;m saying it&#8217;s unweighted.</p>



<p class="wp-block-paragraph">well uh all the edges if we wanted to travel through the graph along the edges we could just</p>



<p class="wp-block-paragraph">sort of go in any direction we felt like so this is unweighted and undirected</p>



<p class="wp-block-paragraph">um let&#8217;s see what else can i show you real fast okay so let&#8217;s talk about um well really fast let&#8217;s</p>



<p class="wp-block-paragraph">talk about the uses that you can have for a graph i think i talked about this in the last video</p>



<p class="wp-block-paragraph">but um you know what can we use graphs for some people think they&#8217;re databases they&#8217;re not really</p>



<p class="wp-block-paragraph">They&#8217;re not really databases.</p>



<p class="wp-block-paragraph">You could technically do that, but it would be pretty slow.</p>



<p class="wp-block-paragraph">There are much better data structures for databases.</p>



<p class="wp-block-paragraph">Really what graphs are mostly used for is to represent relationships between different</p>



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



<p class="wp-block-paragraph">I think I said this in the last video.</p>



<p class="wp-block-paragraph">Imagine if every single node that you see here is a city and the edges represent flight</p>



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



<p class="wp-block-paragraph">So we could fly between city seven and 11.</p>



<p class="wp-block-paragraph">Oh, that&#8217;s funny.</p>



<p class="wp-block-paragraph">I&#8217;m hungry for candy bar now.</p>



<p class="wp-block-paragraph">between city seven and 11 and back and you know back in the other direction if we want to but we</p>



<p class="wp-block-paragraph">can&#8217;t actually fly from city seven to six because there&#8217;s no edge there so we could represent</p>



<p class="wp-block-paragraph">computer networks we could represent road maps airports dependency graphs game maps you could</p>



<p class="wp-block-paragraph">say like every node is somewhere your character could stand and an edge represents where your</p>



<p class="wp-block-paragraph">or represents a connection to another node so that you know your character could move there</p>



<p class="wp-block-paragraph">there&#8217;s all sorts of different things that you could represent with the graph but</p>



<p class="wp-block-paragraph">it&#8217;s not necessarily a fast database it&#8217;s more of like a relationship</p>



<p class="wp-block-paragraph">not to be confused with relational database which is supposed to be lightning fast</p>



<p class="wp-block-paragraph">like if i wanted to search for the number 17 in this graph it&#8217;s not going to be log time like a</p>



<p class="wp-block-paragraph">proper database should be it&#8217;s not going to be constant time like a hash table based database</p>



<p class="wp-block-paragraph">or like a no sql or whatever um so we have undirected and unweighted uh we talked about</p>



<p class="wp-block-paragraph">like different uses let&#8217;s talk a little bit about terminology okay for starters notice how there&#8217;s</p>



<p class="wp-block-paragraph">no hierarchy in this graph in other videos we&#8217;re going to talk about binary search trees and we</p>



<p class="wp-block-paragraph">have to have like a hierarchy there&#8217;s no parent there&#8217;s no child in these graphs there&#8217;s no uh</p>



<p class="wp-block-paragraph">you know like grandchildren ancestors descendants because there&#8217;s not really like a hierarchy it&#8217;s</p>



<p class="wp-block-paragraph">It&#8217;s just things are connected to each other or they&#8217;re not.</p>



<p class="wp-block-paragraph">But we can have something called neighbors.</p>



<p class="wp-block-paragraph">For example, if you can reach a node in one hop, then you might be able to call that a neighbor.</p>



<p class="wp-block-paragraph">So 6 and 17, those are neighbors.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll just type neighbors right here.</p>



<p class="wp-block-paragraph">Oops, neighbors.</p>



<p class="wp-block-paragraph">Because we can reach them in one hop.</p>



<p class="wp-block-paragraph">Later on, or especially if I don&#8217;t remember to mention this,</p>



<p class="wp-block-paragraph">to our graph, then something is only considered a neighbor if you can reach it while respecting</p>



<p class="wp-block-paragraph">the direction of the graph. So we have like neighbors as 6 and 17. So that means 6 and 11</p>



<p class="wp-block-paragraph">are also neighbors. 6 and 12, not neighbors because they can&#8217;t reach each other in one hop.</p>



<p class="wp-block-paragraph">Let&#8217;s see. Adjacency is basically the same thing. I can&#8217;t remember. I think we use adjacency more</p>



<p class="wp-block-paragraph">often in directed graphs, but we could say that 6 and 17 are adjacent to each other,</p>



<p class="wp-block-paragraph">adjacent to each other, which is in this context, sort of a synonym for neighbors.</p>



<p class="wp-block-paragraph">Okay. Something else that I want to talk about in terms of edges,</p>



<p class="wp-block-paragraph">edges are considered to be incident upon nodes or vertices. So like, you know,</p>



<p class="wp-block-paragraph">if I have an arrow that just kind of points to these two things, I could say,</p>



<p class="wp-block-paragraph">you know, edge is incident upon three and 12. It&#8217;s just, it just means,</p>



<p class="wp-block-paragraph">and 12th. Okay, what else should we talk about? We should talk about connected versus, no,</p>



<p class="wp-block-paragraph">that&#8217;s another video. Okay, I&#8217;m going to do another video for connected versus not connected graphs.</p>



<p class="wp-block-paragraph">Maybe I should mention that there are three ways that we can represent a graph, and then maybe I&#8217;ll</p>



<p class="wp-block-paragraph">upgrade to a directed graph in a second. If you want to know about the four different types of</p>



<p class="wp-block-paragraph">graphs, see my previous video. But for now, I&#8217;m going to say there are three ways we could</p>



<p class="wp-block-paragraph">to represent these graphs. The first way, and I&#8217;m talking about how can you represent these</p>



<p class="wp-block-paragraph">graphs inside of the machine? Like how can your computer store and process this graph and maybe</p>



<p class="wp-block-paragraph">run algorithms on it? So the first way that we could represent, at least that I&#8217;m going to talk</p>



<p class="wp-block-paragraph">about, is an edge list. Edge lists are super simple. I&#8217;m going to do a dedicated video just</p>



<p class="wp-block-paragraph">for edge lists in the future. They&#8217;re not very fast, but they&#8217;re very easy to implement. So</p>



<p class="wp-block-paragraph">So honestly, if you&#8217;re just starting with this stuff, I would recommend just implementing an edge list first</p>



<p class="wp-block-paragraph">The next thing that you can do to represent a graph in the machine is make an adjacency list</p>



<p class="wp-block-paragraph">Adjacency lists are just a little bit more complicated</p>



<p class="wp-block-paragraph">But they&#8217;re typically faster than edge lists. Not always not in all cases and</p>



<p class="wp-block-paragraph">In terms of time complexity, you might not feel like you notice much of a difference</p>



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



<p class="wp-block-paragraph">the option of skipping a lot of examinations when you don&#8217;t need to examine something,</p>



<p class="wp-block-paragraph">you kind of skip it.</p>



<p class="wp-block-paragraph">We&#8217;ll talk more about that in the future.</p>



<p class="wp-block-paragraph">But we have an edge list and adjacency list of representation.</p>



<p class="wp-block-paragraph">And then we have an adjacency matrix.</p>



<p class="wp-block-paragraph">I wish I had spell check on this.</p>



<p class="wp-block-paragraph">Otherwise, this is going to be humiliating.</p>



<p class="wp-block-paragraph">An adjacency matrix is sometimes a lightning fast representation of a graph.</p>



<p class="wp-block-paragraph">At first, you might think, wow, that&#8217;s amazing.</p>



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



<p class="wp-block-paragraph">always going to use that. But all of these representations have strengths and weaknesses.</p>



<p class="wp-block-paragraph">None of them are better than the others in every single circumstance. So, you know, computer science</p>



<p class="wp-block-paragraph">and data structures, it&#8217;s all about weighing the pros and cons and picking the right representation</p>



<p class="wp-block-paragraph">or algorithm or whatever that&#8217;s best for you and the code and the data that you&#8217;re actually going</p>



<p class="wp-block-paragraph">to run. So three different ways that we can represent a graph in the future. And let&#8217;s see,</p>



<p class="wp-block-paragraph">already on this. We talked about the basic ways to use them sort of. We talked about neighbors</p>



<p class="wp-block-paragraph">and adjacency. Oh, I got to upgrade to a directed graph real fast just to kind of show you the</p>



<p class="wp-block-paragraph">difference here. Okay, so I&#8217;m going to duplicate this and I&#8217;m just going to start adding direction</p>



<p class="wp-block-paragraph">to all my edges. In my previous video, we talked about this. If you add direction to even one edge,</p>



<p class="wp-block-paragraph">then you have to add direction to all the other edges. Otherwise, you will have an invalid graph.</p>



<p class="wp-block-paragraph">graph so notice how I add a direction to one edge I now have an invalid graph so</p>



<p class="wp-block-paragraph">I&#8217;m just gonna do this change every single edge so that every single edge</p>



<p class="wp-block-paragraph">has a direction you know the basic thing we kind of talked about this in my</p>



<p class="wp-block-paragraph">previous video is that when traveling through the graph you&#8217;re supposed to</p>



<p class="wp-block-paragraph">only be able to travel in the direction of an edge which means if you look at</p>



<p class="wp-block-paragraph">this thing right now you&#8217;re supposed to be able to go from 11 to 7 but you&#8217;re</p>



<p class="wp-block-paragraph">be able to go from 7 to 11 because that violates the direction of the edge. When we add direction</p>



<p class="wp-block-paragraph">we&#8217;re sort of like reducing you know the flexibility of the graph so you can imagine</p>



<p class="wp-block-paragraph">that the previous version that was undirected it was sort of like every single edge here</p>



<p class="wp-block-paragraph">was really two edges pointing in opposite directions if that makes sense. So if you</p>



<p class="wp-block-paragraph">wanted to make sure that you could go back and forth between edge sorry between node 7 and 11</p>



<p class="wp-block-paragraph">the opposite direction you can also do things called parallel edges which is just to say</p>



<p class="wp-block-paragraph">i&#8217;m going to add multiple edges that that go in the same direction from the same start node to</p>



<p class="wp-block-paragraph">the same end node but i&#8217;m not going to do that here that makes it more complicated for some</p>



<p class="wp-block-paragraph">representations but we can just sort of add a whole bunch of edges i&#8217;m just going to say one</p>



<p class="wp-block-paragraph">going back and forth there and so forth remember in my previous video we talked about weighted edges</p>



<p class="wp-block-paragraph">about weighted edges which means we could add a cost to traveling along an edge so you could say</p>



<p class="wp-block-paragraph">something like uh i don&#8217;t know going from 7 to 12 let&#8217;s add another edge here if there was a cost</p>



<p class="wp-block-paragraph">on all these weights maybe i should just add that for fun we could maybe calculate which path would</p>



<p class="wp-block-paragraph">be better so let&#8217;s say we got ones over here and we got fives over here um and maybe like a like</p>



<p class="wp-block-paragraph">and I&#8217;m going to do like an eight.</p>



<p class="wp-block-paragraph">By the way, these sixes don&#8217;t have to be the same.</p>



<p class="wp-block-paragraph">You could just be two different numbers.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do like a three here.</p>



<p class="wp-block-paragraph">And let me just see, have I added a weight to every single edge?</p>



<p class="wp-block-paragraph">So I know I did this in the previous video,</p>



<p class="wp-block-paragraph">but I want to do it again real fast.</p>



<p class="wp-block-paragraph">If we chose to take a path from seven to 12,</p>



<p class="wp-block-paragraph">and we said seven to 11, and then 11 to 12,</p>



<p class="wp-block-paragraph">that&#8217;s a very specific path, which is,</p>



<p class="wp-block-paragraph">it&#8217;s going to cost us five to go along that first,</p>



<p class="wp-block-paragraph">as you have to go along that first edge and then the second edge is going to cost us six</p>



<p class="wp-block-paragraph">and we&#8217;re only traveling along two edges so the total cost of that path is 11.</p>



<p class="wp-block-paragraph">On the other hand let me actually make this look pink.</p>



<p class="wp-block-paragraph">On the other hand if we&#8217;re taking a different path we might come up with a different cost</p>



<p class="wp-block-paragraph">depending on the graph. So let&#8217;s say we start at 11 start at 7 maybe we want to go down to 3</p>



<p class="wp-block-paragraph">to three and then from three we&#8217;ll go to 12 well that might be a different cost so i&#8217;m going to say</p>



<p class="wp-block-paragraph">the cost of this particular path is traveling it&#8217;s going to cost us one to go down that first edge</p>



<p class="wp-block-paragraph">and then a two to go down that second edge which means the total cost of getting to 12 is only 3</p>



<p class="wp-block-paragraph">if we take that orange path versus 11 if we take that pink path i hope you&#8217;re starting to visualize</p>



<p class="wp-block-paragraph">how graphs might be useful to visualize costs if this is a network map we just figured out that</p>



<p class="wp-block-paragraph">network map we just figured out that one route through the network might be faster or less</p>



<p class="wp-block-paragraph">costly than the other or if this is like an airport map maybe you do want to take you know</p>



<p class="wp-block-paragraph">that layover that goes down south instead of that layover that goes east in terms of</p>



<p class="wp-block-paragraph">i don&#8217;t know frequent fire miles that it costs you or money it costs you or jet fuel that it</p>



<p class="wp-block-paragraph">That&#8217;s all I wanted to talk about in this video.</p>



<p class="wp-block-paragraph">I&#8217;m going to make one more video today.</p>



<p class="wp-block-paragraph">Well, it&#8217;ll be released.</p>



<p class="wp-block-paragraph">I don&#8217;t know when, but like in my present moment.</p>



<p class="wp-block-paragraph">I&#8217;m going to make another video right after this</p>



<p class="wp-block-paragraph">where we just talk about connected graphs versus not connected graphs.</p>



<p class="wp-block-paragraph">Thank you so much for watching this video.</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">See you in the future.</p>



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



<p class="wp-block-paragraph">In the future.</p>



<p class="wp-block-paragraph">in the future.</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 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 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 troll me if you want to just wake me up in the middle of the night.</p>



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



<p class="wp-block-paragraph">I promise that&#8217;s what will happen.</p>



<p class="wp-block-paragraph">happen also if you look at the middle of the screen right now you should see a QR code which</p>



<p class="wp-block-paragraph">you can scan in order to go to the website which I think is also named somewhere at the bottom of</p>



<p class="wp-block-paragraph">this video and 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">if you have a suggestion for clarifications or errata or just future videos that you want to</p>



<p class="wp-block-paragraph">videos that you want to see please leave a comment or if you just want to say hey what&#8217;s up what&#8217;s</p>



<p class="wp-block-paragraph">going on you know just send me a comment whatever i also wake up for those in the middle of the</p>



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



<p class="wp-block-paragraph">would really appreciate it so again thank you so much for watching this video and um enjoy the cool</p>



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/graph-basics-in-data-structures-nodes-edges-and-representations/">Graph Basics in Data Structures: Nodes, Edges, and Representations</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/graph-basics-in-data-structures-nodes-edges-and-representations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
