<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Dsa on mahroot's blog</title><link>https://mahroot.dev/tags/dsa/</link><description>Recent content in Dsa on mahroot's blog</description><generator>Hugo</generator><language>en-us</language><copyright>&lt;a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener"&gt;CC BY-NC 4.0&lt;/a&gt;</copyright><lastBuildDate>Tue, 13 Jan 2026 19:37:47 +0100</lastBuildDate><atom:link href="https://mahroot.dev/tags/dsa/index.xml" rel="self" type="application/rss+xml"/><item><title>Crafting My Own Storage Engine-Part 01: Java I/O Fundamentals</title><link>https://mahroot.dev/posts/crafting-my-own-storage-engine-part-01--java-io-fundamentals/</link><pubDate>Tue, 13 Jan 2026 19:37:47 +0100</pubDate><guid>https://mahroot.dev/posts/crafting-my-own-storage-engine-part-01--java-io-fundamentals/</guid><description>&lt;h1 id="the-page-abstraction"&gt;The &amp;ldquo;Page&amp;rdquo; Abstraction&lt;/h1&gt;
&lt;p&gt;so the &lt;code&gt;ByteBuffer&lt;/code&gt; acts like a staging area where we serialize our Java objects (the &lt;code&gt;Page&lt;/code&gt; object) into raw bytes and keep them in RAM using methods like &lt;code&gt;putInt&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;and after that, we need to persist the data to disk — meaning we write those bytes into a file so the data survives after the program stops&lt;/p&gt;
&lt;p&gt;so we have one large file, and since all pages have a fixed size, if we want to write the data for &lt;code&gt;pageId = 14&lt;/code&gt;, we simply compute the offset &lt;code&gt;4096 * 14&lt;/code&gt; and write the buffer at that position using the &lt;code&gt;write&lt;/code&gt; method&lt;/p&gt;</description></item><item><title>Contains Duplicate (LeetCode 217)</title><link>https://mahroot.dev/ilt/2025/12/11/contains-duplicate-leetcode-217/</link><pubDate>Thu, 11 Dec 2025 00:42:08 +0100</pubDate><guid>https://mahroot.dev/ilt/2025/12/11/contains-duplicate-leetcode-217/</guid><description>&lt;h1 id="contains-duplicate-leetcode-217"&gt;Contains Duplicate (LeetCode 217)&lt;/h1&gt;
&lt;p&gt;the link of the problem &lt;a href="https://leetcode.com/problems/contains-duplicate/description/"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Given an integer array &lt;code&gt;nums&lt;/code&gt;, return &lt;code&gt;true&lt;/code&gt; if any value appears &lt;strong&gt;at least twice&lt;/strong&gt; in the array, and return &lt;code&gt;false&lt;/code&gt; if every element is distinct.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;
&lt;strong&gt;Input:&lt;/strong&gt; nums = [1,2,3,1]
&lt;strong&gt;Output:&lt;/strong&gt; true
&lt;strong&gt;Explanation:&lt;/strong&gt;
The element 1 occurs at the indices 0 and 3.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;
&lt;strong&gt;Input:&lt;/strong&gt; nums = [1,2,3,4]
&lt;strong&gt;Output:&lt;/strong&gt; false
&lt;strong&gt;Explanation:&lt;/strong&gt;
All elements are distinct.
&lt;strong&gt;Example 3:&lt;/strong&gt;
&lt;strong&gt;Input:&lt;/strong&gt; nums = [1,1,1,3,3,4,3,2,4,2]
&lt;strong&gt;Output:&lt;/strong&gt; true&lt;/p&gt;</description></item><item><title>Collection Interface</title><link>https://mahroot.dev/posts/collection-interface/</link><pubDate>Tue, 14 Oct 2025 01:15:28 +0200</pubDate><guid>https://mahroot.dev/posts/collection-interface/</guid><description>&lt;p&gt;the collection interface extends Iterable interface from java.lang
we have a method
&lt;strong&gt;boolean add(E e)&lt;/strong&gt; that return true if the collection changed (the elem e added) and false if not
&lt;strong&gt;boolean addAdd(Collection &amp;lt; ? extends E&amp;gt; c)&lt;/strong&gt; , that take a collection of type E of subtype of E and return true if the collection changed (all elm added)&lt;/p&gt;
&lt;p&gt;So if you have a &lt;code&gt;Collection&amp;lt;Animal&amp;gt;&lt;/code&gt; and another &lt;code&gt;Collection&amp;lt;Dog&amp;gt;&lt;/code&gt;,&lt;br&gt;
you can add the &lt;code&gt;Dog&lt;/code&gt;s into the &lt;code&gt;Animal&lt;/code&gt; collection because &lt;code&gt;Dog&lt;/code&gt; &lt;strong&gt;extends&lt;/strong&gt; &lt;code&gt;Animal&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Create My Own JCF-week1</title><link>https://mahroot.dev/posts/create-my-own-jcf-week1/</link><pubDate>Sat, 11 Oct 2025 00:59:35 +0200</pubDate><guid>https://mahroot.dev/posts/create-my-own-jcf-week1/</guid><description>&lt;h3 id="jcf-java-collection-framework-hierarchy"&gt;JCF: Java Collection Framework Hierarchy&lt;/h3&gt;
&lt;p&gt;&lt;img src="https://mahroot.dev/images/Pasted%20image%2020251014010626.png" alt="Pasted image 20251014010626"&gt;&lt;/p&gt;
&lt;p&gt;_Bfore starting implementing JCF should you know the Iterable&lt;E&gt; interface&lt;/p&gt;
&lt;h1 id="1-iterable"&gt;1. Iterable&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Iterable interface is a builtin interface in java it allow us using &amp;ldquo;for-each&amp;rdquo; loop thanks to Iterator method&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;let&amp;rsquo;s take an example
if you work with arrays in java and suppose you create an new array&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt;&lt;span style="color:#f92672"&gt;[]&lt;/span&gt; arr &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; Interger&lt;span style="color:#f92672"&gt;[]&lt;/span&gt;{1,2,3}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and you want to make the forEach loop like this &lt;code&gt;for(int n : arr)&lt;/code&gt; =&amp;gt; this will give you a compiler error&lt;/p&gt;</description></item><item><title>Doubly Linked Lists</title><link>https://mahroot.dev/ilt/2025/09/08/doubly-linked-lists/</link><pubDate>Mon, 08 Sep 2025 23:23:40 +0200</pubDate><guid>https://mahroot.dev/ilt/2025/09/08/doubly-linked-lists/</guid><description>&lt;p&gt;In this blog we&amp;rsquo;ll see how we can implementing a doubly linked list
if you haven’t seen the Singly Linked List yet it&amp;rsquo;s better to check it &lt;a href="https://ayoubmah.github.io/ilt/2025/08/12/singly-linked-list/"&gt;here&lt;/a&gt; first, because the concept is almost the same with just a few changes.&lt;/p&gt;
&lt;p&gt;the main difference is in the node itself
this time a node referenced by the &lt;strong&gt;next&lt;/strong&gt; node and the &lt;strong&gt;prev&lt;/strong&gt; node
as you can see in this image&lt;/p&gt;
&lt;p&gt;&lt;img src="https://mahroot.dev/images/dob.jpeg" alt="dob"&gt;&lt;/p&gt;
&lt;p&gt;let&amp;rsquo;s implemented in java&lt;/p&gt;</description></item><item><title>Leet-Code-Day001</title><link>https://mahroot.dev/ilt/2025/09/04/leet-code-day001/</link><pubDate>Thu, 04 Sep 2025 23:34:00 +0200</pubDate><guid>https://mahroot.dev/ilt/2025/09/04/leet-code-day001/</guid><description>&lt;p&gt;you can see the problem here
&lt;a href="https://leetcode.com/problems/merge-two-sorted-lists/"&gt;Merge Two Sorted Lists&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The idea is that we have &lt;strong&gt;two sorted singly linked lists&lt;/strong&gt;
and we want &lt;strong&gt;a single merged linked list containing all the elements from the two original lists in sorted order&lt;/strong&gt; like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://mahroot.dev/images/WhatsApp%20Image%202025-09-04%20at%2011.50.26%20PM.jpeg" alt="WhatsApp Image 2025-09-04 at 11.50.26 PM"&gt;&lt;/p&gt;
&lt;p&gt;before looking at the steps of the solution, let&amp;rsquo;s see the implementation of the singly linked list with int value (you can see the generic version here &lt;a href="https://ayoubmah.github.io/ilt/2025/08/12/singly-linked-list/"&gt;Singularly Linked List&lt;/a&gt; )&lt;/p&gt;</description></item><item><title>Circularly Linked List</title><link>https://mahroot.dev/ilt/2025/09/04/circularly-linked-list/</link><pubDate>Thu, 04 Sep 2025 00:02:05 +0200</pubDate><guid>https://mahroot.dev/ilt/2025/09/04/circularly-linked-list/</guid><description>&lt;p&gt;Before to read about circularly linked lists i suggest to go to read bit about &lt;a href="https://ayoubmah.github.io/ilt/2025/08/12/singly-linked-list/"&gt;Singly Linked List&lt;/a&gt;, to better understanding circularly linked lists(CLL)&lt;/p&gt;
&lt;p&gt;so basically a CLL is a Singly linked list and instead of the its tail (last node of the list) point on null its point of the first element of the list (head). like this&lt;/p&gt;
&lt;p&gt;&lt;img src="https://mahroot.dev/images/Pasted%20image%2020250904001212.png" alt="Pasted image 20250904001212"&gt;&lt;/p&gt;</description></item><item><title>Singly Linked List</title><link>https://mahroot.dev/ilt/2025/08/12/singly-linked-list/</link><pubDate>Tue, 12 Aug 2025 00:00:00 +0000</pubDate><guid>https://mahroot.dev/ilt/2025/08/12/singly-linked-list/</guid><description>&lt;p&gt;Before you read this if you want a deep dive on Singly LinkedList and DSA with java in general please read the &amp;ldquo;Chapter 3. Fundamental Data Structures&amp;rdquo; p.122 by MICHEAL T.GOODRICH&lt;/p&gt;
&lt;h1 id="1-node"&gt;1. Node&lt;/h1&gt;
&lt;p&gt;First let&amp;rsquo;s define a node, so a node it&amp;rsquo;s a data structure that can store an object and point to another node&lt;/p&gt;
&lt;p&gt;like this
&lt;img src="https://mahroot.dev/images/Pasted%20image%2020250812133629.png" alt="Pasted image 20250812133629"&gt;&lt;/p&gt;
&lt;p&gt;we can define it in java like&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;class&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Node&lt;/span&gt;&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;private&lt;/span&gt; E data;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;private&lt;/span&gt; Node&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; next;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Node&lt;/span&gt;(E data){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;this&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;data&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; data;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;this&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;next&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;null&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; E &lt;span style="color:#a6e22e"&gt;getData&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; data;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;setData&lt;/span&gt;(E data) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;this&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;data&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; data;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; Node&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;getNext&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; next;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;setNext&lt;/span&gt;(Node&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; next) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;this&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;next&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; next;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; String &lt;span style="color:#a6e22e"&gt;toString&lt;/span&gt;(){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;(&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;+&lt;/span&gt;data&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;) =&amp;gt;(null)&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see in the code, the constructor of the Node initializes the next pointer to null, which is what we want.&lt;/p&gt;</description></item></channel></rss>