<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://nabin47.github.io/feed.xml" rel="self" type="application/atom+xml"/><link href="https://nabin47.github.io/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-04-14T18:35:56+00:00</updated><id>https://nabin47.github.io/feed.xml</id><title type="html">blank</title><subtitle>Personal website of Jubair Ahmed Nabin </subtitle><entry><title type="html">Travelling Salesperson HackerRank Solution with Algorithm</title><link href="https://nabin47.github.io/blog/2023/tsp-solution/" rel="alternate" type="text/html" title="Travelling Salesperson HackerRank Solution with Algorithm"/><published>2023-07-31T16:40:16+00:00</published><updated>2023-07-31T16:40:16+00:00</updated><id>https://nabin47.github.io/blog/2023/tsp-solution</id><content type="html" xml:base="https://nabin47.github.io/blog/2023/tsp-solution/"><![CDATA[<p>Travelling salesperson is a classic graph problem. Here, the cost of moving from city <code class="language-plaintext highlighter-rouge">i</code> to city <code class="language-plaintext highlighter-rouge">j</code> is given. The task is to find a path, starting from the city <code class="language-plaintext highlighter-rouge">0</code> encompassing all the cities at most once whose cost is the smallest.</p> <h2 id="problem-statement">Problem Statement:</h2> <p>Given a matrix <code class="language-plaintext highlighter-rouge">M</code> of size <code class="language-plaintext highlighter-rouge">N</code> where <code class="language-plaintext highlighter-rouge">M[i][j]</code> denotes the cost of moving from city <code class="language-plaintext highlighter-rouge">i</code> to city <code class="language-plaintext highlighter-rouge">j</code>. Your task is to complete a tour from the city <code class="language-plaintext highlighter-rouge">0</code> (0-based index) to all other cities such that you visit each city at most once and then at the end come back to the city <code class="language-plaintext highlighter-rouge">0</code> in min cost.</p> <p>Input Format</p> <p>The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N denoting the size of the matrix then in the next line are N*N space separated values of the matrix M.</p> <p>Constraints</p> <p><code class="language-plaintext highlighter-rouge">1&lt;=T&lt;=15, 1&lt;=N&lt;=12, 1&lt;=M[][]&lt;10000</code></p> <p>Output Format</p> <p>For each test case print the required result denoting the min cost of the tour in a new line.</p> <p>Sample Input</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>220 111112 030 1000 50005000 0 10001000 5000 0
</code></pre></div></div> <p>Sample Output</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2233000
</code></pre></div></div> <p>Input Visualization</p> <p><img src="/assets/input-visualization-travelling-salesman.png" alt="Input visualization through graph"/></p> <h2 id="algorithm">Algorithm</h2> <ul> <li>Take the graph input into a 2D matrix.</li> <li>Initialize a visited array of <code class="language-plaintext highlighter-rouge">n</code> sizes with <code class="language-plaintext highlighter-rouge">0</code>.</li> <li>Set <code class="language-plaintext highlighter-rouge">visited[0]</code> to <code class="language-plaintext highlighter-rouge">1</code>.</li> <li>Call traverse with arr, cur node (<code class="language-plaintext highlighter-rouge">0</code>), number of nodes visited (<code class="language-plaintext highlighter-rouge">cnt = 1</code>), total cost (<code class="language-plaintext highlighter-rouge">0</code>), Since already in <code class="language-plaintext highlighter-rouge">0th</code> node so the cost of going from <code class="language-plaintext highlighter-rouge">0th</code> node to <code class="language-plaintext highlighter-rouge">0th</code> node is <code class="language-plaintext highlighter-rouge">0</code>.</li> <li>Check if <code class="language-plaintext highlighter-rouge">cnt == n</code>. If true then we have visited all the nodes. Put the minimum of ans and ( total + cost of going from the current node to node 0) into <code class="language-plaintext highlighter-rouge">ans</code>. Then return.</li> <li>Iterate through all the nodes.</li> <li>If the <code class="language-plaintext highlighter-rouge">ith</code> node is not visited and it’s a valid node make <code class="language-plaintext highlighter-rouge">visited[cur]=1</code>. Call traverse by making ith node equal to <code class="language-plaintext highlighter-rouge">cur</code>, <code class="language-plaintext highlighter-rouge">cnt+1</code> and total+cost from cur to <code class="language-plaintext highlighter-rouge">ith</code> node (<code class="language-plaintext highlighter-rouge">arr[cur][i]</code>).</li> </ul> <h2 id="c-implementation">C++ Implementation</h2> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;climits&gt;
using namespace std;

int ans = INT_MAX, n;

bool valid(int i) {
  return i &gt;= 0 &amp;&amp; i &lt; n;
}

void traverse(vector&lt;vector&lt;int&gt; &gt;&amp; arr, int cur, vector&lt;int&gt; visited, int cnt, int total) {
  // all nodes are visited
  if(cnt == n) {
    ans = min(ans, total + arr[cur][0]); // add the distance from last node to the 0th node
    return;
  }
  
  // explore all the paths that are not yet visited
  for(int i = 0; i &lt; n; i++) {
    if(!visited[i] &amp;&amp; valid(i)) {
      visited[i] = 1;
      traverse(arr, i, visited, cnt+1, total+arr[cur][i]);
      visited[i] = 0; // so that this node can be used in another sequence to check if min cost can be obtained
    }
  }
}

int main() {
  int t;
  cin&gt;&gt;t;
  
  while(t--) {
    cin&gt;&gt;n;
    vector&lt;vector&lt;int&gt; &gt; arr(n, vector&lt;int&gt;(n));
    vector&lt;int&gt; visited(n, 0);
    ans = INT_MAX;
    
    // take the graph input
    for(int i = 0; i &lt; n; i++) {
      for(int j = 0; j &lt; n; j++) {
        cin&gt;&gt;arr[i][j];
      }
    }
    
    visited[0] = 1;
    // check all possible path to find the min cost path
    traverse(arr, 0, visited, 1, 0); 
    
    cout&lt;&lt;ans&lt;&lt;endl;
  }
  return 0;
}
</code></pre></div></div> <p><strong>Problem link:</strong> <a href="https://www.hackerrank.com/contests/target-samsung-13-nov19/challenges/travelling-salesman-4">Travelling Salesman - Target Samsung 13 Nov’19</a> ——</p>]]></content><author><name></name></author><category term="sample-posts"/><category term="formatting"/><category term="links"/><summary type="html"><![CDATA[Travelling salesperson is a classic graph problem. Here, the cost of moving from city i to city j is given. The task is to find a path, starting from the city 0 encompassing all the cities at most once whose cost is the smallest.]]></summary></entry><entry><title type="html">How-Tos of Installing and Mounting a FUSE-based Filesystem</title><link href="https://nabin47.github.io/blog/2023/fuse-filesystem-installation-process/" rel="alternate" type="text/html" title="How-Tos of Installing and Mounting a FUSE-based Filesystem"/><published>2023-07-20T16:40:16+00:00</published><updated>2023-07-20T16:40:16+00:00</updated><id>https://nabin47.github.io/blog/2023/fuse-filesystem-installation-process</id><content type="html" xml:base="https://nabin47.github.io/blog/2023/fuse-filesystem-installation-process/"><![CDATA[<h2 id="what-exactly-is-fuse">What exactly is FUSE?</h2> <p>Before we get any further let’s clear up one thing FUSE is not the fuse that interrupts the circuit when the current becomes too strong. Now that the pun is out of the way let’s get started.</p> <p>FUSE or Filesystem in Userspace is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code<sup>1</sup>.</p> <p>Allowing secure, non-privileged mounts is one of FUSE’s most significant features. This broadens the scope of filesystem applications. Sshfs<sup>2</sup>, a secure network filesystem that uses the sftp protocol, is an excellent example.</p> <h2 id="premise">Premise</h2> <p>This article assumes you already have a filesystem written in Python. Now the next step is to mount it in your system (assuming it’s Unix-like OS). For Windows refer to <a href="https://github.com/winfsp/winfsp">WinFsp</a>. The article was written using Ubuntu 22.04.</p> <h2 id="installing-dependencies">Installing dependencies</h2> <p>To run a FUSE-based filesystem, first, we need to install the FUSE and fusepy modules. The corresponding steps and commands are as follows:</p> <ol> <li>Install FUSE: You can install FUSE module on Ubuntu using the following command:</li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>fuse
</code></pre></div></div> <ol> <li>Install fusepy: You can install fusepy using pip, the package manager for Python. If pip is not installed, you can install it using the following command:</li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>python3-pip
</code></pre></div></div> <ol> <li>Once you have pip installed, you can install fusepy by running the following command:</li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pip3 <span class="nb">install </span>fusepy
</code></pre></div></div> <h2 id="mounting-the-file-system">Mounting the file-system</h2> <p>Now that we have installed the dependencies why not mount the filesystem to see what it does! Suppose you have the codes for the filesystem saved in a Python file with a <code class="language-plaintext highlighter-rouge">.py</code> extension, for example, <code class="language-plaintext highlighter-rouge">examplefs.py</code>.</p> <ol> <li>Run the code: To run the code, open a terminal and navigate to the directory where you saved the code and run the following command:</li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python3 entropyfs.py &lt;mountpoint&gt;
</code></pre></div></div> <ol> <li> <p>Replace <code class="language-plaintext highlighter-rouge">&lt;mountpoint&gt;</code> with the directory where you want to mount the file system. This directory must exist before you run the command.</p> </li> <li> <p>For example, if you want to mount the file system to the <code class="language-plaintext highlighter-rouge">~/testfs</code> directory, run the following command:</p> </li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python3 entropyfs.py ~/testfs
</code></pre></div></div> <ol> <li> <p>The file system is now mounted, and you can interact with it as you would any other file system.</p> </li> <li> <p>To see the list of all mounted filesystems run the following command</p> </li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mount
</code></pre></div></div> <h2 id="unmount-the-filesystem">Unmount the filesystem</h2> <p>To unmount the file system, you can use the <code class="language-plaintext highlighter-rouge">umount</code> command in the terminal.</p> <ol> <li>First, you need to navigate to the directory where you mounted the file system. For example, if you mounted the file system to <code class="language-plaintext highlighter-rouge">~/testfs</code>, you can navigate to it using the following command:</li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/testfs
</code></pre></div></div> <ol> <li>Then, to unmount the file system, run the following command:</li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>umount &lt;mountpoint&gt;
</code></pre></div></div> <ol> <li> <p>Replace <code class="language-plaintext highlighter-rouge">&lt;mountpoint&gt;</code> with the directory where you mounted the file system. In this example, it would be <code class="language-plaintext highlighter-rouge">~/testfs</code>.</p> </li> <li> <p>For example, the command to unmount the file system mounted at <code class="language-plaintext highlighter-rouge">~/testfs</code> would be:</p> </li> </ol> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>umount ~/entropyfs
</code></pre></div></div> <p>After running this command, the file system will be unmounted and you can no longer access it.</p>]]></content><author><name></name></author><category term="sample-posts"/><category term="formatting"/><category term="links"/><summary type="html"><![CDATA[What exactly is FUSE?]]></summary></entry></feed>