<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dhanush Kumar on Medium]]></title>
        <description><![CDATA[Stories by Dhanush Kumar on Medium]]></description>
        <link>https://medium.com/@dhanush1926?source=rss-444e06738f43------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*d9A72yrBwkFQ-2uHiCq7Rg.jpeg</url>
            <title>Stories by Dhanush Kumar on Medium</title>
            <link>https://medium.com/@dhanush1926?source=rss-444e06738f43------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:58:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhanush1926/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Everything About Object Destructuring]]></title>
            <link>https://dhanush1926.medium.com/everything-about-object-destructuring-d47a90f08f3d?source=rss-444e06738f43------2</link>
            <guid isPermaLink="false">https://medium.com/p/d47a90f08f3d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Dhanush Kumar]]></dc:creator>
            <pubDate>Mon, 14 Dec 2020 19:15:43 GMT</pubDate>
            <atom:updated>2020-12-14T19:19:01.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gc0MsqvuExaTFY4W8KLKvw.jpeg" /></figure><p>In JavaScript, almost “everything” is an object. An object can be created with figure brackets {…} with an optional list of properties. A property is a “key: value” pair, where key is a string (also called a “property name”), and value can be anything. The value can be of any primitive data type like integer or boolean, it can be an array or another object. The value can also be a function. In addition to objects that are predefined in the browser, you can define your own objects. <strong>For example</strong> -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da08cb7b0157db4776d75c19645cdbd0/href">https://medium.com/media/da08cb7b0157db4776d75c19645cdbd0/href</a></iframe><h3><strong>What is object destructuring?</strong></h3><p>As the name suggests object destructuring is breaking down the structure of the javascript object into a simpler structure. Destructuring is an ES6 feature that allows you to assign the properties of an object to variables using syntax that looks similar to object literals.</p><h3><strong>Why Object Destructuring?</strong></h3><p>Prior to ES6, when you want to assign properties of the person object to variables, you typically do it like this:</p><pre>var firstName = person.firstName;<br>var street = person.address.street;</pre><p>What if there are 10’s of properties whose value needs to be stored in different variables for further use? Prior to ES6 programmers had to write multiple lines of code to store properties of an array into multiple variables like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/253569abba2c0eb95da2a03ea87b106b/href">https://medium.com/media/253569abba2c0eb95da2a03ea87b106b/href</a></iframe><p>But with ES6 destructing same can be achieved like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fe0c96c6cd01e90e8e48c1a26341f87/href">https://medium.com/media/9fe0c96c6cd01e90e8e48c1a26341f87/href</a></iframe><p>Here we defined 5 local variables key1…key5. There are 3 advantages of destructuring:</p><ol><li>The number of lines of code will reduce.</li><li>Programmers can write more readable code.</li><li>Programmers are encouraged to create local variables before use which will increase the performance.</li></ol><h3><strong>Object Destructuring</strong></h3><p>We saw the basic use and format of object destructuring. Let us explore more awesome features of object destructuring.</p><p>Let’s consider the following object for the rest of the examples.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a047edcce566101a7eca6f34f009f8d1/href">https://medium.com/media/a047edcce566101a7eca6f34f009f8d1/href</a></iframe><h4><strong>Destructuring nested object</strong></h4><p>marks is a nested object inside the student object and computers is a nested object inside marks object. We can fetch the value of the nested object using the snippet below. We created 3 local variables called lab, theory, and Maths. Here marks and Computers are not defined as a variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04eb546e14cde9f6bdb1df14db2f7f40/href">https://medium.com/media/04eb546e14cde9f6bdb1df14db2f7f40/href</a></iframe><h4><strong>Adding default value</strong></h4><p>While destructuring an object we can specify a default value to a variable. If the key is present in the object the value for the key will be stored in the variable else the default value will be stored.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1571483804209ddfbb5c9743e8c60c62/href">https://medium.com/media/1571483804209ddfbb5c9743e8c60c62/href</a></iframe><p>We created 2 local variables firstName and rank. Since firstName is present in the object it’s value will be John but rank is not present in the object so its value will be set to the default value provided while destructuring. Default value can be used while destructuring nested objects as well.</p><h4><strong>Renaming variables during destructuring</strong></h4><p>By default, we need to use the same name as the key in the object while destructuring. But in some scenarios, we need to have different variable names.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74c2bdeacf74ebb6d6ed3c1a47570d4e/href">https://medium.com/media/74c2bdeacf74ebb6d6ed3c1a47570d4e/href</a></iframe><p>We created 2 local variables called <strong>computerLab</strong> and <strong>computerTheory </strong>from lab and theory. Imagine if Physics had lab and theory scores like Computers. While destructuring both Physics and Computers marks will not be possible without renaming the local variables.</p><p>Practice object destructuring <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">here</a></p><h3><strong>Conclusion</strong></h3><p>In this tutorial, we have explored the ES6 object destructuring syntax and various ways we can utilize it in our code. Similarly, arrays can be destructured too. There are lot of other awesome features added to JavaScript like the rest and spread operator, async/await as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d47a90f08f3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conquer Dynamic Programming in 3 steps]]></title>
            <link>https://dhanush1926.medium.com/conquer-dynamic-programming-in-3-steps-be7239f1f538?source=rss-444e06738f43------2</link>
            <guid isPermaLink="false">https://medium.com/p/be7239f1f538</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[fibonacci]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Dhanush Kumar]]></dc:creator>
            <pubDate>Thu, 10 Dec 2020 12:01:18 GMT</pubDate>
            <atom:updated>2020-12-10T12:01:18.764Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ic9Ou8ZXZeiADVCXpOaKIw.jpeg" /></figure><p>Dynamic programming can be daunting in programming interviews. It can be very challenging to even get started on the solution. This article explains in detail the 3 necessary steps to solve a dynamic programming challenge.</p><p>Dynamic programming is an optimization of a plain recursive solution to a problem. It is useful to reduce the number of recursive calls made. The idea is to identify repeating subproblems and store the results of subproblems. This will reduce the time and memory needed to recompute the subproblems. For example to find the 5th Fibonacci number we need to add the 4th and 3rd Fibonacci numbers. All sounds good but to find the 4th Fibonacci number we need to add the 3rd and 2nd Fibonacci number. Do you see the problem? We are computing the 3rd Fibonacci number twice. This very problem can be solved using dynamic programming.</p><h3><strong>Example problem</strong></h3><p>To explain dynamic programming I will be solving the Fibonacci numbers problem.</p><p>The <strong>Fibonacci numbers,</strong> is a <a href="https://en.wikipedia.org/wiki/Integer_sequence">sequence</a>, called the <strong>Fibonacci sequence</strong>, such that each number is the sum of the two preceding ones, starting from 0 and 1.</p><p>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-9Uile1KuElDAZt0uk-KDA.png" /></figure><p>For example, the 8th Fibonacci number is 21</p><h3>solving and fully understanding a dynamic programming problem is a 3 step process</h3><ol><li>Determine the base case</li><li>Implement Brute force recursive solution</li><li>Optimize using dynamic programming</li></ol><p>Optionally some of the dynamic programming problems can be solved using the greedy method.</p><h3><strong>Determine the base case</strong></h3><p>The first step is to determine the base case. The base case helps to stop the recursive chain. In the Fibonacci sequence if n is 1 we return 1 and if n is zero wee return 0. So that’s our base case. When n is less than 2 we no longer proceed instead return a value.</p><pre>if(n == 1) {<br>  return 1;<br>}</pre><pre>if(n == 0) {<br>  return 0;<br>}</pre><h3><strong>Implement Brute force recursive solution</strong></h3><p>All solutions start from a brute force recursive approach and are optimized by removing unnecessary calculations. Same with the Fibonacci series. Recursive functions are those functions which, basically, call themselves.</p><p>To implement the brute force solution we calculate the Fibonacci value of n -1 and n - 2 and add those 2. This will lead to a large number of recursive calls. At every node, we make 2 recursive calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fZCdeLTekBSeZk1BtDN6jg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/638f9ba5d7cbeece45647d32f95a81a4/href">https://medium.com/media/638f9ba5d7cbeece45647d32f95a81a4/href</a></iframe><p><strong>Time and space complexity analysis</strong></p><p>We start the computation from the top node and go down the tree until we reach the base case. From the recursive tree, we can notice that at each level the number of nodes is equal to twice the number of nodes in the previous level. At root, there is only 1 node but at the 1st level there are 2 nodes and then 4,8,16 and so on.</p><p>For fib of 10 the time complexities will be 2¹⁰ since we need to go 10 levels deep and at each level the number of nodes doubles because of the branching logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vyl57mR7niW0EWlXgrExrw.png" /></figure><p>From this pattern, we can conclude that the time complexity is <strong>O(2ⁿ)</strong></p><p>Space complexity is <strong>O(n)</strong> since needs at most O(n) stacks space for recursions.</p><h3><strong>Optimize using dynamic programming</strong></h3><p>Optimizing a brute force recursive problem starts by identifying the repeating subproblems. From the above recursive chart, we can notice that the 4th, 3rd, 2nd Fibonacci numbers are computed more than once. If we store the result of these computations we can avoid finding the value more than once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCIIwN4KDZifUeSkBwmzDQ.png" /></figure><p>In the above diagram, all nodes in blue are computed once, the nodes in yellow are reused and the nodes in red are not computed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7198ce41a6ebb17cf00bbb1ff7c70bac/href">https://medium.com/media/7198ce41a6ebb17cf00bbb1ff7c70bac/href</a></iframe><p>By using an array to store the already computed values reduces the number of recursive calls made. This reduces the time complexity from exponential to linear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IsWM5m416t26ZNbin6XrIQ.png" /></figure><h3><strong>Time and space complexity analysis</strong></h3><p>The number of recursive calls made is reduced to 2 x n which reduces the time complexity to O(2n), by eliminating the constant the time complexity is O(n)</p><p>Space complexity is still O(n) because the stack space required at any given point is O(n)</p><h3>Practice problems:</h3><p>Now that you know what dynamic programming is and how to solve a problem using the technique, why don’t you try out these questions:</p><ol><li><a href="https://leetcode.com/problems/jump-game/">https://leetcode.com/problems/jump-game/</a></li><li><a href="https://leetcode.com/problems/house-robber/">https://leetcode.com/problems/house-robber/</a></li><li><a href="https://leetcode.com/problems/combination-sum-iv/">https://leetcode.com/problems/combination-sum-iv/</a></li><li><a href="https://leetcode.com/problems/shortest-common-supersequence/">https://leetcode.com/problems/shortest-common-supersequence/</a></li><li><a href="https://leetcode.com/problems/longest-common-subsequence/">https://leetcode.com/problems/longest-common-subsequence/</a></li><li><a href="https://leetcode.com/problems/longest-palindromic-subsequence/">https://leetcode.com/problems/longest-palindromic-subsequence/</a></li></ol><h3><strong>Conclusion</strong></h3><p>Any dynamic programming problems can be solved using these 3 rules but the problem is determining if a problem can be solved using dynamic programming. More and more practice will make it easy to determine if a problem has repeating subproblems and can be solved using dynamic programming.</p><blockquote>Practice makes perfect. After a long time of practicing, our work will become natural, skillfull, swift, and steady. — Bruce Lee</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be7239f1f538" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>