<?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 Aman Kumar Goyal on Medium]]></title>
        <description><![CDATA[Stories by Aman Kumar Goyal on Medium]]></description>
        <link>https://medium.com/@amanearthian?source=rss-16a27ebc7b2b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wpwl-we_KvZZUg4XtV7o6g.jpeg</url>
            <title>Stories by Aman Kumar Goyal on Medium</title>
            <link>https://medium.com/@amanearthian?source=rss-16a27ebc7b2b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:11:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amanearthian/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[Death of Ivan Ilyich]]></title>
            <link>https://medium.com/papermagnets/death-of-ivan-ilyich-9363162ef1fe?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9363162ef1fe</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[death]]></category>
            <category><![CDATA[literature]]></category>
            <category><![CDATA[tolstoy]]></category>
            <category><![CDATA[russian-literature]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Fri, 10 May 2024 03:40:38 GMT</pubDate>
            <atom:updated>2024-05-10T03:40:38.614Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you living a good life or it is a delusion?</p><p>At the age of 41, Leo Tolstoy underwent a profound change and believed that he encountered death itself, what came after is a collection of short stories revolving around death and ‘The Death of Ivan Ilyich’ is the most well-known of those stories.</p><p>This is the story of a life not well lived and its consequences. The story begins with Ivan’s friends getting the news of his death and the reaction of his colleagues who were more worried about their prospects.</p><p>The story then narrates the life of Ivan from the very beginning to his end, we get to experience his so-called ‘perfect’ life which goes downhill very sharply ending with his death. But, the story is not about Ivan or his death it asks us a very important question i. e. What does it mean to be human? Through Ivan, the author portrays a very vivid image of humans who think their success at work is everything and in doing so one misses important things in life as Ivan did neglecting his family, health, and social life he was so deep in his delusion of living a good life that only death was able to break it, only at the brisk of his death Ivan realizes that his life was not good and he could have lived it in a much better way.</p><p>The story is very much relevant in today’s as we are so indulged in our work, that we don’t focus on other aspects of life which will lead to drastic results in the future hence the delusions of Ivan are no different from those people of the current age.</p><p>So, reading the story raises a very important question whether the life we are living is good, or are we in delusion, and can it be lived in a better way?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9363162ef1fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/papermagnets/death-of-ivan-ilyich-9363162ef1fe">Death of Ivan Ilyich</a> was originally published in <a href="https://medium.com/papermagnets">papermagnets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Regression in Python]]></title>
            <link>https://medium.com/roottech/linear-regression-in-python-a587dc7fe063?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a587dc7fe063</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 14:30:45 GMT</pubDate>
            <atom:updated>2020-11-03T10:45:45.104Z</atom:updated>
            <content:encoded><![CDATA[<p>Artificial Intelligence is a hot topic now and nearly everyone wants to learn about it but artificial intelligence is a broader term consisting of a lot of many different types and techniques. Machine learning acts as a gateway to the world of artificial intelligence it is the common starting point from where people decide which subdomain of A. I. to choose and learn.</p><p>Linear Regression is the first algorithm which is taught in machine learning it is an easy regression algorithm taken from statistic. It is a starting point in machine learning it teaches a beginner how a problem is handled and how a machine learning algorithm works. So in this blog, we will see linear regression and its code in python.</p><h3>Regression</h3><p>So first, let’s talk about regression. In Regression we have few independent variables i.e. they are uncorrelated and we have to find a relation between them to get the value of dependent variable y.<br>The standard equation of regression is:</p><h3>Simple Linear Regression</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VNEBBRDof_w4LnOC.png" /></figure><p>In linear regression, we have given an input vector <strong>X </strong>with only one parameter with n entries, and also the output vector <strong>y </strong>our task is to find a relationship such that we can find the value of y of a previously unknown x.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*tUz9ynF4nBWEQ19zjgOzaQ.png" /></figure><p>Let&#39;s now see how this task is accomplished first we will go through the mathematics and see the algorithm from a statistical point of view and then we will see the machine learning point of view followed by implementation in python.</p><h3>Statistical View Point</h3><p>This is the equation of linear regression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UFGY87kIz4mKTdI4" /></figure><p>here,<br>beta0 is the intercept of the regression line and it is constant. <br>beta1 is the matrix of weights of matrix <strong>x</strong>.</p><p>To compute the linear regression hypothesis we have to find the most appropriate weights but the big question is here how? the answer is simpler by comparing the result of the hypothesis with the given output yi and minimize the error.</p><h4>Mean Squared Error</h4><p>Now the question is how would the error be calculated? We calculate by summing up the square of the difference between the y_hat and y and divide them by the total number of inputs, it is known as mean squared error (MSE) pretty intuitive name,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*Yer_ejS2AyQUxbYT" /></figure><p>The error function is also known as the cost function which we will see when we learn about the machine learning point of view.</p><p>To minimize the error function we will use differentiation: differentiating with respect to beta and setting the first derivative to zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*1HEgxzL1fPKlH8W93h7AQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*EU7cHiGfztVkTwh-GEmpmg.png" /></figure><p>So the final prediction is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*Jb9YDJcbANqA-17yrAM_vw.png" /></figure><h3>Machine Learning Approach</h3><p>In machine learning point of view, the hypothesis equation remains the same, and the error function is referred to as the cost function but here is a major difference. The cost function is not minimized with that dreadful-looking equation as it is computationally very very expensive because we have to find the inverse of a matrix and for huge matrices, inverse is a pretty expensive operation. The solution here is gradient descent an efficient algorithm to minimize the cost function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*p81N3pdLbjpuYNsm.jpg" /></figure><h4>Gradient Descent</h4><p>Gradient descent is an optimization algorithm that works pretty well in linear regression let me give you an intuitive understanding of the working of the algorithm. Suppose you are on the tip of a mountain and you want to come down to the lowest point so you would start coming down the best approach here would be a strategy to get to the bottom of the valley quickly is to go downhill in the direction of the steepest slope, that’s exactly what gradient descent does it find the steepest slope to come down fast it finds the gradient of the weight and it goes in the direction of the decreasing gradient until it reaches zero which is minimum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mxfGqWp6u10nJ2rJ.png" /></figure><p>Now, let’s see how it is implemented. The weight vector is initialized randomly and then it improves gradually taking one step at a time each step attempting to decrease the cost function until the algorithm converges to a minimum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*ruF1iecHlyp2iHYA.png" /></figure><h4>Learning Rate</h4><p>Here the most important factor is the learning rate alpha which determines the size or the length of the step it is crucial in finding the appropriate minimum, if the learning rate would be too small the algorithm will never converge while if the learning rate would be too large then it might overshoot and never converge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/0*pH4C2m01WLFgyT08.png" /></figure><h4>Convex vs Concave curve</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*eHycuEcMc1g0ymS3.png" /><figcaption>Concave Error Function with multiple minima</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*GMH-w_2p_z-P5Cju.jpg" /><figcaption>Convex Error Function with a single minima</figcaption></figure><p>When the error function is convex then it is easy to find minimum as it is only one while in the case of a convex function there can be multiple minima i.e. there are many local minima and one global minima and the learning rate should be appropriate to jump over to local minima but it should not be large enough that it even misses the global minima.</p><h3>Python Implementation</h3><p>So now we have seen both the statistical and machine learning approach let’s implement the algorithm in python and watch it in action.</p><h4>Linear Regression from Scratch</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac63ee47e7615e1fa494aacbe4b33533/href">https://medium.com/media/ac63ee47e7615e1fa494aacbe4b33533/href</a></iframe><h4>Linear Regression using Sklearn</h4><pre><strong><br>&gt;&gt;&gt; import numpy as np<br>&gt;&gt;&gt; from sklearn.linear_model import LinearRegression</strong></pre><pre><strong>&gt;&gt;&gt; X = np.array([[1, 1], <br>                  [1, 2], <br>                  [2, 2], <br>                  [2, 3]])<br>&gt;&gt;&gt; y = np.dot(X, np.array([1, 2])) + 3</strong></pre><pre><strong>&gt;&gt;&gt; reg = LinearRegression().fit(X, y)<br>&gt;&gt;&gt; reg.score(X, y)<br>1.0</strong></pre><pre><strong>&gt;&gt;&gt; reg.coef_<br>array([1., 2.])</strong></pre><pre><strong>&gt;&gt;&gt; reg.intercept_</strong></pre><h4>Regression Line</h4><p>You can see here that the regression line made by plotting y_hat against X_train is linear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*V3f_KisXq1BzLefrn7hQxA.png" /></figure><p>If are reading this then congratulations you have made it to the end of the blog and if you have any problem or issue please comment it out, if you like it please clap for me.</p><blockquote>Thank You :)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a587dc7fe063" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roottech/linear-regression-in-python-a587dc7fe063">Linear Regression in Python</a> was originally published in <a href="https://medium.com/roottech">RootTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Machine Learning is Overhyped!!!” Really?]]></title>
            <link>https://medium.com/roottech/machine-learning-is-overhyped-really-b6145d929231?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6145d929231</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Tue, 21 Jul 2020 17:41:38 GMT</pubDate>
            <atom:updated>2020-07-21T17:41:38.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X4XvZb0g6VjHNIJa" /><figcaption>Photo by <a href="https://unsplash.com/@agkdesign?utm_source=medium&amp;utm_medium=referral">Alex Knight</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“Machine Learning and Artificial Intelligence is overhyped and will take you nowhere soon.” Have you heard a lot of this term? Are you in dilemma as a beginner where to dive into the world of ML &amp; AI? Hi myself Aman Kumar Goyal and today I’ll share with you my thoughts on the above specified topic.<br>I am a student and my thoughts would be for those students who are thinking about learning AI but are in a dilemma. So, let’s begin.</p><p>There is a wave of AI going around and one can see that nearly everyone wants to learn about machine learning but the above specified phrase also go hand-in-hand and it leads to a dilemma also, observing so many students learning about ML &amp; AI sometimes it occurs in mind if everyone is learning it so how can one be able to secure a job. So what is the guarantee the that everyone would get a job or become a good researcher.</p><h4>Motivation</h4><p>Motivation is the biggest factor before beginning it you should ask yourself — Why am I going to do it? Do I really want to pursue this domain or Am I just influenced by others? You should have a very clear understanding about why you are doing it? and what is your end goal? For example, in my case I am pretty sure that I want to be a researcher and no matter what others say I know that there are unlimited possibilities in AI and I want to invent new algorithms to perform some truly astonishing tasks. You should have such a clear understanding and drive so that no one can stop you.</p><p>There are two goals for everyone in AI field — one is to do a job as an engineer or data scientist and the other one is to be a researcher let’s talk about both.</p><h4>ML engineer or Data Analyst / Scientist …</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kbVNQK8ZEk36hxuO" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=medium&amp;utm_medium=referral">Luke Chesser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A lot of people, software engineers working in industry says that jobs related to ML, DL &amp; AI are very little and the competition is fierce because nearly everyone is learning it but, let me tell you in many surveys conducted by leading institutes of the world it was found that <strong>there would a shortage of data scientists than needed </strong>now you must be thinking if everyone is learning it how come there would a shortage of data scientists. The biggest reason is that most of those learning data science are just doing it for money as there main motivation they try it for little but as they go deep into its mathematics they get demotivated and leave it. That’s what I told you, you should have a clear motivation.Hence <strong>there would be a shortage of good data scientists who can meet the industry demands</strong>.So, if you are really serious about this field then let me tell you there is no one who get stop you if you go deep into this field then there would ample opportunities for you and there is no need to worry about anything. <strong>All you need is real passion for this field</strong>, real will be assured automatically</p><h4>Researcher</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jfPjGjX6orGcnTH7" /><figcaption>Photo by <a href="https://unsplash.com/@craftedbygc?utm_source=medium&amp;utm_medium=referral">Green Chameleon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you are aiming to be researcher then you only limit is sky, data is increasing day-by-day, computation power is increasing and <strong>AI really is new electricity. </strong>Newer techniques and methods are being developed and there are infinite possibilities as AI is on a really basic level there is a long road to go to make really intelligent and efficient machines. So if you are aiming to be a researcher then there is no need to worry, you are going to contribute towards some of the greatest innovations of the tech world and there is no limit to it but you motivation and end goal should be clear. For motivation you can read about famous researchers like Andrew Ng, Yann LeCun etc.</p><h4>Ending Note</h4><p>At an ending note all I can say is AI is a booming field with endless possibilities and if you are really passionate about it then there are ample opportunities for you but, to grab these opportunities you have to make yourself pro-efficient enough to get hired or to publish a research paper in a famous journal and when you reach that level no one would be there to stop you so stop thinking about such things and work hard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aXZuva3MMq2dOxCh" /><figcaption>Photo by <a href="https://unsplash.com/@spacex?utm_source=medium&amp;utm_medium=referral">SpaceX</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><strong>Sky is the limit.</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6145d929231" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roottech/machine-learning-is-overhyped-really-b6145d929231">“Machine Learning is Overhyped!!!” Really?</a> was originally published in <a href="https://medium.com/roottech">RootTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Git & GitHub]]></title>
            <link>https://medium.com/swlh/introduction-to-git-github-2da070643251?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2da070643251</guid>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 04:54:47 GMT</pubDate>
            <atom:updated>2020-07-21T12:43:54.548Z</atom:updated>
            <content:encoded><![CDATA[<p>Well if you are enrolled in a computer science course or degree or somewhat associated with computer science domain you might have heard about these two terms and you might be wondering what are these terms , what they mean or signify and why is there so much buzz about it, so we will cover all these things and it will be a complete beginner’s guide to git , git commands and GitHub. Let’s start step by step.</p><h3><strong>Version Control</strong></h3><p>Version control systems are a category of software tools that helps software developers manage changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back and compare earlier versions of the code to help fix the mistake.</p><h3>Features of Version Control</h3><blockquote><strong>History<br></strong>Git keeps track of your source code and all the changes made to it, so that you can see what changes have been done to the project, files that are changed you will get exact details about everything.</blockquote><blockquote><strong>Backup &amp; restore<br></strong>It acts as a great resources for backup and restore, you can see changes can restore previous versions of the projects it really helps when a change breaks the whole project then you can track the change and can also restore to previous version.</blockquote><blockquote><strong>Collaboration<br></strong>It acts as a great tool for collaboration, many people can contribute to it at the same time irrespective of whether they live in the same geographic area. Everyone can alter the code whatever way he wants by making a branch and if changes are feasible then the branch is merged to the master branch.</blockquote><blockquote><strong>Sandboxing<br></strong>If you want to make big changes to your project and afraid if it would lead to a fruitful result or not then git is really helpful in such case it let you make a branch and make changes without affecting the master branch and you can merge your branch with that of master whenever you want.</blockquote><h3>Git</h3><p><strong>Git</strong> is a distributed version control system for tracking changes in source code during development. It is designed for coordinating work among programmers and track changes in any set of files. All the changes and history of a project is stores in a <strong>.git </strong>folder.</p><p>Git was created by Linus Torvalds in 2005 for development of the Linux kernel. It is the most popular and widely used version control system out there.</p><h3>GitHub</h3><p>GitHub is basically a website, a cloud hosting service that enables you to store, manage and create git repositories for free. It is most popular and largest host of source code in the world with over <strong>40 million users</strong> and more than <strong>100 million repositories.</strong></p><p>Other Alternatives to GitHub include:<br><em>GitLab.<br>BitBucket.<br>Launchpad.<br>AWS CodeCommit.<br>Google Cloud Source Repositories.</em></p><h3>Installation</h3><p>We will not discuss installation process here, for that matter I think Git has pretty easy process and also there is documentation. Just go to</p><blockquote><a href="https://git-scm.com/downloads"><em>https://git-scm.com/downloads</em></a></blockquote><p>Also creating an account on GitHub is as easy as creating on other platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/0*rZ06F3VjFWq0Qv9H" /></figure><h3>Git Config</h3><p>The git config command is a convenience function that is used to set Git configuration values on a global or local project level. These configuration levels correspond to .gitconfig text files. Executing git config will modify a configuration text file.</p><p>The most basic use case for git config is to invoke it with a configuration name, which will display the set value at that name. Configuration names are dot delimited strings composed of a ‘section’ and a ‘key’ based on their hierarchy. For example: user.email</p><p>First you have configure your username and email used for your GitHub account.</p><pre>git config — global user.name &lt;USERNAME&gt;</pre><pre>git config — global user.email &lt;EMAILID&gt;</pre><h3>Git Repository</h3><p>A Git repository is the .git/ folder inside a project. This repository tracks all changes made to files in your project, building a history over time. Meaning, if you delete the .git/ folder, then you delete your project’s history.</p><p>To create a <strong>new repository</strong>, you will need to initialize git first to do so git init command is used, it is a one time command used only once in the initial steps of creating a repository.</p><pre>git init</pre><p>Executing this command will create a new .git sub directory in your current working directory and this file will now track all the history of your project.</p><h3><strong>Git Clone</strong></h3><p>If a project is set up in a central repository and you want to commit changes you can do so by making a clone of that repository, this will enable you to working on a copy of repository on your local machine.</p><p>Git clone creates a “working copy” which has no distinction with that of the central repository i.e. it would be like a pointer to central repository, there would a connection that is established automatically by git itself.</p><pre>git clone &lt;repo&gt;</pre><pre>cd &lt;repo-dirctory&gt;</pre><p>The first command initializes a new Git repository on your local machine and add the content of the central repository to it. Hence, you get a copy of central repository on your local machine and you can work on it, commit changes and make pull requests.</p><h3><strong>Git fork</strong></h3><p>A fork is a copy of a repository, forking allows you to freely experiment with changes and these changes will not affect the original project unless they merge the pull request that you have made.</p><p>Forking is done to ensure security otherwise anyone would have change the code and create major problems only those who have access can commit changes by directly cloning the central repository.</p><p>But what if you don’t have access? don’t working here forking comes in play just fork the projet which you want to work on it will create a copy and you can work freely on this copy by cloning it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Hh0RmF0oq4InKrqZ" /></figure><p>You can find the fork button on the right left corner as shown in image.</p><h3><strong>Git commit</strong></h3><p>The git commit command captures a snapshot of the project’s currently staged changes. These snapshots can be thought of as “safe” versions of a project — Git will never change them unless you explicitly ask it to. Prior to the execution of git commit, the git add command is used to promote changes to the project that will be stored in a commit.</p><p>To commit changes done to a repository you have to follow these steps:</p><blockquote>After commiting all desired changes you would first use git add command</blockquote><pre>git add .</pre><blockquote>Instead of ‘.’ you also can specify the specific file or directory where changes are made.</blockquote><blockquote>Then you need to enter git status command which would show all the changes, files or lines of code added or deleted.</blockquote><pre>git status</pre><blockquote>Then you can commit the changes by using git commit and you shold always include a message with your commit so that anyone reviewing your commit can understand what are the changes that are committed in by you</blockquote><pre>Git commit -m”&lt;CHANGES MADE&gt;”</pre><h3><strong>Branches in Git</strong></h3><p>A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit process. You can think of them as a way to request a brand new working directory, staging area, and project history. New commits are recorded in the history for the current branch, which results in a fork in the history of the project.</p><p>The git branch command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.</p><pre>git branch</pre><p>List all of the branches in your repository.</p><pre>git branch &lt;branch&gt;</pre><p>Create a new branch called &lt;branch&gt;. This does <em>not</em> check out the new branch.</p><h3><strong>Merge Branches</strong></h3><p>Git merge will combine multiple sequences of commits into one unified history. In the most frequent use cases, git merge is used to combine two branches. The following examples in this document will focus on this branch merging pattern. In these scenarios, git merge takes two commit pointers, usually the branch tips, and will find a common base commit between them. Once Git finds a common base commit it will create a new “merge commit” that combines the changes of each queued merge commit sequence.</p><p>Say we have a new branch feature that is based off the master branch. We now want to merge this feature branch into master.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/0*SP3Pm7lByiS9klqt" /></figure><p>Invoking this command will merge the specified branch feature into the current branch, we’ll assume master. Git will determine the merge algorithm automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Ecb3RMCvcAcT-hne" /></figure><p>Merge commits are unique against other commits in the fact that they have two parent commits. When creating a merge commit Git will attempt to auto magically merge the separate histories for you. If Git encounters a piece of data that is changed in both histories it will be unable to automatically combine them. This scenario is a version control conflict and Git will need user intervention to continue.</p><h3><strong>Pull Request</strong></h3><p>Pull requests let you tell others about changes you’ve pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.</p><p>The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It’s the counterpart to git fetch, but whereas fetching imports commits to local branches, pushing exports commits to remote branches. Remote branches are configured using the git remote command.</p><h3><strong>Best Practices for using git</strong></h3><p>1. Make clean, single-purpose commits<br>2. Write meaningful commit messages<br>3. Commit early, commit often<br>4. Don’t alter published history<br>5. Don’t commit generated files</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2da070643251" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-to-git-github-2da070643251">Introduction to Git &amp; GitHub</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KNN — Understanding K Nearest Neighbor Algorithm in Python]]></title>
            <link>https://medium.com/roottech/knn-understanding-k-nearest-neighbor-algorithm-in-python-71488b8802f0?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/71488b8802f0</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Thu, 18 Jun 2020 18:24:00 GMT</pubDate>
            <atom:updated>2020-07-25T07:01:22.289Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding KNN with code in Python from scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nIZHJiLHjvGvw2jd" /><figcaption>Photo by <a href="https://unsplash.com/@mero_dnt?utm_source=medium&amp;utm_medium=referral">Chinh Le Duc</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>K Nearest Neighbors is a very simple and intuitive supervised learning algorithm. A supervised learning algorithm is one in which you already know the result you want to find. It works like this you give your model a dataset having data and results, using the data your model creates a decision boundary to predict the desired result.</p><p>It is a really intuitive and simple algorithm and it can be used both as a classifier and as a regressor. I will not give you a standardized definition of classification and regressor as it might confuse you let’s understand with an example: Given a dataset of features of cat and dog your job is to tell by examining the features that given animal is cat or dog this is a classification problem while you are given a dataset of houses having various features and price of houses on examining the data you have to predict the price of a house given to you as query this is a regression problem here you are not classifying you are predicting a value.</p><p>Now first we will see and implement kNN and then we will see how it can be used both as a classifier and a regressor.</p><h4>kNN Algorithm</h4><ol><li>Your algo would receive a query point in the dataset and you have to give results on this query point.</li><li>Calculate Euclidean distance of query points from the nearest k points(k nearest neighbors).</li><li>Store these distances in a list.</li><li>Sort the list.</li><li>Take the majority vote and predict results.</li></ol><p>So, it is pretty simple we first get a query for example on a 2-D feature set query can be [2, 3]. We take the nearest k points and calculate the distance of each point from the query point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*WRoD4F5cc0g4qba_" /></figure><p>Take a look at the picture above we have the black dot as query and we have k=3 so we calculate the distance of 3 nearest points and store distance in a list then we will sort the list and as we can see more points belong to the dataset at the top so the query belongs to the data member at the top.</p><p>Let’s now see the code which would give you a much better idea about the algorithm.</p><ul><li>First, we will import important libraries we have imported sklearn to make dummy data, matplotlib.pyplot for making plots and NumPy library which a very famous library for carrying out mathematical computations.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*RBFzby4779YrOCf6" /></figure><ul><li>Now, we will create dummy data we are creating data with 100 samples having two features.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/0*Vr3Ah4sE7_Zo-hY7" /></figure><ul><li>Let’s first see how is our data by taking a look at its dimensions and making a plot of it. X contains 100 samples of two featured data, we will put feature 1(indexed as 0) in variable x_axis and feature 2(indexed1) in y_axis and plot it out in a scatter plot using function “plt.satter(x_axis, y_axis)”, we have also plotted a query point as you can see in the pic below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/0*wizFXPnSnGVEYzYk" /></figure><ul><li>We have created a dictionary while I will be talking about after we have completed the kNN algorithm. We have also created a distance function to calculate Euclidean Distance and return it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/0*YQWG21ncdv8ZmoKr" /></figure><ul><li>Finally, we have arrived at the implementation of the kNN algorithm so let’s see what we have done in the code below.</li><li>We have defined a kNN function in which we will pass X, y, x_query(our query point), and k which is set as default at 5.</li><li>We have taken variable m which is the number of training examples using statement — m = X.shape[0].</li><li>We have created an empty list named distances.</li><li>Now, we will iterate over samples and calculate the distance of these points from query points and we will append this distance as well as the label of the point in the dataset in the distances list.</li><li>After iterating over the whole dataset we will sort the list using the sorted function you can use any other method if you want.<br>We will split the first k rows of the sorted distances list.</li><li>Converting a list to numpy array will help us a lot to perform mathematical computations a lot easier. As we have stored both distance and label we have created a new variable label and store the first column and all rows.</li><li>We now find the unique labels and number of times these labels occur and store them in two variables ‘uniq_label’ and ‘counts’ and we can predict by finding the unique label having maximum occurrence using argmax() function.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/0*DclghcHMxtDJ8p1Z" /></figure><ul><li>Now we can run a query on our model and see the prediction, note that we have returned the dictionary name corresponding to the result by using dic[int(pred)].</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*aq7N1Mx3kcxBxfs9" /></figure><h4>kNN As A Classifier</h4><p>We can use kNN as a classifier and the example above is also a classification problem and I don’t think there is nay more need to explain kNN as a classifier, I will just show how we can use kNN as a classifier to classify images of the famous <strong>Mnist Dataset </strong>but I won’t be explaining it only code will be shown here, for a hint it will group all the numbers in different cluster calculate distance of query point from all other points take k nearest and then predict the result.</p><h4>Using kNN for Mnist Handwritten Dataset Classification</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e89dfed08753c69572393cdaceba0792/href">https://medium.com/media/e89dfed08753c69572393cdaceba0792/href</a></iframe><h4><strong>kNN As A Regressor</strong></h4><p>kNN can also be used as a regressor, formally regressor is a statistical method to predict the value of one dependent variable i.e output y by examining a series of other independent variables called features in machine learning.</p><p>We will use kNN to solve the Boston House prediction problem.</p><h4>Boston House Price Prediction</h4><ul><li>Importing libraries — Matplotlib for plotting data, sklearn for model, dataset, and train_test_split.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*LcpETNL5IEGezQH7" /></figure><ul><li>Loading boston dataset and we will see the shape of our data and keys of data to get an idea about our data.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*KZgBJ9lHSCwp-bQ9" /></figure><ul><li>Splitting train and test set.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*aVmN6_7nqVM3dlhg" /></figure><ul><li>Here we are using the sklearn to implement knn I choose it to show you the usage of sklearn as till now we have just coded knn all the way from scratch. It is pretty simple with sklearn we are predicting for different values of k to see variations and it has two steps first passing parameters in the model, second fitting it for train data, to examine the model we calculate r squared error (also called r2 error) using the inbuilt score method of sklearn and at the end, we are returning the test_score, training_score and the list of models for different values of k.</li><li>We are calling our function and saving the values in the respective variables.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*bHeNcTPlQO58DtM3" /></figure><ul><li>Here are the predictions by model for varying k.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*qzMkrkCzmjWAM8iv" /></figure><ul><li>Examining performance for k=6.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*-qBlAc4y1Wv4pmlL" /></figure><ul><li>Let’s plot a graph for both train and test data. R-squared error is pretty low which shows that kNN doesn’t work well as a regressor.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Is0tsF6T1rI889aw" /></figure><h4>What should be the value of K?</h4><p>Choosing the value of k is crucial as it will determine the accuracy of your algorithm and it can change the performance of your algorithm. So, the big question arises is what should be the value of k? Let’s see…</p><ul><li>The value of k should be large as it is better to consider more neighbors but it should not be at the cost of speed that should be always kept in mind.</li><li>Value of k should not be even as it might be the case that for a query the distances belonging to different datasets might be equal for example, suppose there are 2 categories and value of k=6, now the query point is nearest to the equal number of points belonging to both categories and now model can’t distinguish and give you result.</li></ul><p>You can take sqrt(n) as a good approximation of k but it is advisable to try a few values of k and choose the most optimized value.</p><h4>Advantages</h4><ol><li><strong>KNN is pretty intuitive and simple</strong>: K-NN algorithm is very simple to understand and equally easy to implement.</li><li><strong>K-NN has no assumptions</strong>: kNN is a non-parametric algorithm and hence it has no assumptions unlike other algorithms like linear regression.</li><li><strong>No</strong> <strong>Training Step:</strong> K-NN does not explicitly build any model, it simply gives results on the new data entry, based on learning from historical data. New data entry would be tagged with the majority class in the nearest neighbor.</li><li><strong>It constantly evolves</strong>: k-NN is a memory-based approach. The classifier immediately adapts as we collect new training data. It allows the algorithm to respond quickly to changes in the input during real-time use.</li><li><strong>Very easy to implement for the multi-class problem: </strong>Most of the classifier algorithms are easy to implement for binary problems and need effort to implement for multi-class whereas KNN adjusts to multi-class without any extra efforts.</li><li><strong>Can be used both for Classification and Regression:</strong> One of the biggest advantages of KNN is that KNN can be used both for classification and regression problems.</li><li><strong>One Hyper Parameter: </strong>Choosing the right value of hyperparameter can be a very painful experience which is not the case with kNN as it has only one hyperparameter.</li><li><strong>Variety of distance criteria to choose from: </strong>KNN algorithm gives users the flexibility to choose distance while building KNN model. There are various methods to calculate distance:<br>Euclidean Distance<br>Hamming Distance<br>Manhattan Distance<br>Minkowski Distance</li></ol><h4>Disadvantages</h4><ol><li><strong>Slow algorithm</strong>: K-NN might be very easy to implement but as the dataset grows, efficiency or speed of algorithm declines very fast.</li><li><strong>Dimensionality: </strong>KNN works well with a small number of input variables but as the numbers of variables grow K-NN algorithm struggles to predict the output of the new data point.</li><li><strong>KNN needs homogeneous features</strong>: If you decide to build k-NN using a common distance, like Euclidean or Manhattan distances, it is completely necessary that features have the same scale, since a given distance in one feature must mean the same for the second feature.</li><li><strong>Optimal value of neighbors</strong>: One of the biggest issues with KNN is to choose the optimal value of hyperparameter k to be considered while classifying the new data entry.</li><li><strong>Imbalanced data causes problems</strong>: kNN doesn’t perform well on imbalanced data. If we consider two classes, A and B, and the majority of the training data is labeled as A, then the model will ultimately give a lot of preference to A. This might result in getting the less common class B wrongly classified.</li><li><strong>Outlier sensitivity: </strong>KNN algorithm is very sensitive to outliers as it simply chose the neighbors based on distance criteria.</li></ol><p><strong>I hope you liked the article if you learned something new please clap and appreciate me in the response and if you find anything wrong please inform by leaving a comment.</strong></p><p><em>Originally published at </em><a href="https://mlwithakg.blogspot.com/2020/06/knn-unserstanding-k-nearest-neighbour.html"><em>https://mlwithakg.blogspot.com</em></a><em> on June 18, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71488b8802f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roottech/knn-understanding-k-nearest-neighbor-algorithm-in-python-71488b8802f0">KNN — Understanding K Nearest Neighbor Algorithm in Python</a> was originally published in <a href="https://medium.com/roottech">RootTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Climbing up the Binary Trees in C++]]></title>
            <link>https://medium.com/roottech/climbing-up-the-binary-trees-in-c-e88a86253d62?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e88a86253d62</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[binary-tree]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Fri, 12 Jun 2020 07:37:36 GMT</pubDate>
            <atom:updated>2020-07-01T09:19:52.052Z</atom:updated>
            <content:encoded><![CDATA[<h3>Binary Trees in C++</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*erfPslHhJy6LHKhk" /></figure><p>Hello readers, now we will begin our discussion of binary trees you might have seen linear data structures but a tree is a non-linear one. So, lets dive deep in the details of binary tree and see what are they? How are they implemented? and various functionalities of binary tree.</p><p>A tree is a non-linear data structure with hierarchical arrangement of data elements called nodes. The central node at the top is called root node as it is the root of tree and all elements can be accessed by this node. The top nodes are parent node and other nodes connected to it are its child, we handle trees through this parent child relationship. Two non root nodes connected to same parent are called siblings.</p><p>There are many types of trees and our discussion will remain specific to binary tree.</p><h3>Binary Tree</h3><p>A binary tree is a tree in which each parent node has at most two children i.e each node can have either 0,1 or 2 child nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ec7ej9GlSy9rmfIm.png" /></figure><p>You can see in the figure above each node has at most 2 nodes. We refer to child nodes as left and right node.</p><h3>Types</h3><p>Based on structure of tree a binary tree can be classified into:</p><h4>Complete Binary Tree</h4><p>In complete binary tree, all levels are filled except possibly the last one, and all nodes are filled in as far left as possible i.e. it can be possible that nodes at right are not connected to any other node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*m-2OaK2Be848qqdm.jpg" /></figure><h4>Full Binary Tree</h4><p>In full binary tree, each node has either 0 or 2 nodes.</p><h4><strong>Perfect binary tree</strong></h4><p>In perfect binary tree, all nodes have two children and all leaves are at the same level.</p><h3>Common Terminologies</h3><h4>Root</h4><p>Root nodes is the topmost nodes of a tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*TCtnRrnSxP7zKu7mYN2JXQ.png" /><figcaption>A is root and parent of it’s child nodes B and C</figcaption></figure><h4>Parent Node</h4><p>Nodes which are connected to other nodes in the downward direction are called parent nodes as they act as parent to other subsequent nodes.</p><h4>Child Node</h4><p>Nodes connected to parent node are called as the child nodes of that parent.</p><h4>Leaf Node</h4><p>Leaf nodes are the last nodes i.e. nodes with no children or node present at last level of a branch.</p><h4>Internal Node</h4><p>Node which is present at position other than last level. In other words, nodes having 1 or more child nodes i.e. these are nodes other than the leaf nodes.</p><h4>Depth of a node</h4><p>Depth of a node is the number of edges between the node and root node.</p><h4>Height of a node</h4><p>Height of a node is the number of edges between the nodes and its leaf nodes. Height of root node is the height of tree.</p><h3>Creating Node of Tree</h3><p>Now, we have seen the basic terminologies of binary tree and we will begin understanding the implementation and working of binary tree. The basic unit of a binary tree is its node and to move ahead we first have create a node so lets see how can we create node of a binary tree.</p><p>Each node contains three components:</p><ul><li>Pointer to left sub-tree.</li><li>Pointer to right sub-tree.</li><li>Data element</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*YE08ItLUfoFz32-sVPuQEQ.png" /><figcaption>A node of binary tree having data A and pointer to left subtree and right subtree node</figcaption></figure><pre>class node{<br>	public:<br>	int data;<br>	node* left;<br>	node* right;<br><br>	node(int d){<br>		data = d;<br>		left=NULL;<br>		right = NULL;<br>	}<br>};</pre><p>We have used class instead of structure as we are in C++, we take three variables data for storing data elements, and two pointers left and right of data type ‘node’ as data type of a pointer to node should be same as that of the node. We have used a constructor of same name as class i.e. node, in node constructor data is passed and it is stored in data block, and left and right pointers are set to NULL as default.</p><h3>Tree Traversals</h3><p>Traversal is accessing each node of a tree, traversal can be done in many fashions and we will discuss them one by one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FPPmYDhv8baioSgq.png" /></figure><h4>PostOrder</h4><p>Post here means the parent will be accessed last, i.e. first we access left subtree then right subtree then parent node. The order would be Left → Right →Parent.</p><blockquote><strong>Algorithm<br></strong>Until all nodes are traversed −<br><strong>Step 1</strong> − Recursively traverse left subtree.<br><strong>Step 2</strong> − Recursively traverse right subtree.<br><strong>Step 3</strong> − Visit root node.</blockquote><p>Lets see what would be the postorder traversal of above tree.<br><strong><em>POSTORDER: </em></strong><em>A → C → E → D → B → H → I → G → F</em></p><h4>InOrder</h4><p>Inorder here means that will be access the tree in a order which is left to right, i.e. first we access left subtree then parent node then right subtree. The order would be Left → Parent → Right .</p><blockquote><strong>Algorithm<br></strong>Until all nodes are traversed −<br><strong>Step 1</strong> − Recursively traverse left subtree.<br><strong>Step 2</strong>− Visit root node.<br><strong>Step 3</strong>− Recursively traverse right subtree.</blockquote><p>Lets see what would be the inorder traversal of above tree.<br><strong><em>INORDER: </em></strong><em>A → B → C → D → E → F → G → H → I</em></p><h4>PreOrder</h4><p>Pre here means the parent will be accessed first, i.e. first we access the parent node the left subtree then right subtree. The order would be Parent → Left → Right .</p><blockquote><strong>Algorithm<br></strong>Until all nodes are traversed −<br><strong>Step 1</strong>− Visit root node.<br><strong>Step 2</strong>− Recursively traverse left subtree.<br><strong>Step 3</strong>− Recursively traverse right subtree.</blockquote><p>Lets see what would be the preorder traversal of above tree.<br><strong><em>PREORDER: </em></strong><em>F → B → A → D → C → E → G → I → H</em></p><h4>LevelOrder</h4><p>In levelorder traversal we will access the tree level by level from left to right . We will implement it using two functions one to traverse over a particular level and other to traverse over all levels by calling the first function.</p><p>Lets see what would be the levelorder traversal of above tree.<br><strong><em>LEVELORDER: </em></strong><em>F → B → G → A → D → I → C → E → H</em></p><pre>void printKLevel(node* root,int l){<br>	if(root==NULL)<br>		return;<br>		<br>	if(l==1){<br>		cout&lt;&lt;root-&gt;data&lt;&lt;&quot; &quot;;<br>		return;<br>	}<br>	printKLevel(root-&gt;left , l-1);<br>	printKLevel(root-&gt;right , l-1);<br>}<br>void printALLevels(node* root){<br>	int h=height(root);<br><br>	for(int i=0 ; i&lt;h ; i++){<br>		printKLevel(root,i);<br>		cout&lt;&lt;endl;<br>	}<br>	return;<br>}</pre><h3>Binary Tree Operation</h3><h4>Building Tree</h4><pre>node* buidtree(string s){<br>	if(s==&quot;true&quot;){<br>	    int d;<br> 	    cin&gt;&gt;d;<br>	    node*root=new node(d);</pre><pre>string l;<br>	    cin&gt;&gt;l;</pre><pre>if(l==&quot;true&quot;){<br>	        root-&gt;left=buidtree(l);<br>            }<br>	    string r;<br>	    cin&gt;&gt;r;</pre><pre>if(r==&quot;true&quot;){<br>	        root-&gt;right=buidtree(r);<br>	    }<br>	    return root;<br>	}<br>	return NULL;<br>}</pre><h4>Insertion</h4><pre>/*function to insert element in binary tree */</pre><pre>void insert(Node* temp, int key){ </pre><pre>        queue&lt;Node*&gt; q;<br>        q.push(temp); </pre><pre>        while (!q.empty()) {<br>              Node* temp = q.front();<br>              q.pop(); </pre><pre>              if (!temp-&gt;left) {<br>                  temp-&gt;left = new Node(key);<br>                  break; <br>              } else {<br>                  q.push(temp-&gt;left); </pre><pre>              }</pre><pre>              if (!temp-&gt;right) {<br>                  temp-&gt;right = new Node(key);<br>                  break; <br>              } else{    <br>                  q.push(temp-&gt;right);</pre><pre>              }        <br>        }</pre><pre>}</pre><h4>Deletion</h4><p>Deletion in binary tree is simpler than other trees as there is no particular ordering, but we remove the rightmost element last level of tree as it would shrink the size of tree on deletion.</p><p>If there is no specific element is not defined then the right most part gets deleted but that’s generally not used unlike stack, so generally the user or tester determines the element to be deleted we will delete the elements in two steps:</p><ul><li>First, we will swap the element to be deleted with the last i.e. the rightmost element of last level.</li><li>Second, we will remove the element present at rightmost position.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b31670896abffbe87d51a2acd401f510/href">https://medium.com/media/b31670896abffbe87d51a2acd401f510/href</a></iframe><h3>Height of Tree</h3><p>Height of tree is the height of root node which is number of edges between the root node and last node.</p><p>We can calculate the height by calculating number of edges in the left and right subtree and then take the max of them and increment by 1, recursion makes is pretty easy. We add 1 because of the extra edge used to connect the left or right subtree with root node.</p><pre>int height(node* root){<br>	if(root==NULL)<br>		return 0;<br><br>	int ls = height(root-&gt;left);<br>	int rs = height(root-&gt;right);<br>	return max(ls,rs)+1;<br>}</pre><h3>The End…</h3><p>Hope I have been able to explain each topic well and now its your turn to code binary tree yourself it will make your concepts more strong.</p><p>Keep learning and Happy Programming :— )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e88a86253d62" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roottech/climbing-up-the-binary-trees-in-c-e88a86253d62">Climbing up the Binary Trees in C++</a> was originally published in <a href="https://medium.com/roottech">RootTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ins & Outs of Queues in C++]]></title>
            <link>https://medium.com/roottech/the-ins-outs-of-queues-in-c-41bce61f2c79?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/41bce61f2c79</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 16:28:37 GMT</pubDate>
            <atom:updated>2020-06-03T16:29:24.544Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello readers, in this blog we are going to learn about queues and I am going to give you in-depth insight to queues and we will also see some important and powerful methods that comes in C++ Standard Template Library. So, lets get started…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ge-TKCrPLEFRG1KQ" /><figcaption>Photo by <a href="https://unsplash.com/@levidjones?utm_source=medium&amp;utm_medium=referral">Levi Jones</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Queue data structure is a linear data structure which follows a FIFO i.e. First In First Out order, so you might be asking what does that mean? it’s means is element which comes first in the queue will be the first to leave it. As you can see in the above image, in a waiting queue the person which comes first will be the first to leave the queue and whenever you find it difficult to understand anything about queue, you should compare it with a real life queue because the insertion and deletion operations in queue data structure are just like these real life queues.</p><p>There are four types of queues :</p><ul><li>Simple Queue.</li><li>Circular Queue.</li><li>Priority Queue.</li><li>Doubly Ended Queue.</li><li>Circular Doubly Queue.</li></ul><p>In this blog, we will not see priority queue and discuss the rest in detail so, lets begin.</p><h3>Queue Operations &amp; Methods</h3><h4>Front</h4><p>Front is like a pointer(but not literally a pointer), it stores the index of the first element present in the queue. We will see how front is handled in the enqueue and dequeue operations.</p><h4>Rear</h4><p>Rear is just like front but it stores the index of last element present in the queue. We will see manipulation of rear in detail in enqueue and dequeue operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*Cw7kulAN46MiY3A5.png" /></figure><h4>isfull</h4><p>isFull method is used to check whether the queue is full or not. It’s implementation is simple, we have to just check if the rear is equal to last index of queue container. It is a boolean type function.</p><pre>MAX_SIZE = n; // max_size is the maximum size of the queue container <br>bool isFull(){<br>     return rear == MAX_SIZE-1 ;<br></pre><h4>isEmpty</h4><p>isEmpty method is used to check whether the queue is empty or not. It is a boolean type function. It returns true if front is equal to -1 or front is greater than rear.</p><pre>bool isEmpty(){<br>     return front == -1;<br>}</pre><h4>Enqueue</h4><p>Enqueue is the insertion operation of queue, insertion is done at the end of queue as done is a real life queue. On insertion the rear variable is updated to increase its value by one. Lets see the algorithmic steps to understand the enqueue operation better.</p><blockquote>1) Check for isFull condition as we can’t insert a new element in a queue which is already filled.<br> if(isFull()) <br> print(“Overflow”);<br> return;</blockquote><blockquote>2) If queue is not full then we again need to check for two more conditons.</blockquote><blockquote>3) If front == -1 then we will increment both front and rear. In the beginning we will initialize both front and rear with -1, and if front is equal to -1 then it indicates that queue is empty and we are adding first element to queue and hence both front and rear have same index value i.e. 0.</blockquote><blockquote>4) Else we will just increment rear as we have to add new element next to current last element and to do so we are incrementing rear.</blockquote><blockquote>5)At last we will just put the data at index rear in queue.<br> queue[rear] = data;</blockquote><blockquote>6) Return</blockquote><h4>Dequeue</h4><p>Dequeue is the deletion operation of queue, deletion is done from the front of queue as done is a real life queue. On deletion the front variable is updated to decrease its value by one. Lets see the algorithmic procedure</p><blockquote>1) Check for isEmpty condition as we can’t delete an element from a queue which is empty.<br> if(isEmpty()) <br> print(“Underflow”);<br> return;</blockquote><blockquote>2) If queue is not empty then we again need to check for two more conditons.</blockquote><blockquote>3) If front == rear, this case arise only if there is only one element is present in queue, we will reset both front and rear as after deleting this last element the queue will be empty we will do so by setting value of front and rear to -1.</blockquote><blockquote>4) Else we will just increment front.</blockquote><blockquote>5) Return</blockquote><h3>Coding Implementation in C++</h3><h4>Implementation by simple array</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6b00c98068182c1b74e07de18adb78b/href">https://medium.com/media/f6b00c98068182c1b74e07de18adb78b/href</a></iframe><h3>An Empty queue can also be full !!!</h3><p>Yes, it is a pretty big problem with a simple queue that even if there are few empty blocks present in queue it can still overflow. Lets see the scenerio in which this condition occur.</p><p>Suppose we have made a queue of 8 blocks and we have added 8 elements now, in this case queue is full and the rear is pointing to index 7, if we remove few elements suppose 4 elements from queue then the front variable which was pointing to 0 would now points to fifth element i.e. index 4. Now, we have 4 blocks empty but if we try to add a new element then we can’t do so because rear is already at the maximum possible index. So you can see even if we have 4 empty blocks we have encountered overflow condition that’s a huge wastage of storage. Hence, we need more efficient techniques to overcome this issue.</p><h3>How To Overcome?</h3><p>To overcome the issue discussed above we use different techniques and approaches. We can shift all the elements on deletion but shifting all elements is a little costly hence we come up with newer implementation ideas of queues and these queues solved the above mentioned issue really well.</p><p>We use circular queue in which we just handle the front and rear a little bit differently and it shows astonishing results. There are two more queues doubly queue and circular doubly queue these can also handle the issue really well and in all these three circular doubly is the best.</p><h3>Circular Queue</h3><p>As we have seen that, weight the condition that queue is full even if there are few vacant spaces in the queue. To overcome this limitations we use circular Queue which is just a little different approach and the array remains same we just code it in such a way that the queue behaves like it is circular with last element connected with the first. It follows just few changes and you will get much efficient circular queue which will ensure full storage utilization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*iEQXZZXG7Wmh_JcJI64YGA.png" /></figure><h3>Implementation of circular array</h3><p>We will see coding implementation of circular queue in C++ and once I show you the code I will explain everything in detail.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ddd4814fc753f0f8657bc9bd8863a02/href">https://medium.com/media/1ddd4814fc753f0f8657bc9bd8863a02/href</a></iframe><p>So, you can there is nothing special just we have taken mod while updating values of front and rear this will ensure that all spaces get utilized also, rear is initializes with MAXSIZE -1. Try to dry run with an example you will understand it yourself it’s pretty simple just give it a try you will learn a lot.</p><h3>Queue STL</h3><p>Standard template library of C++ has great inbuilt functions and method and we will them.</p><ul><li><strong>empty → </strong>Test whether container is empty.</li><li><strong>size → </strong>Return size of container .</li><li><strong>front → </strong>Access front element of queue container.</li><li><strong>back →</strong>Access last element of queue container.</li><li><strong>push → </strong>Insert element in queue container..</li><li><strong>emplace → </strong>Construct and insert element in queue container. .</li><li><strong>pop → </strong>Remove next element from queue container..</li><li><strong>swap → </strong>Swap contents of queue container.</li></ul><h3>Doubly Ended Queue (Deque)</h3><p>Doubly Ended Queue, commonly referred to as deque is a special type of queue in which on can insert and delete at both the ends of the queue hence the name doubly ended. It makes some operations easier and helps in better storage utilization as compared to simple queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UUPX5ofQJPz4EQ9n.png" /><figcaption>Deque</figcaption></figure><p>Implementation of deque is pretty simple and similar to simple queue just you have write two additional functions for insertion at front and deletion at end, also there might need to change few conditions a little. We can also implement deque using circular queue which makes it much more efficient.</p><p>I am leaving the implementation of deque as an exercise for you hoping that you will try yourself and trust me it will be fun and will give you a deeper insight in concepts of queue.</p><h3>Deque in STL</h3><p>In standard template library, we generally use deque as it is efficient and has many amazing inbuilt functions you can see yourself deque is equipped with much more functions as compared to simple queue.</p><h4><strong>Iterators</strong>:</h4><ul><li><strong>begin → </strong>Return iterator to beginning of queue .</li><li><strong>end →</strong>Return iterator to end of queue container.</li><li><strong>rbegin →</strong>Return reverse iterator to reverse beginning of queue.</li><li><strong>rend →</strong>Return reverse iterator to reverse end of queue container.</li><li><strong>cbegin →</strong><a href="http://www.cplusplus.com/reference/deque/deque/cbegin/"><strong> </strong></a>Return const_iterator to beginning of queue .</li><li><strong>cend →</strong><a href="http://www.cplusplus.com/reference/deque/deque/cend/"><strong> </strong></a>Return const_iterator to end of queue .</li><li><strong>crbegin →</strong>Return const_reverse_iterator to reverse beginning of queue.</li><li><strong>crend →</strong>Return const_reverse_iterator to reverse end of queue container.</li></ul><h4><strong>Capacity</strong></h4><ul><li><strong>size →</strong>Return size of queue container.</li><li><strong>max_size →</strong>Return maximum size of queue container.</li><li><strong>resize →</strong>Change size of queue container.</li><li><strong>empty →</strong>Test whether container is empty of queue container.</li><li><strong>shrink_to_fit →</strong><a href="http://www.cplusplus.com/reference/deque/deque/shrink_to_fit/"><strong> </strong></a>Shrink to fit of queue container.</li></ul><h4><strong>Element access</strong>:</h4><ul><li><strong>at →</strong>Access element of queue container..</li><li><strong>front →</strong>Access first element of queue container..</li><li><strong>back →</strong>Access last element of queue container..</li></ul><h4><strong>Modifiers</strong>:</h4><ul><li><strong>assign →</strong>Assign container content .</li><li><strong>push_back →</strong>Add element at the end of queue .</li><li><strong>push_front →</strong>Insert element at beginning of queue .</li><li><strong>pop_back →</strong>Delete last element of queue .</li><li><strong>pop_front →</strong>Delete first element of queue .</li><li><strong>insert →</strong>Insert elements from the queue.</li><li><strong>erase →</strong>Erase elements from the queue.</li><li><strong>swap →</strong>Swap content of the queue.</li><li><strong>clear →</strong>Clear content of the queue.</li><li><strong>emplace →</strong>Construct and insert element at the queue.</li><li><strong>emplace_front → </strong>Construct and insert element at beginning of the queue.</li><li><strong>emplace_back →</strong>Construct and insert element at the end of the queue.</li><li><strong>swap → </strong>Exchanges the contents of two deque containers .</li></ul><h3>Here comes the end….</h3><p>So that’s all, we have reached the end of blog and we have covered the basics of simple, doubly, circular queue and we have seen STL functions and methods for simple queue and deque. I hope you understood what we have discussed and do try to code all the queues yourself it will strengthen the concepts even more. <br>If you feel there is anything missing in the blog please let me know by leaving a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J_kqmZQ1vqIzN0Jh" /><figcaption>Photo by <a href="https://unsplash.com/@adigold1?utm_source=medium&amp;utm_medium=referral">Adi Goldstein</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Okay then keep learning and Happy Programming : — )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41bce61f2c79" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roottech/the-ins-outs-of-queues-in-c-41bce61f2c79">The Ins &amp; Outs of Queues in C++</a> was originally published in <a href="https://medium.com/roottech">RootTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack in C++]]></title>
            <link>https://levelup.gitconnected.com/stack-in-c-50b1a19d4c98?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/50b1a19d4c98</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Fri, 29 May 2020 17:14:46 GMT</pubDate>
            <atom:updated>2020-05-31T12:38:06.333Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JzghhrMKthHY0-59" /><figcaption>Photo by <a href="https://unsplash.com/@sincerelymedia?utm_source=medium&amp;utm_medium=referral">Sincerely Media</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Welcome back readers, in this blog we are going to learn basics of stack and their coding implementation. Inbuilt functions and methods will also be covered briefly. So lets dive right in and begin our learning journey about stacks.</p><h3>What is a Stack?</h3><p>A stack is a linear data structure having data elements stored in a contiguous manner. It follows <strong>LIFO order i.e. Last In First Out order</strong>, in which the element which is inserted at the end gets popped out first. One can only push or pop an element from the top. You can get a better understanding of stack if you compare it with a stack of books.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lSu1IlCejX_AEkSP" /><figcaption>Photo by <a href="https://unsplash.com/@kaimantha?utm_source=medium&amp;utm_medium=referral">Claudia Wolff</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Take a look at the above image, the book placed last in stack is on top of stack and can be popped out(removed) from stack easily. On the other hand, the book which is placed first in the stack is at bottom and would be the last to be popped out.</p><p>It is a pretty simple data structure but has good applications and there are things which can only be best done using a stack.</p><h3>Applications of stack</h3><ul><li>Balancing of symbols.</li><li>Infix to Postfix / Prefix conversion.</li><li>Redo-undo features at many places.</li><li>Forward and backward feature in web browsers.</li><li>Used in algorithms like Tower of Hanoi, tree traversals, stock span problem, histogram problem.</li><li>In Graph Algorithms like Topological Sorting and Strongly Connected Components.</li></ul><h3>FLOW</h3><p>Before moving on to the implementation of the stack, we will first discuss the two most occurring words while performing stack operations these are:</p><h4>Underflow</h4><p>In underflow condition, all the elements of stack get removed i.e. there is no element in stack and stack is empty. If someone tries to remove one more element from this empty stack then the condition occurred is called underflow.</p><h4>Overflow</h4><p>Overflow condition occurs in a stack of a fixed size in this condition, the stack gets full i.e. all the space gets occupied and if one more element gets inserted in the stack then it can’t be done and the stack will overflow due to more data than it can hold.</p><h3>Building Stack</h3><p>Now we will see how a stack is made. I will use a class instead of structure and, I will use a vector to implement a stack as it makes our work much much easier and you will see it yourself if you have ever tried implement stack using simple array. If not just see the code for that you will understand yourself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*L17ufGQ00AZQwxDN.jpg" /></figure><pre>class stack{<br>	private:<br>	vector&lt;int&gt; v;<br><br>	public:<br>	void push(int data){<br>		v.push_back(data);<br>	}<br><br>	bool isEmpty(){<br>		return v.size() == 0;<br>	}<br><br>	int top(){<br>		return v[v.size()-1];<br>	}<br>	void pop(){<br>		if(!isEmpty()){<br>			v.pop_back();<br>		}<br>	}<br>};</pre><p>We have used a vector v and declared it private so that no one can access it directly. we have made methods through which we can use access stack. There are four basic stack operations.</p><h4>push()</h4><p>Push operation is for insertion at the top of stack. We have used the push_back method of vector to add a new element at the end of stack vector, apparently which is the top of our stack. Now you can see how much easier our work has become using vector.</p><h4>pop()</h4><p>Pop operation is used to pop out the top most element of the stack. We have used the pop_back method of vector to do so. To pop out, we first check if the stack is empty or not if it is not empty then the element can be popped out otherwise <strong>underflow </strong>condition is met.</p><h4>top()</h4><p>Top refers to the topmost element of stack. This method is used to get the element present at the top of the stack. In an array implementation we have to update the value of top and the element at the index top is returned when this method is called, but in our case returning the last element of vector will do our work, and we don’t need to keep a top variable or to update it. Again using vector has a clear advantage here.</p><h4>isEmpty()</h4><p>In this method, we check whether the stack is empty or not, and it is used in pop operation to avoid “underflow” condition. It returns a bool result for whether the size of the vector is zero or not.</p><p>There is one more method, <strong>IsFull(). </strong>It is used with an array to check if the stack is full or not but, in case of vector we haven’t predefined any size and hence there is no upper limit of size like 10 or 10000. That’s why we haven’t used it in our implementation.</p><h3>Another implementation</h3><p>There is another implementation using a linked list. The top of stack is represented by head, all the insertions will be insertion_at_head and deletion will also be from the head, underflow condition would met if next of a node points to NULL and there will be no isFull condition.</p><p>I would suggest you to try implement stack with a linked list yourself. It would help you a lot to understand the concepts, and it is pretty simple and I have already given you some hints which are more than sufficient.</p><h3>Stack STL</h3><p>These libraries have very efficiently written code with better space and time complexity. To use stack STL, you need to include the stack header then you can declare stack of any data type you want.</p><pre>#include&lt;stack&gt;  // To include stack library<br>stack&lt;int&gt; s; // stack of integers.</pre><p>Now you can use all the methods of stack directly without coding them beforhand. The basic methods are:</p><p><strong>push </strong>→ Inserts element at the top of the stack.</p><p><strong>pop </strong>→ It removes the element at the top of stack.</p><p><strong>top → </strong>Top method is used to accesses the top element of stack.</p><p><strong>empty → </strong>checks whether the underlying container is empty</p><pre>#include &lt;iostream&gt;       <br>#include &lt;stack&gt;          </pre><pre>using namespace std;<br>int main (){<br>  stack&lt;int&gt; m;</pre><pre>  for (int i=0; i&lt;5; ++i) <br>       m.push(i);           <strong>//Using Push operation to insert element</strong></pre><pre>  cout &lt;&lt; &quot;Element at top is &quot; &lt;&lt; m.top() &lt;&lt; endl;</pre><pre>  cout &lt;&lt; &quot;Popping out elements...&quot;;<br>  while (!m.empty()){       <strong>//using empty method </strong></pre><pre>     cout &lt;&lt;&#39; &#39;&lt;&lt; mystack.top();<strong>//top to see the element at top</strong><br>     m.pop();               <strong>//Using pop to pop out elements</strong><br>  }</pre><pre>  return 0;<br>}</pre><pre><strong>Output:</strong></pre><pre>Element at top is 15<br>Popping out elements... 4 3 2 1 0</pre><p><strong>size → </strong>It returns the number of elements present in stack.</p><pre>#include &lt;iostream&gt;       <br>#include &lt;stack&gt;          <br><br>using namespace std;<br>int main (){</pre><pre>  stack&lt;int&gt; m;<br>  cout &lt;&lt; &quot;size: &quot; &lt;&lt; m.size() &lt;&lt; endl;<br><br>  for (int i=0; i&lt;5; i++) <br>       m.push(i);<br>  cout &lt;&lt; &quot;size: &quot; &lt;&lt; m.size() &lt;&lt; endl;<br><br>  return 0;<br>}</pre><pre><strong>Output:</strong></pre><pre>size: 0<br>size: 5<br></pre><p><strong>emplace </strong>→ It constructs element in-place at the top of stack.</p><pre>#include &lt;iostream&gt;      <br>#include &lt;stack&gt;          <br>#include &lt;string&gt;  </pre><pre>using namespace std;     <br>int main (){</pre><pre>  stack&lt;string&gt; m;<br><br>  m.emplace (&quot;First sentence&quot;);<br>  m.emplace (&quot;Second sentence&quot;);<br><br>  cout &lt;&lt; &quot;m contains: &quot;&lt;&lt;endl;<br>  while (!m.empty()){<br>    cout &lt;&lt; m.top() &lt;&lt; endl;<br>    m.pop();<br>  }<br><br>  return 0;<br>}</pre><pre><strong>Output</strong>:</pre><pre>mystack contains:<br>Second sentence<br>First sentence</pre><p><strong>swap </strong>→ It swaps the contents of the stack.</p><pre>#include &lt;iostream&gt;  <br>#include &lt;stack&gt;       </pre><pre>using namespace std;<br>int main (){</pre><pre>stack&lt;int&gt; stack1, stack2;<br>  stack1.push(10); <br>  stack1.push(20); <br>  stack1.push(30);<br>  <br>  stack2.push(40); <br>  stack2.push(50);<br><br>  stack1.swap(stack2);<br><br>  cout &lt;&lt; &quot;Elements of stack1: &quot; &lt;&lt; endl;<br>  while (!stack1.empty()){<br>    cout &lt;&lt; stack1.top() &lt;&lt; endl;<br>    stack1.pop();<br>  }</pre><pre>cout &lt;&lt; &quot;Elements of stack2: &quot; &lt;&lt; endl;<br>  while (!stack2.empty()){<br>    cout &lt;&lt; stack2.top() &lt;&lt; endl;<br>    stack2.pop();<br>  } </pre><pre>  return 0;<br>}</pre><pre><strong>Output:<br></strong>Elements of stack1: <br>50<br>40<br>Elements of stack2: <br>30<br>20<br>10<br></pre><p>You can yourself how much easier STL makes our work and as I told you before these are very efficient.</p><h3>The End</h3><p>And here comes the end we have seen the basics of the stack, its inbuilt methods, and implementation in C++.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JUIC6U2DumRlbLmx" /><figcaption>Photo by <a href="https://unsplash.com/@adigold1?utm_source=medium&amp;utm_medium=referral">Adi Goldstein</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I hope you have understood what’s been discussed, If you like this article please leave a clap. <br>Keep coding and Happy Programming : — )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50b1a19d4c98" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/stack-in-c-50b1a19d4c98">Stack in C++</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Linked Lists in C++]]></title>
            <link>https://medium.com/swlh/all-about-linked-lists-in-c-687d0945cb0?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/687d0945cb0</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Wed, 27 May 2020 16:16:13 GMT</pubDate>
            <atom:updated>2024-07-01T19:01:57.865Z</atom:updated>
            <content:encoded><![CDATA[<p>Linked lists are very important, useful and powerful data structures and are used for many purposes in C++. In this blog I am going to cover as much as possible from a beginner’s point, so let’s get started.</p><p>Linked list is a linear data structure in which data is stored in a contiguous manner, each element is stored in the form of a node, a node is created dynamically on run-time and these nodes are connected using pointers.<br>Linked lists are of many times</p><ul><li>Singly Linked List.</li><li>Doubly Linked List.</li><li>Circular Linked List.</li><li>Circular Doubly Linked List.</li></ul><p>Below is an image of a singular linked list to give you a glimpse of how data is arranged in a singly linked list. Ignore the details we will cover them later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*Aw3w0MnSL5zhcj3Z.png" /></figure><h3>Linked Lists v/s array</h3><p>In some operations linked lists come out to perform better than arrays. I am covering this because you should be aware of the merits and demerits of linked lists over arrays, only then you would understand the necessity of linked lists.</p><h4>Merits</h4><ul><li>Elements are added dynamically.</li><li>There is no need for a continuous block of memory nodes present at different memory locations which are connected by pointers.</li><li>Insertion and deletion operations are more efficient than an array.</li></ul><h4>Demerits:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*NNiXTsDTD5UlJ3eIG5VmZQ.png" /><figcaption>Node of Singly Linked List</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*Oq7kMmsvsT_AnhExeoDJqg.png" /><figcaption>Node of Doubly linked list</figcaption></figure><ul><li>Linked Lists take more memory as it is required more memory for pointer block i.e. to store an element you need twice the memory for two blocks one for element itself and other for the address of next node.</li></ul><p>In case of doubly linked list there are two extra blocks one for address of next node and one for previous block.</p><ul><li>In linked list one can’t randomly access data element which is really easy in case of array.</li></ul><h3>Singly Linked Lists</h3><p>In Singly linked lists nodes have only one pointer i.e. to the address of next node and due to having only one connected they are called so.</p><p>You use an analogy to visualize better, compare it to a train where engine is the head and every coach represents a block each block is connected to next block by a link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X2JmereSTJO861lB" /><figcaption>Photo by <a href="https://unsplash.com/@drc1948?utm_source=medium&amp;utm_medium=referral">Denis Chick</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Now we will see how we can build a linked list in cpp all its basic operations then we will see some some inbuilt functions and modules to make which are very powerful and makes our work much easier.But first let’s how the node of a singly linked list is created.</p><h3>Node</h3><p>Well a node can be built using a structure as in C but in my opinion it is better to use the power and capabilities of classes in C++, hence I will show you how to create a node in C++ using class.</p><pre>class node{<br>public:<br> int data;<br> node* next;</pre><pre>node(int d){<br>  data = d;<br>  next = NULL;<br> }<br>};</pre><p>So you can see we have got a class named node, there are two variable one is of type int for element of integer type(you can store any type of data in your list by changing the type here, you can also make a templated list and define the type later in main() ), and the other is of type node as you are aware of fact that a pointer to anything should be of data type same as that of the element which the pointer is pointing.<br>Now, in the constructor named <strong>node </strong>we have got an input and we have specified the input to data variable and set the address of next node to be null.</p><p>As you go on to functionalities of linked lists you will get a better understanding as then you will be able to see the bigger picture.</p><h3>Insertion</h3><p>Moving on to our next topic i.e. insertion in linked list, insertion operation can be done at head, at the end or at any other position. One important thing before moving on, we store the address of first node in a pointer named head to refer the list it is very important variable and at any point if you mess up with the head it might happen that your whole list might get lost.</p><p>So coming back to insertion I will show insertion at head, end and at any other position but it is advised to insert an element at head as it would take constant time and it is the easiest. Let’s dive right in to code.</p><h4><strong>Insertion at Tail</strong></h4><p>It requires to traverse over the whole linked list to insert at tail, we first declare a new node and put the input data in the data block using the constructor we have made it is most common step and you have to create a node every time so it will itself comes in handy. <br>First we check if the list is empty because if it is so then we have to just add new node as first element, if this is not the case then we will traverse by running loop till we reach the end of list and then add node.<br>End condition is checked by <strong>while(temp-&gt;next !- NULL), </strong>where NULL denote that end is reached and one more thing to consider is to use a different variable each time so that you wouldn’t mess up with the head node. Also notice that we have passed the head node as reference that’s why we don’t need to return the node.</p><pre>void insertAtTail(node* &amp;head ,int d){<br> node* n = new node(d);<br> if(head == NULL){<br>  head = n; <br> }</pre><pre>else{<br>  node* temp = head;<br>  while(temp-&gt;next != NULL){<br>   temp = temp-&gt;next;<br>  }<br>  temp-&gt;next = n;<br> }<br> return;<br>}</pre><h4><strong>Insertion at Head</strong></h4><p>It is pretty simply, we first create a new node which is same as done before then we check if the list is empty if it is then just add it as first element, if it is not then put the address of head in the next of new node and the address of new node in head.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*3u0Wl5wwrwdL-54T.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*Q5XqhLzESYgfBnwe.png" /></figure><pre>void insertAtHead(node* &amp;head ,int d){<br>	node* n = new node(d);<br>	if(head == NULL){<br>		head = n;	<br>	}<br><br>	else{<br>		n-&gt;next = head;<br>		head = n;<br>	}<br>	return;<br>}</pre><h4><strong>Insertion at any position given</strong></h4><p>We create a node same as in above cases then we iterate to reach at position one less than given we do so because if it is needed to add a new node at fourth position then we need to be on third position then we connect new node using this node.</p><pre>void insertAtOther(node* &amp;head, int d, int position){<br>	node* n = new node(d);<br>	if(postion == 1){<br>		n-&gt;next = head;<br>		head = n;	<br>	}<br>	else{<br>		node* temp = head;<br>                position = position-1;<br>                while(position--){<br>                      temp = temp-&gt;next;<br>                }<br>          <br>                n-&gt;next = temp-&gt;next;<br>                temp-&gt;next = n;<br>        }<br>	return;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*5daTkcrnCYJz-H1G" /></figure><p>Above is a figure showing insertion at third position. While working with liked lists it is often better to visualize everything in your mind beforehand it will make your work more easier.</p><p>Now you try to visualize insertion a head and tail and see how easy it becomes to understand the code.</p><h3>Printing List</h3><p>Traversing and printing list is pretty simple we create a temp variable store head in it and traverse using this temp variable.</p><pre><br>void printList(node* &amp;head){<br>	node*temp=head;<br>	while(temp!=NULL){<br>		cout&lt;&lt;temp-&gt;data&lt;&lt;&quot; &quot;;<br>		temp = temp-&gt;next;<br>	}<br>	return;<br>}</pre><h3>Deletion</h3><p>Deletion operation is one of primary operations of linked list and are important in understanding linked lists better. Deletion can our at head, tail and at any given position. We will see code one by one but I am not going to explain everything as I have already done before and it would be better if you yourself try to understand you code to improve to understanding. Let’s get started</p><h4>Deletion at Head</h4><pre>void deletionAtHead(node* &amp;head){<br>	<br>	if(head == NULL){<br>		cout&lt;&lt;&quot;List is empty&quot;&lt;&lt;endl;	<br>	}<br><br>	else{   <br>                node* temp = head;<br>		head = temp-&gt;next;	<br>                free(temp);<br>        }<br>	return;<br>}</pre><h4>Deletion at Tail</h4><pre>void deletionAtTail(node* &amp;head){<br> <br>        if(head == NULL){<br>                cout&lt;&lt;&quot;List is empty&quot;&lt;&lt;endl;<br>        }<br>        if(head-&gt;next == NULL){<br>                delete head;<br>                head= NULL;<br>        }      <br>        else{<br>                node* temp = head;<br>                while((temp-&gt;next)-&gt;next != NULL){<br>                      temp= temp-&gt;next;<br>                }<br>                delete(temp-&gt;next);<br>                temp-&gt;next = NULL;<br>        }<br>        return;<br>}</pre><h4>Deletion at any other position</h4><pre>void deletionAtOther(node* &amp;head, int position){</pre><pre>        if(head == NULL){ <br>                cout&lt;&lt;&quot;List is empty&quot;&lt;&lt;endl;<br>        }	<br>	if(postion == 1){<br>		delete head;<br>		head = NULL;	<br>	}<br>	else{<br>		node* t1 = head, t2;<br>                position--;<br>                while(position--){<br>                      t1 = t1-&gt;next;<br>                }<br>                t2 = t1-&gt;next-&gt;next; <br>                free(t1-&gt;net);               <br>                t1-&gt;next = NULL;<br>        }<br>	return;<br>}</pre><h3>Doubly Linked List</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*A6722a_zCls8sHfMz4vTnA.png" /></figure><p>Doubly linked list is very similar to singly linked list , instead of just one pointer it has got two pointers one for previous block and one for next block and we use a head and a tail pointer variable to point the head and tail of list use of two pointers makes it much easier to perform operations but it also costs us more memory.</p><pre>class node{<br>    public:<br>       int data;<br>       node* next, *prev;</pre><pre>    node(int d){<br>       data = d;<br>       prev = NULL;  <br>       next = NULL;<br>    }<br>};</pre><p>As you can see the node is very similar to singly linked list and the coding part is also very similar just you have to deal with another previous pointer. You can code it up yourself from the concepts you have and that’s I am not going to show you the code for operations in doubly linked list.</p><h3>Circular Linked Lists &amp; Doubly Circular Linked List</h3><p>Circular and doubly circular linked linked are just singly and doubly linked list with its last element pointing to first node. It makes our work even more easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/0*zmuNeh64Nd4chLwa.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/0*uijtvi-TRa4AQS21" /></figure><p>Above images will give you an insight about how they work and the coding part is similar to those discussed above just you have to point the last node to first node.</p><h3>List STL</h3><p>C++ STL is a powerful library which provides us many inbuilt functions and methods which makes our work much more easier. You can use the list STL by including “list”.</p><pre>#include&lt;list&gt;<br>list&lt;int&gt; l;</pre><p>We will see briefly the basic functions and methods available in C++.</p><h4><strong>Iterators</strong>:</h4><ul><li><strong>begin → </strong>Return iterator pointing to beginning of the list.</li><li><strong>end → </strong>Return iterator pointing to end pointof the list.</li><li><strong>rbegin →</strong>Return reverse iterator pointing to reverse beginning of the list.</li><li><strong>rend →</strong>Return reverse iterator pointing to reverse end of the list.</li><li><strong>cbegin →</strong>Return const_iterator pointing to beginning of the list.</li><li><strong>cend →</strong>Return const_iterator pointing to end of the list.</li><li><strong>crbegin →</strong>Return const_reverse_iterator pointing to reverse beginning of the list.</li><li><strong>crend →</strong>Return const_reverse_iterator pointing to reverse end of the list.</li></ul><h4><strong>Capacity</strong>:</h4><ul><li><strong>empty →</strong>Test whether container is empty.</li><li><strong>size → </strong>Returns the size of the storage space currently allocated to the list.</li><li><strong>max_size →</strong>Return maximum size of the list.</li></ul><h4><strong>Element access</strong>:</h4><ul><li><strong>front →</strong>Access first element of the list.</li><li><strong>back →</strong>Access last element of the list.</li></ul><h4><strong>Modifiers</strong>:</h4><ul><li><strong>assign →</strong>Assign new content to container of the list.</li><li><strong>emplace_front →</strong>Construct and insert element at beginning of the list.</li><li><strong>push_front →</strong>Insert element at beginning of the list.</li><li><strong>pop_front →</strong>Delete first element of the list.</li><li><strong>emplace_back →</strong>Construct and insert element at the end of the list.</li><li><strong>push_back →</strong>Add element at the end of the list.</li><li><strong>pop_back →</strong>Delete last element of the list.</li><li><strong>emplace →</strong>Construct and insert element of the list.</li><li><strong>insert →</strong>Insert elements in the list.</li><li><strong>erase →</strong>Erase elements of the list.</li><li><strong>swap →</strong>Swap content of the list.</li><li><strong>resize →</strong>Change size of the list.</li><li><strong>clear →</strong>Clear content of the list.</li></ul><h4><strong>Operations</strong>:</h4><ul><li><strong>splice →</strong>Transfer elements from list to list .</li><li><strong>remove →</strong>Remove elements with specific value .</li><li><strong>remove_if →</strong>Remove elements fulfilling condition .</li><li><strong>unique →</strong>Remove duplicate values from the list.</li><li><strong>merge →</strong>Merge sorted lists .</li><li><strong>sort →</strong>Sort elements in container .</li><li><strong>reverse →</strong>Reverse the order of elements .</li></ul><h3>That’s all…..</h3><p>That’s all, I hope you have learnt a lot linked list and I would suggest to try whatever you have learnt do try to code everything from scratch for a better understanding if you feel like that you are comfortable then you can shift to code entirely using STL otherwise you wouldn’t be able to understand what’s happening under the hood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i7Do8npnikyDkWdZ" /><figcaption>Photo by <a href="https://unsplash.com/@nitram509?utm_source=medium&amp;utm_medium=referral">Martin W. Kirst</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Go get you hands dirty by code it up and try something new, try to code in your own style. <br>Have Fun, Keep coding and Happy Programming : — )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=687d0945cb0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/all-about-linked-lists-in-c-687d0945cb0">All about Linked Lists in C++</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vectors in C++: A beginner’s guide]]></title>
            <link>https://medium.com/analytics-vidhya/vectors-in-c-a-beginners-guide-51ec40e641c3?source=rss-16a27ebc7b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/51ec40e641c3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[vector]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Aman Kumar Goyal]]></dc:creator>
            <pubDate>Mon, 25 May 2020 17:26:55 GMT</pubDate>
            <atom:updated>2021-08-07T13:18:15.743Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vectors in C++ STL : A beginner’s guide</h3><p>Hey folks, In this blog I am going to introduce you to vectors and its basic functionalities and capabilities of a vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/0*Kt4RmX782Jem-dKo" /></figure><p>You might be working with arrays and vectors are no different than that but they comes with additional features, capabilities and many powerful inbuilt functions and methods.</p><p>Vectors are dynamic arrays which can change their size dynamically at runtime. Continuous space is allocated which makes it easier to iterate over the vector and it takes linear time to insert or remove element at position other than that of end point, it takes constant time to insert or remove element from the last position. Generally elements are inserted at the end.</p><p>Compared to the other dynamic sequence containers, vectors are very efficient accessing its elements and relatively efficient adding or removing elements from its end. For operations that involve inserting or removing elements at positions other than the end, they perform worse than the others.</p><h3>Getting Started</h3><ul><li>To use vectors you have to first include the vector library:</li></ul><pre><strong>#include&lt;vector&gt;</strong></pre><ul><li>You can define a vector of any type you want whether it be an integer vector or float type, char type, a vector of strings, or it can also be a vector of pairs or a vector of vectors</li></ul><pre><strong>vector&lt;int&gt; v;    //vector of integers<br>vector&lt;float&gt; v;  //vector of floating point numbers<br>vector&lt;char&gt; v;   //vector of characters<br>vector&lt;string&gt; v; //vector of string<br>vector&lt; pair&lt;int, int&gt; &gt; v; //vector of pairs of integers<br>vector&lt; vector&lt;int&gt; &gt; v;    //vector of vectors</strong></pre><ul><li>You can even specify the size of your vector beforehand.</li></ul><pre><strong>vector&lt;int &gt; v(n); </strong></pre><ul><li>To insert elements in vector we generally use the inbuilt push_back method.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9aowmJDzhBlOn0-n.png" /></figure><pre><strong>for(i=0; i&lt;n; i++){<br>    cin&gt;&gt;x;<br>    v.push_back(x);<br>}</strong></pre><ul><li>You can iterate over the vector just like array which makes it really easier to work with, also you can refer to a particular element same as in array using indexes.</li></ul><pre><strong>for(i=0 ; i&lt;n ; i++){<br>    cout&lt;&lt;a[i]; // indexing same as array<br>}</strong></pre><ul><li>You can also use the inbuilt sort function with vectors.</li></ul><pre><strong>sort(v.begin(), v.end());</strong></pre><p>Now, we have seen that vectors are just a little bit different than array when it comes to implementation from here we will see all the inbuilt methods and functions which makes vector a much powerful data structure as compared to simple array.</p><h3>Iterators</h3><ul><li><strong>begin() </strong>→Returns an iterator pointing to the first element in the vector.</li><li><strong>end() </strong>→Returns an iterator pointing to the theoretical element that follows the last element in the vector.</li><li><strong>rbegin()</strong> (reverse beginning) →Returns a reverse iterator pointing to the last element in the vector. It moves from last to first element.</li><li><strong>rend()</strong> ( reverse end)→Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector.</li><li><strong>cbegin()</strong> →Returns a constant iterator pointing to the first element in the vector.</li><li><strong>cend()</strong> →Returns a constant iterator pointing to the theoretical element that follows the last element in the vector.</li><li><strong>crbegin()</strong> →Returns a constant reverse iterator pointing to the last element in the vector . It moves from last to first element.</li><li><strong>crend()</strong> →Returns a constant reverse iterator pointing to the theoretical element preceding the first element in the vector.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ef0d116500328b4ddc6a753d100eff4/href">https://medium.com/media/2ef0d116500328b4ddc6a753d100eff4/href</a></iframe><h3>Capacity</h3><ul><li><strong>size()</strong> → Returns the number of elements in the vector.</li><li><strong>max_size()</strong> → Returns the maximum number of elements that the vector can hold.</li><li><strong>capacity()</strong> → Returns the size of the storage space currently allocated to the vector expressed as number of elements.</li><li><strong>resize(n)</strong> → Resizes the container so that it contains ’n’ elements.</li><li><strong>empty()</strong> → Returns whether the container is empty.</li><li><strong>shrink_to_fit()</strong> → Reduces the capacity of the container to fit its size and destroys all elements beyond the capacity.</li><li><strong>reserve() </strong>→ Requests that the vector capacity be at least enough to contain n elements.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7bc618af0f4d33b9ff05563d13980ac/href">https://medium.com/media/b7bc618af0f4d33b9ff05563d13980ac/href</a></iframe><h3>Modifiers</h3><ul><li><strong>assign() </strong>→ It assigns new value to the vector elements by replacing old ones.</li><li><strong>push_back()</strong> → It push the elements into a vector from the back.</li><li><strong>pop_back() </strong>→ It is used to pop or remove elements from a vector from the back.</li><li><strong>insert()</strong> → It inserts new elements before the element at the specified position.</li><li><strong>erase()</strong> → It is used to remove elements from a container from the specified position or range.</li><li><strong>swap()</strong> → It is used to swap the contents of one vector with another vector of same type. Sizes may differ.</li><li><strong>clear()</strong> → It is used to remove all the elements of the vector container.</li><li><strong>emplace()</strong> → It extends the container by inserting new element at position.</li><li><strong>emplace_back()</strong> → It is used to insert a new element into the vector container, the new element is added to the end of the vector.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f643aff6a6a7040031d60ae6370d9640/href">https://medium.com/media/f643aff6a6a7040031d60ae6370d9640/href</a></iframe><h3>Element Access</h3><ul><li><strong>reference operator [g]</strong> → Returns a reference to the element at position ‘g’ in the vector.</li><li><strong>at(g) </strong>→ Returns a reference to the element at position ‘g’ in the vector.</li><li><strong>front()</strong> → Returns a reference to the first element in the vector.</li><li><strong>back()</strong> → Returns a reference to the last element in the vector.</li><li><strong>data()</strong> → Returns a direct pointer to the memory array used internally by the vector to store its owned elements.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d47b02360c65d80f0ec84b2734036513/href">https://medium.com/media/d47b02360c65d80f0ec84b2734036513/href</a></iframe><h3>Here comes the end….</h3><p>That’s it here comes the end of this blog and I hope you like it and you have learned some basic concepts of vector, now go and play with the concepts you have learned try to get your hands dirty by writing some code and you can read more about vector through websites like cppreference.com there are many resources out there.</p><p>Keep Learning and Happy Programming :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51ec40e641c3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/vectors-in-c-a-beginners-guide-51ec40e641c3">Vectors in C++: A beginner’s guide</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>