<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sayani Mallick</title>
    <description>The latest articles on DEV Community by Sayani Mallick (@saydroid427).</description>
    <link>https://dev.to/saydroid427</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F531999%2F44329fe9-6fba-4594-b892-11c2d5457c8c.png</url>
      <title>DEV Community: Sayani Mallick</title>
      <link>https://dev.to/saydroid427</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saydroid427"/>
    <language>en</language>
    <item>
      <title>Data structures and algorithms</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Wed, 10 Mar 2021 13:48:28 +0000</pubDate>
      <link>https://dev.to/saydroid427/data-structures-and-algorithms-2713</link>
      <guid>https://dev.to/saydroid427/data-structures-and-algorithms-2713</guid>
      <description>&lt;p&gt;Data structures and algorithms are a must for any coding interview.&lt;br&gt;
There is no well set road map for learning data structures and algorithms other than hard work, consistency and practice. Since this is a very vast field, therefore, only regular practice can help you become a good programmer. &lt;br&gt;
While learning data structures and algorithms, I have solved various questions and decided to compile all the codes I come across into a git repository. Everyone and anyone enthusiastic in data structures and algorithms can contribute to the repository. All you have to do is: fork, clone, create a branch , write your code and send a pull request describing the code you have written.&lt;br&gt;
Here is the link of the git repository:&lt;br&gt;
&lt;a href="https://github.com/SAY-droid427/DSAQuestions"&gt;DATA STRUCTURES AND ALGORITHMS&lt;/a&gt;&lt;br&gt;
Hope this will help learners who want to learn DSA!&lt;br&gt;
Follow me on &lt;a href="https://github.com/SAY-droid427"&gt;Github&lt;/a&gt;&lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>algorithms</category>
      <category>github</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Depth first search on Graphs</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Sat, 23 Jan 2021 18:07:39 +0000</pubDate>
      <link>https://dev.to/saydroid427/depth-first-search-on-graphs-26k</link>
      <guid>https://dev.to/saydroid427/depth-first-search-on-graphs-26k</guid>
      <description>&lt;p&gt;Depth first search on Graphs is a very basic question on graphs and is necessary to solve any graph question of graphs.&lt;br&gt;
A graph is  a data structure which is defined in terms of vertices and edges,that is, G=f(V,E).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ALGORITHM&lt;/strong&gt;&lt;br&gt;
In depth first search, we first mark all the nodes as 'unvisited'. We start from the root of the graph and mark it as visited, and then move on to its connected nodes. If the present node has any unvisited node then we move on to that node. In the absence of any unvisited node, we backtrack and move to another node. &lt;/p&gt;

&lt;p&gt;Let us implement the Explore function&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explore(i)&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;mark all nodes as unvisited&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;for all i node in graph&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;{&lt;/strong&gt;&lt;br&gt;
    &lt;strong&gt;if node unvisited&lt;/strong&gt;&lt;br&gt;
        &lt;strong&gt;mark node as visited&lt;/strong&gt;&lt;br&gt;
        &lt;strong&gt;Explore(i)&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1ElTPtDW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z44ellhycl58g7qlwaib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1ElTPtDW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z44ellhycl58g7qlwaib.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps you!&lt;/p&gt;

</description>
      <category>computerscience</category>
    </item>
    <item>
      <title>Longest common subsequence in C++</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Thu, 07 Jan 2021 17:22:11 +0000</pubDate>
      <link>https://dev.to/saydroid427/longest-common-subsequence-in-c-4h1d</link>
      <guid>https://dev.to/saydroid427/longest-common-subsequence-in-c-4h1d</guid>
      <description>&lt;p&gt;The longest common subsequence is a standard dynamic programming problem. In the longest common subsequence problem, two strings are given. The aim is to find out the length of the longest common subsequence.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;INPUT:&lt;/strong&gt;&lt;br&gt;
abcde&lt;br&gt;
abxyzd&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OUTPUT:&lt;/strong&gt;3&lt;/p&gt;

&lt;p&gt;The output of the above input will be 3 because the longest common subsequence is abd.&lt;/p&gt;

&lt;p&gt;Other examples:&lt;br&gt;
&lt;strong&gt;INPUT:&lt;/strong&gt;&lt;br&gt;
axyz&lt;br&gt;
ghjk&lt;br&gt;
&lt;strong&gt;OUTPUT:&lt;/strong&gt;0&lt;br&gt;
There is no common subsequence at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INPUT:&lt;/strong&gt;&lt;br&gt;
a&lt;br&gt;
abcdefghijklmno&lt;br&gt;
&lt;strong&gt;OUTPUT:&lt;/strong&gt;1&lt;br&gt;
The longest common subsequence is a&lt;/p&gt;

&lt;p&gt;Using the dynamic programming concept, we form a two dimensional array &lt;br&gt;
t[length_of_first_string+1][length_of_second_string+1].&lt;br&gt;
We then initialize the two dimensional array as:If the length of the first string or second string is zero, then the common subsequence length will also be zero.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CODE:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JeZpDl7v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x782rpde31bhj9kaxmkx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JeZpDl7v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x782rpde31bhj9kaxmkx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps you! Do follow me on &lt;a href="https://www.github.com/say-droid427"&gt;Github&lt;/a&gt;!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fractional knapsack using C++</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Wed, 06 Jan 2021 16:53:49 +0000</pubDate>
      <link>https://dev.to/saydroid427/fractional-knapsack-using-c-2c2n</link>
      <guid>https://dev.to/saydroid427/fractional-knapsack-using-c-2c2n</guid>
      <description>&lt;p&gt;Fractional knapsack problem is a famous problem in greedy algorithms. The problem statement tells that a knapsack is given which has a weight W. You are given a list of weights and values of different items. The expected output is to output the maximum value of items that can be packed inside the knapsack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ALGORITHM&lt;/strong&gt;&lt;br&gt;
1.We find the value per unit weight for each item&lt;br&gt;
2.Next, we find the item with the maximum value per unit weight and check if the weight of that item is less or equal to the resultant weight of the knapsack then we include that item completely. Then we update the resultant weight of the knapsack.&lt;br&gt;
3.If the weight of the item is less than that of the knapsack but the weight of the knapsack is not zero, then we include that amount of the item which fits into the knapsack.&lt;br&gt;
4.If the sum of weights of all the items is less than the weight of the knapsack, then the output will be the sum of the values of each item.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CODE&lt;/strong&gt;&lt;br&gt;
The code snippet is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PWP9frEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sj0r5me7rknipaxt8jn8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PWP9frEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sj0r5me7rknipaxt8jn8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps you! If you liked the article do follow me on &lt;a href="https://github.com/SAY-droid427"&gt;Github&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>codenewbie</category>
      <category>computerscience</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Converting a sorted array into a binary search tree in C++</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Wed, 06 Jan 2021 16:08:28 +0000</pubDate>
      <link>https://dev.to/saydroid427/converting-a-sorted-array-into-a-binary-search-tree-in-c-2odg</link>
      <guid>https://dev.to/saydroid427/converting-a-sorted-array-into-a-binary-search-tree-in-c-2odg</guid>
      <description>&lt;p&gt;Let us see how to convert a sorted array into a  binary search tree. Before that let us see what is a binary search tree.&lt;/p&gt;

&lt;p&gt;What is a binary search tree?&lt;/p&gt;

&lt;p&gt;A binary search tree is a node based data structure which has the following properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The left sub-tree of a node contains elements lesser than that of the node&lt;/li&gt;
&lt;li&gt;The right sub-tree of a node contains elements greater than that of the node&lt;/li&gt;
&lt;li&gt;There are no duplicated values in the binary search tree.&lt;/li&gt;
&lt;li&gt;Each of the left sub-tree and right sub-tree follow the rules 1 and 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To create a binary search tree from a sorted array we first find the middle element and create the root. Then we use a recursive function to form the left and right sub-trees.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br&gt;
The code snippet for creating a node:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IQ_mClUL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cmzu1brbibagul0a8j6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IQ_mClUL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cmzu1brbibagul0a8j6z.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function for converting array to binary search tree:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vqFH4iAL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/elkbglm0th194747tu20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vqFH4iAL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/elkbglm0th194747tu20.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function for preorder traversal and printing of the binary search tree:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wSqaLLj2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rxyrazeqg2dqyd1gnrk4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wSqaLLj2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rxyrazeqg2dqyd1gnrk4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps you! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dynamic Programming Question: 0-1 Knapsack problem</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Sun, 03 Jan 2021 10:24:23 +0000</pubDate>
      <link>https://dev.to/saydroid427/dynamic-programming-question-0-1-knapsack-problem-2p8e</link>
      <guid>https://dev.to/saydroid427/dynamic-programming-question-0-1-knapsack-problem-2p8e</guid>
      <description>&lt;p&gt;0-1 Knapsack problem is a very classic example of dynamic programming. &lt;br&gt;
PROBLEM STATEMENT:Given an array of items with their quantity and their values, determine the maximum value of the items that can fit into the bag with a capacity of W.&lt;/p&gt;

&lt;p&gt;SOLUTION:&lt;br&gt;
An important thing to keep in mind about such question is that here we cannot take the fraction of any item, it is either whole or nothing at all.&lt;br&gt;
This question can be solved with the help of dynamic programming. In fact, this question is a classic question of dynamic programming.&lt;br&gt;
ALGORITHM:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We have been given a list of items with their value and weights. &lt;/li&gt;
&lt;li&gt;Here we use the concept of dynamic programming, that is, we store the results of the previous calculations in an array and using those results for further calculations.
3.We start our calculations from the nth item. Here we check whether the weight of the nth item is less than the weight of the knapsack.If the weight of the knapsack is greater than the weight of the item , then we have two options, we can either include that item or we can exclude that item from our chosen ones. As we have been asked to store the maximum, therefore, we choose the maximum of the two.&lt;/li&gt;
&lt;li&gt;If the weight of the knapsack is less than the weight of the item there is no way we can include that item.&lt;/li&gt;
&lt;li&gt;We continue this process from the nth item to the 1st item.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CODE&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hU37eCrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0v2xr46wpolsc3uc6r43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hU37eCrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0v2xr46wpolsc3uc6r43.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this post helps you in becoming a better competitive programmer. Follow my &lt;a href="https://github.com/SAY-droid427"&gt;Github&lt;/a&gt; for more competitive programming questions &lt;/p&gt;

</description>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Solving Balanced Parenthesis Problem</title>
      <dc:creator>Sayani Mallick</dc:creator>
      <pubDate>Sun, 03 Jan 2021 09:56:50 +0000</pubDate>
      <link>https://dev.to/saydroid427/solving-balanced-parenthesis-problem-5827</link>
      <guid>https://dev.to/saydroid427/solving-balanced-parenthesis-problem-5827</guid>
      <description>&lt;p&gt;A famous interview question on stacks is to solve the balanced parenthesis problem. In this question, the input consists of a series of parenthesis and other characters and the expected output is to print "Balanced" if the bracket sequence is balanced otherwise "Unbalanced".&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;strong&gt;INPUT&lt;/strong&gt;: []{}{}{}[]&lt;br&gt;
&lt;strong&gt;OUTPUT&lt;/strong&gt;:Balanced&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INPUT&lt;/strong&gt;: [{}]{}&lt;br&gt;
&lt;strong&gt;OUTPUT&lt;/strong&gt;:Balanced&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ALGORITHM&lt;/strong&gt;&lt;br&gt;
To solve this problem, we scan through the elements of the string one by one. If the character under consideration is an opening parenthesis "([{", then we push it to the stack.&lt;br&gt;
If the character is a closing parenthesis, then we check whether the stack is empty or not. If the stack is empty, then it means the brackets are unbalanced. However if the stack is not empty, then we check whether the top element on the stack is the corresponding opening parenthesis or not, that is,( for ), { for }, [ for ]. If it is then we continue scanning, else the sequence is unbalanced.&lt;br&gt;
But the algorithm does not end here.&lt;br&gt;
After the entire string has been scanned, we check again whether the stack is empty. If the stack is empty and the previous scanning results(the algorithm followed above) also show that the string is balanced, then we print that the sequence is Balanced.&lt;br&gt;
However if the stack is not empty, then it means that there is some parenthesis whose match has not been found yet, and the sequence is, hence , unbalanced.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wu-SI6cF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2z5bw195skorsm67krt3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wu-SI6cF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2z5bw195skorsm67krt3.png" alt="stack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y3tbSe58--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sqw1d8kl5feg9q8t3jbx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y3tbSe58--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sqw1d8kl5feg9q8t3jbx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps you!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>codenewbie</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
