<?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>constant time access Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/constant-time-access/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/constant-time-access/</link>
	<description></description>
	<lastBuildDate>Mon, 19 Oct 2026 05:40:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>constant time access Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/constant-time-access/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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>
	</channel>
</rss>
