<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: singhimat99</title>
    <description>The latest articles on DEV Community by singhimat99 (@singhimat99).</description>
    <link>https://dev.to/singhimat99</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F996790%2Fee17aac8-3ad3-4ec5-823d-6baf3f8c80df.jpg</url>
      <title>DEV Community: singhimat99</title>
      <link>https://dev.to/singhimat99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/singhimat99"/>
    <language>en</language>
    <item>
      <title>Introduction to Graphs</title>
      <dc:creator>singhimat99</dc:creator>
      <pubDate>Fri, 03 Feb 2023 22:13:46 +0000</pubDate>
      <link>https://dev.to/singhimat99/introduction-to-graphs-15ga</link>
      <guid>https://dev.to/singhimat99/introduction-to-graphs-15ga</guid>
      <description>&lt;p&gt;Welcome to a new post on 'In My Own Words', where we take on programming concepts and make them simple for the every-day learner. With easy-to-follow examples and explanations in plain language, join me on my journey to understand the world of programming. Let's get started!&lt;/p&gt;

&lt;p&gt;Today we will be talking about Graphs! A common data structure used to solve a ton of different problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now what is a graph?
&lt;/h2&gt;

&lt;p&gt;A graph is a data structure (an organized way to store information) that has vertices and edges. Now, those are some complicated words. Instead, let's refer to "nodes" as "dots" and "edges" as "connections" or "lines". &lt;/p&gt;

&lt;p&gt;A simple way to grasp the concept of a graph is to think of the childhood game "Connect the Dots". Just as in the game, a graph consists of points or nodes connected by lines or edges, creating a network of relationships between the nodes. This network can then be used to solve a variety of real-world problems and serves as the foundation of many crucial algorithms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3q8Vigej--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/la1gpuzdm7rqt8wg2lki.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3q8Vigej--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/la1gpuzdm7rqt8wg2lki.jpeg" alt="image of connect the dots" width="880" height="1322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A graph is a visual representation of information and the relationships between it. For instance, you and your followers on Instagram can be represented as points, and the fact that they follow you is represented as a connection between those dots. The connection represents the relationship or interaction, in this case, following on Instagram.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are graphs useful for?
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered how Google Maps shows us the location of everything and provides us with routes that follow actual roads instead of a straight line path? They use graphs! Landmarks and intersections are represented as dots, and roads, streets, and highways are represented as connections. What we see as the map is just a satellite image of the Earth. The actual mapping happens beneath the image. &lt;/p&gt;

&lt;p&gt;When you ask the Google Maps app for directions from your current location to a destination, it first finds the two locations in the graph data structure where they are stored. Then, it runs an algorithm to find the shortest path between the two dots. In simple terms, Google Maps uses graphs to understand how different places are connected and then creates a path by connecting those dots in the most efficient way.&lt;/p&gt;

&lt;p&gt;Graphs are a powerful data structure that has many practical applications in the real world. In the coming days, we will delve into some of the numerous algorithms related to graphs. I hope you found this informative and now have a clearer understanding of graph data structures. Thank you for reading!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Creating a Word Search Puzzle for my Portfolio (part 2)</title>
      <dc:creator>singhimat99</dc:creator>
      <pubDate>Fri, 06 Jan 2023 02:10:39 +0000</pubDate>
      <link>https://dev.to/singhimat99/creating-a-word-search-puzzle-for-my-portfolio-part-2-12bl</link>
      <guid>https://dev.to/singhimat99/creating-a-word-search-puzzle-for-my-portfolio-part-2-12bl</guid>
      <description>&lt;p&gt;In case you haven't already, please check out the first part of this series: &lt;a href="https://dev.to/singhimat99/how-i-created-a-word-search-game-for-my-portfolio-react-part-1-138n"&gt;Part 1&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  So, where were we...
&lt;/h3&gt;

&lt;p&gt;We had just finished setting up the grid for our game, which serves as the foundation for the word search. The grid acts as the backdrop for the letters that players will choose from to form a sequence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wgBluM7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cb134ue0h5xtxw5b9vic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wgBluM7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cb134ue0h5xtxw5b9vic.png" alt="image of grid" width="293" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can focus on replacing all these 0's with letters.&lt;/p&gt;

&lt;p&gt;For this we are going to need an algorithm that does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;arranges all of the provided words on a grid of the same size in random order&lt;/li&gt;
&lt;li&gt;fills all remaining cells with random letters&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lets tackle this problem
&lt;/h2&gt;

&lt;p&gt;We know the words can only be placed either horizontally, vertically, diagonally up, or diagonally down. (refer to part 1, if you are lost),&lt;/p&gt;

&lt;p&gt;So we need a grid and we need to place a list of words on that grid in one of 4 possible orientations. &lt;/p&gt;

&lt;p&gt;To begin, we can define a function that accepts the size of the grid and a list of words as input. We can use the size to create a 2D matrix, and then iterate over the list of words using a loop&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2xEsZ3ph--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2a48jkqfaqw24vaj6ri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2xEsZ3ph--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2a48jkqfaqw24vaj6ri.png" alt="Image description" width="880" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the loop, we need to randomly select a direction for the current word. To do this, we can create an array containing the four possible orientations: horizontal, vertical, diagonally up, diagonally down.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OEG7yGea--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcm2avishf5ocbfsl8ik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OEG7yGea--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcm2avishf5ocbfsl8ik.png" alt="Image description" width="880" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Hold on just a second
&lt;/h3&gt;

&lt;p&gt;I just thought of a problem that we would likely face while solving this.&lt;/p&gt;

&lt;p&gt;If we randomly place a word on the grid and select an orientation for it, there is a possibility that the word will be positioned outside the boundaries of the grid. &lt;/p&gt;

&lt;p&gt;For example, if I select the word "javascript" and give it a horizontal orientation, and then try to place it starting at the rightmost edge of the matrix, there will likely be an error because we will be attempting to place a letter outside the boundaries of the matrix.&lt;/p&gt;

&lt;p&gt;To prevent this issue, we can add a do-while loop inside our for loop. This loop will continue running until the word is placed within the boundaries of the matrix. To keep track of this, we can initialize a variable "placed" that is set to &lt;code&gt;False&lt;/code&gt; and will be set to &lt;code&gt;True&lt;/code&gt; if the word is successfully placed. This will allow us to break out of the loop when the word has been properly positioned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lJbLTV_G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1xyuxuuvm95czvwvzm8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lJbLTV_G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1xyuxuuvm95czvwvzm8y.png" alt="Image description" width="622" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, as we go through the process of placing the word, if we encounter a location that is outside the boundaries of the matrix, we can use the &lt;code&gt;continue&lt;/code&gt; keyword to restart the while loop and select a new orientation and position for that word.&lt;/p&gt;

&lt;h3&gt;
  
  
  Okay, back to the algorithm
&lt;/h3&gt;

&lt;p&gt;So first let’s assign a random starting position for the word with the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qiEvidYT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gria6ctrqrfhwhaogap2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qiEvidYT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gria6ctrqrfhwhaogap2.png" alt="initial starting position" width="880" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we can select a random orientation from our array of orientations. We will also initialize our &lt;code&gt;rise&lt;/code&gt; and &lt;code&gt;run&lt;/code&gt; variables, which we will use in various operations later on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZiEuRYR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwn13ewl2llnqa6rn968.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZiEuRYR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwn13ewl2llnqa6rn968.png" alt="orientations rise and run" width="880" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we just need to determine the slope (rise and run) based on the random orientation that we got.&lt;/p&gt;

&lt;p&gt;We can use a switch case statement and assign the appropriate rise and run values. (Notice how these values can be derived from our slope validation function in part 1).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DOsVTRiz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7bzs57kazo92es60uu4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DOsVTRiz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7bzs57kazo92es60uu4.png" alt="switch case statement" width="508" height="840"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to determine if the end of our word will be placed outside the grid. To do this, we can calculate the position of the last letter in the word. We can do this by adding the &lt;code&gt;row&lt;/code&gt; to the product of the length of the word and the &lt;code&gt;run&lt;/code&gt;, and doing the same with the &lt;code&gt;column&lt;/code&gt; and &lt;code&gt;rise&lt;/code&gt; variables.&lt;/p&gt;

&lt;p&gt;After this calculation, we will have the row and column values for the last letter of the word. If either of these numbers is larger than the length of the matrix or less than 0, we need to try a different orientation (restart the while loop) to make sure that the word fits within the grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GD-z6Xn6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fjmypwep5dhen8glhugw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GD-z6Xn6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fjmypwep5dhen8glhugw.png" alt="find end of word" width="880" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we pass this check, it means that the beginning and end of the word are both within the boundaries of the matrix. &lt;/p&gt;

&lt;p&gt;Now, we need to check if there are any other words in the way. We can't overlap words unless they share one letter.&lt;/p&gt;

&lt;p&gt;We need to set up a loop to iterate over each letter of the current word to check if the current position is already taken. We will also initialize a variable called &lt;code&gt;failed&lt;/code&gt; outside the loop. This variable will be used later in the while loop.&lt;/p&gt;

&lt;p&gt;For each letter in the word, we can calculate the position on the matrix where this letter would be placed. We can do this by multiplying the index of the letter by the &lt;code&gt;run&lt;/code&gt; or &lt;code&gt;rise&lt;/code&gt; and adding it to the initial &lt;code&gt;row&lt;/code&gt; or &lt;code&gt;column&lt;/code&gt;, respectively.&lt;/p&gt;

&lt;p&gt;Here's how it works: on the first iteration, the index is 0, so after multiplying it to the &lt;code&gt;run&lt;/code&gt; or &lt;code&gt;rise&lt;/code&gt; we end up with 0 which we add to the &lt;code&gt;row&lt;/code&gt; and &lt;code&gt;column&lt;/code&gt; values, which means we check the starting position. &lt;/p&gt;

&lt;p&gt;On the next iteration, the index is 1. This time we are multiplying the &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;rise&lt;/code&gt; by 1 which means this time we will be adding the &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;rise&lt;/code&gt; values tot he &lt;code&gt;row&lt;/code&gt; and &lt;code&gt;column&lt;/code&gt; values respectively. By doing these calculations we will be checking where the current letter of the word would be placed based on the orientation we selected at the beginning of the while loop.&lt;/p&gt;

&lt;p&gt;After that, we can check if the position in the matrix is empty or if it is occupied by the same letter as the current letter of the word.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ilRcLaBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q20bs0whv0mfr8uv00j9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ilRcLaBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q20bs0whv0mfr8uv00j9.png" alt="picture of loop" width="880" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If at any point we find that this condition is false we break out of the loop as set failed to true. So that we can restart the whole loop based on this condition:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PEAIjVW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9j4grqnvq7hm78ms7si.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PEAIjVW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9j4grqnvq7hm78ms7si.png" alt="if failed, continue" width="464" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, if our word passes all the previous checks we know two things that are crucial before attempting to place the word on the matrix. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the word is within the matrix&lt;/li&gt;
&lt;li&gt;we can place the word without overriding a previous word&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we can finally place the word!!&lt;/p&gt;

&lt;p&gt;We have already done half of this in our last check so it is simple from here. We just calculate the new row and column using a similar calculation and then we place the current letter at that position on the matrix. Once we have finished this we can finally set &lt;code&gt;placed&lt;/code&gt; to &lt;code&gt;True&lt;/code&gt; and break out of the loop!!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mmE0B3Tn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbvdv17qv7g43avwwtx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mmE0B3Tn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbvdv17qv7g43avwwtx3.png" alt="Image description" width="724" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  We have finally finished the hard part
&lt;/h3&gt;

&lt;p&gt;Now all that we have left to do is replace all of the empty spaces with a random word. This very simple we just iterate over the matrix with a nested for loop and if the current index is empty. We assign it a random letter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_PHD5jkL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mh0h2ruuf7dytppnmrzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_PHD5jkL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mh0h2ruuf7dytppnmrzg.png" alt="Image description" width="880" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have a puzzle that is now ready to be solved all we have to do now is check if the player is picking the right word. &lt;/p&gt;

&lt;h4&gt;
  
  
  To be continued…
&lt;/h4&gt;

</description>
    </item>
    <item>
      <title>My Strategy for Learning Data Structures</title>
      <dc:creator>singhimat99</dc:creator>
      <pubDate>Thu, 05 Jan 2023 04:35:27 +0000</pubDate>
      <link>https://dev.to/singhimat99/my-strategy-for-learning-data-structures-11lb</link>
      <guid>https://dev.to/singhimat99/my-strategy-for-learning-data-structures-11lb</guid>
      <description>&lt;h2&gt;
  
  
  Like all good stories in the past few weeks mine starts with OpenAI's Chat GPT.
&lt;/h2&gt;

&lt;p&gt;I have just started my journey in learning Data Structures so naturally I ask chat GPT the best strategy for learning and one of the methods was to implement the given data structure from scratch. Now that sounds daunting...&lt;/p&gt;

&lt;p&gt;However, this is a great idea! I am definitely going to add it into my learning strategy. So heres what I have so far.&lt;/p&gt;

&lt;p&gt;First I have to pick a data structures to study then I will follow these steps until I feel confident in my ability to understand and use the data structure:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Research Research Research.
&lt;/h3&gt;

&lt;p&gt;I will spend some time first gathering information on the data structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotfu9p7hakt84932cpgw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotfu9p7hakt84932cpgw.png" alt="student researching in the library" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My research will be focused on the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;basics of how to read and write from the structure&lt;/li&gt;
&lt;li&gt;how it came about&lt;/li&gt;
&lt;li&gt;which problems it solves&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Next I will try to implement it on my own in Java.
&lt;/h3&gt;

&lt;p&gt;Yes, I said Java, a language I do not even know yet. Why would I do this? There is a couple reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The main reason is that in order to find all of the syntax necessary to create this structure I will need to fully understand how it works.&lt;/li&gt;
&lt;li&gt;I want to learn Java, I remember asking ChatGPT a while ago the best way to learn Java and one of the answers it gave me was to implement data structures in the language.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This step is only possible if I have a deep understanding of the data structure. I will develop this by first learning all of the necessary lower level concepts that go into building the structure like how it is stored in memory and what other data structures are used to build it. These are the steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn the low level concepts&lt;/li&gt;
&lt;li&gt;Write the data structure in pseudocode&lt;/li&gt;
&lt;li&gt;convert the pseudocode into Java (and possibly Javascript just for fun)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is going to be the hardest step and will likely take a couple of days but I believe it's necessary for the learning process.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdhampbit5b9964h9v6qx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdhampbit5b9964h9v6qx.png" alt="student having a hard time" width="800" height="400"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Finally I will solve Leetcode easy questions with my own implementation of the data structure.
&lt;/h3&gt;

&lt;p&gt;I believe this step is crucial because it will help me learn how to actually use the data structure to solve a problem. This will connect all of the dots and align all of the stars for me to understand the data structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0juiz4g5n5r2vuxak4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0juiz4g5n5r2vuxak4j.png" alt="bright idea by a student" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
In case you haven't noticed all of the pictures in this post have been generated by AI.&lt;/p&gt;

&lt;p&gt;Once I have done all of these steps I believe I can start tackling harder Leetcode questions using the data structure (and maybe even my implementation of it ¯_(ツ)_/¯).&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>How I created a Word Search Game for my Portfolio (React) Part 1</title>
      <dc:creator>singhimat99</dc:creator>
      <pubDate>Wed, 28 Dec 2022 23:58:01 +0000</pubDate>
      <link>https://dev.to/singhimat99/how-i-created-a-word-search-game-for-my-portfolio-react-part-1-138n</link>
      <guid>https://dev.to/singhimat99/how-i-created-a-word-search-game-for-my-portfolio-react-part-1-138n</guid>
      <description>&lt;p&gt;So what does it take to build word-search?&lt;/p&gt;

&lt;h2&gt;
  
  
  Lets Break this down..
&lt;/h2&gt;

&lt;p&gt;We first need to understand the game itself.&lt;/p&gt;

&lt;p&gt;Word search is a very common game often found in newspapers. Its quite simple the player just has to find the listed words inside of a grid if seemingly random letters. &lt;/p&gt;

&lt;p&gt;So we know we need a grid with randomly placed letters and we need a way for the player to select possible words on the grid.&lt;/p&gt;

&lt;h3&gt;
  
  
  First lets handle selecting words
&lt;/h3&gt;

&lt;p&gt;What we know: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We know we are dealing with a grid so we can think in terms of x and y coordinates (or rows and columns)&lt;/li&gt;
&lt;li&gt;We know that there are only four ways to select a word: horizontal, vertical, diagonally up, and diagonally down.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Lets start with a simple matrix
&lt;/h4&gt;

&lt;p&gt;Start with just a simple react component and then create 10x10 2D array filled with zeros. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2i6nqSlI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmkgc3ff2qycbz1xvy6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2i6nqSlI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmkgc3ff2qycbz1xvy6f.png" alt="Code snap of 2d array" width="880" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then use the javascript map method on the array state to render out the array as buttons and add some styles (I used tailwind) to get to something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7LHA54qP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s93ykdjoe7d16bnb0kwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7LHA54qP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s93ykdjoe7d16bnb0kwa.png" alt="image f=of grid of zeros" width="293" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to keep track of clicks on these buttons. We know that we're going to need a click event listener to do that so I added an 'onClick' event to each button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eU2w9Mbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ukffabbdyj8undiuxva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eU2w9Mbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ukffabbdyj8undiuxva.png" alt="code added on-click event to a button" width="580" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we're gunna need some state to keep track of clicks and we need to decide what happens we we do click a button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e9Q8T1Vp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqnpursrm58wcp176gnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e9Q8T1Vp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqnpursrm58wcp176gnl.png" alt="code initializing some state" width="738" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we click a random button on this grid we should first increment clicks and then we can change the 0 to a 1 wherever we clicked as a way of acknowledging the click. In order to keep track of the location we will use the indexes of i and j for rows and columns respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qzqxxvBC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cs6dd5n19bs1i57g3laf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qzqxxvBC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cs6dd5n19bs1i57g3laf.png" alt="code incrementing clicks" width="796" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far we are keeping track of clicks we can see if the user has clicked more than once. For now if the user has clicked more than twice let's just disable all buttons. To do this we are gunna need another state variable and set a disabled prop on each button. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U-DCSmV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvtyxdt7i7li7o2r4vel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U-DCSmV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvtyxdt7i7li7o2r4vel.png" alt="code disabling buttons" width="508" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: When we change state in react it is asynchronous. This means we have to check if the value of clicks is 1 instead of 2 because the clicks will only be incremented after the handleClick function has already run.&lt;/p&gt;

&lt;p&gt;Let's also set up another button to reset the board(returning to our initial table of 0's and clicks to 0). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lzrr_vfA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45o9wqxt8j0qhxc2zd60.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lzrr_vfA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45o9wqxt8j0qhxc2zd60.png" alt="code to reset table" width="880" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So right now the user can change 2 of the 0's on the board at a time before they have to reset. &lt;/p&gt;

&lt;p&gt;This is useful because in word search you are usually trying to find the beginning or end of a word which is either in a straight line or diagonal. &lt;/p&gt;

&lt;p&gt;Now all we have to do is check if the 2 places the user has selected are directly horizontal, vertical, or diagonal from each other. &lt;/p&gt;

&lt;p&gt;So let's create a helper function to do so. In this function we are essentially checking whether the slope between the two cells is valid (hence the name isValidSlope).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MaH1L0jZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fs4qxxb3kd23i7rjzuiv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MaH1L0jZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fs4qxxb3kd23i7rjzuiv.png" alt="code of initial helper function" width="880" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Oops...
&lt;/h2&gt;

&lt;p&gt;At this point I realized that in order to do this I had to somehow keep track of the 2 cells that had been selected. So lets handle this first...&lt;/p&gt;

&lt;p&gt;We are definitely going to need some state to handle this so let's create initialize this to an empty array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4FrkW75E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3x2m7ghtdj8afdjihm56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4FrkW75E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3x2m7ghtdj8afdjihm56.png" alt="code initializing some state" width="880" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we are using a 2D array we should have access to the indexes in the map functions. We can use the indexes that we used earlier to select a cell, which are already passed into the handleClick function.&lt;/p&gt;

&lt;p&gt;So if the user is clicking for the first time we can assume that this is the first cell. Then we can save this location to our state variable to keep track of it for the next click. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EC6ZiFUg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1baebneyb25xjl2ghqw8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EC6ZiFUg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1baebneyb25xjl2ghqw8.png" alt="code setting previous cell" width="768" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if the user has clicked more than once we can calculate the slope using the previous cell location and the current cell location the user just clicked on. We do this by subtracting the current row (i) from the previous row (previousCell[0]), and the current column (j) from the previous column (previousCell[1]). This will give use the rise and run values for the 2 cells, and we can pass this into our helper function!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_EsSEmBM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ot51b3q109bpvmctwetp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_EsSEmBM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ot51b3q109bpvmctwetp.png" alt="code calculating slope" width="880" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Phew! Now that we took care of that we can get back to our isValidSlope function.
&lt;/h3&gt;

&lt;p&gt;Now that we have slope calculated from above all we have to do is to see if it valid or not. &lt;/p&gt;

&lt;p&gt;How do we know what a valid slope is? &lt;/p&gt;

&lt;p&gt;Well, like we talked about earlier the only way a word can appear on the grid is horizontally, vertically, or diagonally. &lt;/p&gt;

&lt;p&gt;This means that there is only a 4 types of possible slopes. So first let's take care of the easy cases. We know that is the word is either horizontal or vertical either the rise or run will be 0. So we can return true if that is the case. (See lines 2-4 in code below)&lt;/p&gt;

&lt;p&gt;Now we have 2 more cases in which there could be a valid slope and that is diagonally up or diagonally down.&lt;/p&gt;

&lt;p&gt;If the slope if diagonally down, then the rise must be the run * -1. So, this means if we add them together then we will end up with 0. (See line 5)&lt;/p&gt;

&lt;p&gt;If the slope if diagonally up, then the rise and run must be exactly the same. So we can check if they are equal and if that is true we can return true. (See line 6)&lt;/p&gt;

&lt;p&gt;In any other case we can return false.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0lDIlbY4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7xl3f77dthyc1mn8qwo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0lDIlbY4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7xl3f77dthyc1mn8qwo.png" alt="code validating slope" width="868" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can check the slope and see if the 2 cells selected are lined up correctly. But why were we doing this again? Oh yeah, because we want to find words.&lt;/p&gt;

&lt;p&gt;We can use this to select the cells in between the 2 cells and change all of the 0's in the cells into 1's. &lt;/p&gt;

&lt;p&gt;In order to do this we can use the slope that we calculated earlier. We will start at the current cell and use the slope to calculate the rise and run factors we need to increment over the the cells between the current and previous cells. As we do this we will save each location to a new array called totalCells.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vA25dE4u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni9qae1vnuf4b5jvotte.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vA25dE4u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni9qae1vnuf4b5jvotte.png" alt="code creating new array of selected cells" width="880" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we simply set the table to the new version with all of the appropriate locations changed to 1's &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ON2ZNx-C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uyehjund38eh3d44y4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ON2ZNx-C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uyehjund38eh3d44y4j.png" alt="code setting table using new array of locations" width="880" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we can move all of this code into a helper function that gets called when the user is on their second click called selectCellsBetween.&lt;/p&gt;

&lt;h4&gt;
  
  
  AWESOME!
&lt;/h4&gt;

&lt;p&gt;We just finished the first part of this problem! We can now keep track of all the cells that are selected and make sure that the user is not just able to select any random cells.&lt;/p&gt;

&lt;h4&gt;
  
  
  In my next Blog We will build the grid of Letters...
&lt;/h4&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
  </channel>
</rss>
