<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Algorithms on Salman's Blog</title><link>https://salmanfs.ca/tags/algorithms/</link><description>Recent content in Algorithms on Salman's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 04 May 2026 06:50:17 +0000</lastBuildDate><atom:link href="https://salmanfs.ca/tags/algorithms/index.xml" rel="self" type="application/rss+xml"/><item><title>Knapsack Problem</title><link>https://salmanfs.ca/posts/knapsack-problem/</link><pubDate>Mon, 04 May 2026 06:50:17 +0000</pubDate><guid>https://salmanfs.ca/posts/knapsack-problem/</guid><description>&lt;p&gt;0/1 Knapsack Problem: Given weights and profits of n items, maximize the profit without exceeding knapsack capacity. Each item can only be chosen at most once.&lt;/p&gt;
&lt;h2 id="problem-statment"&gt;Problem statment&lt;/h2&gt;
&lt;p&gt;You are given a list of items, each with a weight and a profit, along with a backpack with a specified maximum capacity. Your goal is to calculate the maximum profit you can achieve without exceeding the backpack&amp;rsquo;s capacity. You must select items such that the total weight of the items is less than or equal to the backpack&amp;rsquo;s capacity. You can select at most one of each item.&lt;/p&gt;</description></item><item><title>Longest Increasing Subsequence</title><link>https://salmanfs.ca/posts/longest-increasing-subsequence/</link><pubDate>Sat, 20 Dec 2025 06:50:17 +0000</pubDate><guid>https://salmanfs.ca/posts/longest-increasing-subsequence/</guid><description>&lt;h2 id="problem-statement"&gt;Problem statement&lt;/h2&gt;
&lt;p&gt;Given a list of strings, return the length of the longest [lexicographically] increasing subsequence (LIS).
A &lt;strong&gt;subsequence&lt;/strong&gt; is a a sequence derived from the original by deleting zero or more elements without changing the relative order of the remaining items.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[&amp;quot;A1&amp;quot;, &amp;quot;B2&amp;quot;, &amp;quot;B1&amp;quot;, &amp;quot;C3&amp;quot;, &amp;quot;C2&amp;quot;]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Output: &lt;code&gt;3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Explanation: The longest subsequence in which each subsequent element is strictly greater (lexicographically) then the element before it is of length 3, e.g. &lt;code&gt;[&amp;quot;A1&amp;quot;, &amp;quot;B2&amp;quot;, &amp;quot;C3&amp;quot;]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;The first method is brute-force. The idea is that we generate all possible subsequences and return the legnth of the largest one.&lt;/p&gt;</description></item></channel></rss>