{"id":2807,"date":"2025-03-11T13:42:22","date_gmt":"2025-03-11T13:42:22","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=2807"},"modified":"2025-03-14T16:20:10","modified_gmt":"2025-03-14T16:20:10","slug":"dsa-tuotiral","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/dsa\/dsa-tuotiral\/","title":{"rendered":"DSA Tuotiral"},"content":{"rendered":"\n<p>Got it! Here&#8217;s the updated <strong>8-hour JavaScript DSA training plan<\/strong> with examples <strong>without using inbuilt functions<\/strong> like <code>.push()<\/code>, <code>.pop()<\/code>, <code>.shift()<\/code>, <code>.split()<\/code>, etc.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2>\ud83d\ude80 <strong>8-Hour JavaScript DSA Training Plan (Without Inbuilt Functions)<\/strong><\/h2>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 1: Introduction to DSA &amp; Complexity Analysis<\/strong><\/h3>\n\n\n\n<ul><li><strong>Topics:<\/strong><ul><li>What is DSA?<\/li><li>Time and Space Complexity (Big O Notation)<\/li><\/ul><\/li><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<ol><li><strong>Constant Time &#8211; O(1)O(1)<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function getFirstElement(arr) {\n    return arr[0];\n}\n<\/pre>\n\n\n\n<ol start=\"2\"><li><strong>Linear Time &#8211; O(n)O(n)<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function findMax(arr) {\n    var max = arr[0];\n    for (var i = 1; i &lt; arr.length; i++) {\n        if (arr[i] > max) {\n            max = arr[i];\n        }\n    }\n    return max;\n}\n<\/pre>\n\n\n\n<p>3. Find second highest<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;1, 2, 3, 4, 5, 6, 7]\n\nmax = -Infinity\nsecond_highest = -Infinity\n\nfor(let i = 0; i &lt; nums.length; i++){\n    if(nums&#91;i] &gt; max) {\n        second_highest = max\n        max = nums&#91;i]\n    } else if(nums&#91;i] &gt; second_highest &amp;&amp; nums&#91;i] !== max)\n        second_highest = nums&#91;i]\n\n}\n\nconsole.log(\"Maximum: \", max);\nconsole.log(\"Second Highest: \", second_highest);<\/code><\/pre>\n\n\n\n<p>4. Sort array using bubble sort<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function bubbleSort(arr) {\n    let n = arr.length;\n\n    for (let i = 0; i &lt; n - 1; i++) {\n        \/\/ Last i elements are already sorted, so no need to check them\n        for (let j = 0; j &lt; n - i - 1; j++) {\n            if (arr&#91;j] &gt; arr&#91;j + 1]) {\n                \/\/ Swap the elements\n                let temp = arr&#91;j];\n                arr&#91;j] = arr&#91;j + 1];\n                arr&#91;j + 1] = temp;\n            }\n        }\n    }\n\n    return arr;\n}\n\n\/\/ Example usage\nconst nums = &#91;5, 2, 9, 1, 5, 6];\nconsole.log(bubbleSort(nums)); \/\/ Output: &#91;1, 2, 5, 5, 6, 9]<\/code><\/pre>\n\n\n\n<p>5. Unique Array &#8211; O(n2)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uniq = &#91;]\nfor(let i = 0; i &lt; nums.length; i++) {\n    let in_array = true\n    for(let j = 0; j &lt; uniq.length; j++) {\n        if(nums&#91;i] === uniq&#91;j]) {\n            in_array = false\n            break\n        }\n    }\n    \n    if(in_array)\n        uniq&#91;uniq.length] = nums&#91;i]\n}\n\nconsole.log(\"Unique Array: \", uniq);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 2: Arrays and Strings<\/strong><\/h3>\n\n\n\n<ul><li><strong>Topics:<\/strong><ul><li>Manually manipulating arrays and strings<\/li><\/ul><\/li><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<ol><li><strong>Reverse an Array<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function reverseArray(arr) {\n    var reversed = [];\n    for (var i = arr.length - 1; i >= 0; i--) {\n        reversed[reversed.length] = arr[i];\n    }\n    return reversed;\n}\nconsole.log(reverseArray([1, 2, 3, 4])); \/\/ [4, 3, 2, 1]\n<\/pre>\n\n\n\n<ol start=\"2\"><li><strong>Check if a String is a Palindrome<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function isPalindrome(str) {\n    var reversed = \"\";\n    for (var i = str.length - 1; i >= 0; i--) {\n        reversed += str[i];\n    }\n    return str === reversed;\n}\nconsole.log(isPalindrome(\"madam\")); \/\/ true\n<\/pre>\n\n\n\n<p>3. String is panagram or not<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function isPangram(sentence) {\n    \/\/ Convert the sentence to lowercase\n    sentence = sentence.toLowerCase();\n\n    \/\/ Create a set to store unique letters\n    const letters = new Set();\n\n    for (let char of sentence) {\n        \/\/ Check if the character is an alphabet letter\n        if (char &gt;= 'a' &amp;&amp; char &lt;= 'z') {\n            letters.add(char);\n        }\n    }\n\n    \/\/ If the set size is 26, it's a pangram\n    return letters.size === 26;\n}\n\n\/\/ Example Usage\nconsole.log(isPangram(\"The quick brown fox jumps over the lazy dog\")); \/\/ true\nconsole.log(isPangram(\"Hello World\"));                                 \/\/ false\n<\/code><\/pre>\n\n\n\n<p>4. String is anagram or not<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function isAnagram(str1, str2) {\n    const formatStr = (str) =&gt; str.toLowerCase().replace(\/&#91;^a-z]\/g, '');\n\n    str1 = formatStr(str1);\n    str2 = formatStr(str2);\n\n    if (str1.length !== str2.length) return false;\n\n    const charCount = {};\n\n    \/\/ Count characters from str1\n    for (let char of str1) {\n        charCount&#91;char] = (charCount&#91;char] || 0) + 1;\n    }\n\n    \/\/ Reduce the count based on str2\n    for (let char of str2) {\n        if (!charCount&#91;char]) return false;\n        charCount&#91;char]--;\n    }\n\n    return true;\n}\n\n\/\/ Test cases\nconsole.log(isAnagram(\"listen\", \"silent\"));         \/\/ true\nconsole.log(isAnagram(\"hello\", \"world\"));           \/\/ false\nconsole.log(isAnagram(\"Triangle\", \"Integral\"));     \/\/ true\nconsole.log(isAnagram(\"Dormitory\", \"dirty room\"));  \/\/ true\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 3: Linked Lists<\/strong><\/h3>\n\n\n\n<ul><li><strong>Topics:<\/strong><ul><li>Manually implement Linked List operations<\/li><\/ul><\/li><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Node(data) {\n    this.data = data;\n    this.next = null;\n}\n\nfunction LinkedList() {\n    this.head = null;\n}\n\nLinkedList.prototype.insert = function (data) {\n    var newNode = new Node(data);\n    if (!this.head) {\n        this.head = newNode;\n        return;\n    }\n    var current = this.head;\n    while (current.next !== null) {\n        current = current.next;\n    }\n    current.next = newNode;\n};\n\nLinkedList.prototype.display = function () {\n    var current = this.head;\n    while (current !== null) {\n        console.log(current.data);\n        current = current.next;\n    }\n};\n\nvar list = new LinkedList();\nlist.insert(10);\nlist.insert(20);\nlist.display();\n<\/pre>\n\n\n\n<p>3.1. Linked List complete example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Node class to represent each element in the linked list\nclass Node {\n    constructor(value) {\n        this.value = value;\n        this.next = null;\n    }\n}\n\n\/\/ LinkedList class\nclass LinkedList {\n    constructor() {\n        this.head = null;\n        this.size = 0;\n    }\n\n    \/\/ Add element at the end of the list\n    append(value) {\n        const newNode = new Node(value);\n\n        if (!this.head) {\n            this.head = newNode;\n        } else {\n            let current = this.head;\n            while (current.next) {\n                current = current.next;\n            }\n            current.next = newNode;\n        }\n        this.size++;\n    }\n\n    \/\/ Add element at the beginning of the list\n    prepend(value) {\n        const newNode = new Node(value);\n        newNode.next = this.head;\n        this.head = newNode;\n        this.size++;\n    }\n\n    \/\/ Insert element at a specific position\n    insertAt(value, index) {\n        if (index &lt; 0 || index &gt; this.size) {\n            console.log(\"Invalid index\");\n            return;\n        }\n\n        if (index === 0) {\n            this.prepend(value);\n            return;\n        }\n\n        const newNode = new Node(value);\n        let current = this.head;\n        let previous;\n        let count = 0;\n\n        while (count &lt; index) {\n            previous = current;\n            current = current.next;\n            count++;\n        }\n\n        previous.next = newNode;\n        newNode.next = current;\n        this.size++;\n    }\n\n    \/\/ Remove element by value\n    remove(value) {\n        if (!this.head) return;\n\n        if (this.head.value === value) {\n            this.head = this.head.next;\n            this.size--;\n            return;\n        }\n\n        let current = this.head;\n        let previous = null;\n\n        while (current &amp;&amp; current.value !== value) {\n            previous = current;\n            current = current.next;\n        }\n\n        if (current) {\n            previous.next = current.next;\n            this.size--;\n        } else {\n            console.log(\"Value not found in the list.\");\n        }\n    }\n\n    \/\/ Get index of a value\n    indexOf(value) {\n        let current = this.head;\n        let index = 0;\n\n        while (current) {\n            if (current.value === value) {\n                return index;\n            }\n            current = current.next;\n            index++;\n        }\n        return -1;\n    }\n\n    \/\/ Check if the list is empty\n    isEmpty() {\n        return this.size === 0;\n    }\n\n    \/\/ Get the size of the list\n    getSize() {\n        return this.size;\n    }\n\n    \/\/ Print the list\n    print() {\n        if (this.isEmpty()) {\n            console.log(\"List is empty\");\n            return;\n        }\n\n        let current = this.head;\n        let result = \"\";\n        while (current) {\n            result += current.value + \" -&gt; \";\n            current = current.next;\n        }\n        console.log(result + \"null\");\n    }\n\n    \/\/ Clear the list\n    clear() {\n        this.head = null;\n        this.size = 0;\n    }\n}\n\n\/\/ Example Usage\nconst list = new LinkedList();\n\nlist.append(10);\nlist.append(20);\nlist.append(30);\nlist.print(); \/\/ Output: 10 -&gt; 20 -&gt; 30 -&gt; null\n\nlist.prepend(5);\nlist.print(); \/\/ Output: 5 -&gt; 10 -&gt; 20 -&gt; 30 -&gt; null\n\nlist.insertAt(15, 2);\nlist.print(); \/\/ Output: 5 -&gt; 10 -&gt; 15 -&gt; 20 -&gt; 30 -&gt; null\n\nlist.remove(20);\nlist.print(); \/\/ Output: 5 -&gt; 10 -&gt; 15 -&gt; 30 -&gt; null\n\nconsole.log(\"Index of 15:\", list.indexOf(15)); \/\/ Output: 2\n\nconsole.log(\"Size of list:\", list.getSize()); \/\/ Output: 4\n\nlist.clear();\nlist.print(); \/\/ Output: List is empty\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 4: Stacks and Queues<\/strong><\/h3>\n\n\n\n<ul><li><strong>Topics:<\/strong><ul><li>Manual stack and queue implementation<\/li><\/ul><\/li><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<ol><li><strong>Stack Implementation<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Stack() {\n    this.items = [];\n    this.top = -1;\n}\n\nStack.prototype.push = function (element) {\n    this.top++;\n    this.items[this.top] = element;\n};\n\nStack.prototype.pop = function () {\n    if (this.top &lt; 0) return null;\n    var popped = this.items[this.top];\n    this.top--;\n    return popped;\n};\n\nvar stack = new Stack();\nstack.push(10);\nstack.push(20);\nconsole.log(stack.pop()); \/\/ 20\n<\/pre>\n\n\n\n<p>1.1. Complete Stack Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Stack {\n    constructor() {\n        this.items = {};\n        this.top = 0; \/\/ To keep track of the index\n    }\n\n    \/\/ Add element to the stack\n    push(element) {\n        this.items&#91;this.top] = element;\n        this.top++;\n    }\n\n    \/\/ Remove element from the stack\n    pop() {\n        if (this.isEmpty()) {\n            return \"Stack is empty\";\n        }\n        this.top--;\n        const removedItem = this.items&#91;this.top];\n        delete this.items&#91;this.top];\n        return removedItem;\n    }\n\n    \/\/ View the top element of the stack\n    peek() {\n        if (this.isEmpty()) {\n            return \"Stack is empty\";\n        }\n        return this.items&#91;this.top - 1];\n    }\n\n    \/\/ Check if the stack is empty\n    isEmpty() {\n        return this.top === 0;\n    }\n\n    \/\/ Get the size of the stack\n    size() {\n        return this.top;\n    }\n\n    \/\/ Print all elements in the stack\n    print() {\n        let result = '';\n        for (let i = 0; i &lt; this.top; i++) {\n            result += this.items&#91;i] + ' ';\n        }\n        console.log(result.trim());\n    }\n\n    \/\/ Clear the stack\n    clear() {\n        this.items = {};\n        this.top = 0;\n    }\n}\n\n\/\/ Example Usage\nconst stack = new Stack();\n\nstack.push(10);\nstack.push(20);\nstack.push(30);\nstack.print();  \/\/ Output: 10 20 30\n\nconsole.log(stack.peek()); \/\/ Output: 30\n\nconsole.log(stack.pop());  \/\/ Output: 30\nstack.print();             \/\/ Output: 10 20\n\nconsole.log(stack.isEmpty()); \/\/ Output: false\n\nstack.clear();\nconsole.log(stack.isEmpty()); \/\/ Output: true\n<\/code><\/pre>\n\n\n\n<ol start=\"2\"><li><strong>Queue Implementation<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Queue() {\n    this.items = {};\n    this.front = 0;\n    this.rear = 0;\n}\n\nQueue.prototype.enqueue = function (element) {\n    this.items[this.rear] = element;\n    this.rear++;\n};\n\nQueue.prototype.dequeue = function () {\n    var item = this.items[this.front];\n    delete this.items[this.front];\n    this.front++;\n    return item;\n};\n\nvar queue = new Queue();\nqueue.enqueue(10);\nqueue.enqueue(20);\nconsole.log(queue.dequeue()); \/\/ 10\n<\/pre>\n\n\n\n<p>2.2. Complete Queue Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Queue {\n    constructor() {\n        this.items = {};\n        this.front = 0;\n        this.rear = 0;\n    }\n\n    \/\/ Enqueue (add) element to the queue\n    enqueue(element) {\n        this.items&#91;this.rear] = element;\n        this.rear++;\n    }\n\n    \/\/ Dequeue (remove) element from the queue\n    dequeue() {\n        if (this.isEmpty()) {\n            return \"Queue is empty\";\n        }\n        const removedItem = this.items&#91;this.front];\n        delete this.items&#91;this.front];\n        this.front++;\n        return removedItem;\n    }\n\n    \/\/ View the front element of the queue\n    peek() {\n        if (this.isEmpty()) {\n            return \"Queue is empty\";\n        }\n        return this.items&#91;this.front];\n    }\n\n    \/\/ Check if the queue is empty\n    isEmpty() {\n        return this.rear === this.front;\n    }\n\n    \/\/ Get the size of the queue\n    size() {\n        return this.rear - this.front;\n    }\n\n    \/\/ Print all elements in the queue\n    print() {\n        let result = '';\n        for (let i = this.front; i &lt; this.rear; i++) {\n            result += this.items&#91;i] + ' ';\n        }\n        console.log(result.trim());\n    }\n\n    \/\/ Clear the queue\n    clear() {\n        this.items = {};\n        this.front = 0;\n        this.rear = 0;\n    }\n}\n\n\/\/ Example Usage\nconst queue = new Queue();\n\nqueue.enqueue(10);\nqueue.enqueue(20);\nqueue.enqueue(30);\nqueue.print();  \/\/ Output: 10 20 30\n\nconsole.log(queue.peek()); \/\/ Output: 10\n\nconsole.log(queue.dequeue()); \/\/ Output: 10\nqueue.print();               \/\/ Output: 20 30\n\nconsole.log(queue.isEmpty()); \/\/ Output: false\n\nqueue.clear();\nconsole.log(queue.isEmpty()); \/\/ Output: true<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 5: Recursion<\/strong><\/h3>\n\n\n\n<ul><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<ol><li><strong>Factorial Using Recursion<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function factorial(n) {\n    if (n === 0) return 1;\n    return n * factorial(n - 1);\n}\nconsole.log(factorial(5)); \/\/ 120\n<\/pre>\n\n\n\n<ol start=\"2\"><li><strong>Fibonacci Series<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function fibonacci(n) {\n    if (n &lt;= 1) return n;\n    return fibonacci(n - 1) + fibonacci(n - 2);\n}\nconsole.log(fibonacci(6)); \/\/ 8\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 6: Searching and Sorting<\/strong><\/h3>\n\n\n\n<ul><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<ol><li><strong>Binary Search<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function binarySearch(arr, target) {\n    var left = 0, right = arr.length - 1;\n    while (left &lt;= right) {\n        var mid = Math.floor((left + right) \/ 2);\n        if (arr[mid] === target) return mid;\n        else if (arr[mid] &lt; target) left = mid + 1;\n        else right = mid - 1;\n    }\n    return -1;\n}\nconsole.log(binarySearch([1, 2, 3, 4, 5], 3)); \/\/ 2\n<\/pre>\n\n\n\n<ol start=\"2\"><li><strong>Bubble Sort<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function bubbleSort(arr) {\n    for (var i = 0; i &lt; arr.length - 1; i++) {\n        for (var j = 0; j &lt; arr.length - 1 - i; j++) {\n            if (arr[j] > arr[j + 1]) {\n                var temp = arr[j];\n                arr[j] = arr[j + 1];\n                arr[j + 1] = temp;\n            }\n        }\n    }\n    return arr;\n}\nconsole.log(bubbleSort([5, 2, 9, 1])); \/\/ [1, 2, 5, 9]\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 7: Trees and Graphs<\/strong><\/h3>\n\n\n\n<ul><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<ol><li><strong>Binary Search Tree (Insert &amp; Traverse)<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function TreeNode(val) {\n    this.val = val;\n    this.left = null;\n    this.right = null;\n}\n\nfunction insert(root, val) {\n    if (!root) return new TreeNode(val);\n    if (val &lt; root.val) root.left = insert(root.left, val);\n    else root.right = insert(root.right, val);\n    return root;\n}\n\nfunction inOrderTraversal(root) {\n    if (root) {\n        inOrderTraversal(root.left);\n        console.log(root.val);\n        inOrderTraversal(root.right);\n    }\n}\n\nvar root = null;\nroot = insert(root, 10);\nroot = insert(root, 5);\nroot = insert(root, 15);\ninOrderTraversal(root); \/\/ 5 10 15\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3><strong>Hour 8: Hashing and Final Assignment<\/strong><\/h3>\n\n\n\n<ul><li><strong>Examples:<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function HashTable(size) {\n    this.table = new Array(size);\n}\n\nHashTable.prototype.hash = function (key) {\n    var hash = 0;\n    for (var i = 0; i &lt; key.length; i++) {\n        hash += key.charCodeAt(i);\n    }\n    return hash % this.table.length;\n};\n\nHashTable.prototype.set = function (key, value) {\n    var index = this.hash(key);\n    this.table[index] = [key, value];\n};\n\nHashTable.prototype.get = function (key) {\n    var index = this.hash(key);\n    if (this.table[index] &amp;&amp; this.table[index][0] === key) {\n        return this.table[index][1];\n    }\n    return undefined;\n};\n\nvar ht = new HashTable(10);\nht.set(\"name\", \"John\");\nconsole.log(ht.get(\"name\")); \/\/ John\n<\/pre>\n\n\n\n<h2>Complete Program<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Tuple Example using Class (Simulated Tuple)\nclass Tuple {\n    constructor(...elements) {\n        this.elements = elements;\n    }\n    get(index) {\n        return this.elements[index];\n    }\n    set(index, value) {\n        this.elements[index] = value;\n    }\n}\n\nconst tuple = new Tuple(1, 'hello', true);\nconsole.log(tuple.get(0)); \/\/ Accessing element\n\ntuple.set(1, 'world'); \/\/ Modifying element\nconsole.log(tuple.get(1));\n\n\/\/ Map Example using Class\nclass CustomMap {\n    constructor() {\n        this.map = new Map();\n    }\n    add(key, value) {\n        this.map.set(key, value);\n    }\n    get(key) {\n        return this.map.get(key);\n    }\n    delete(key) {\n        this.map.delete(key);\n    }\n    iterate() {\n        for (const [key, value] of this.map.entries()) {\n            console.log(key, value);\n        }\n    }\n}\n\nconst customMap = new CustomMap();\ncustomMap.add('name', 'John');\ncustomMap.add('age', 30);\nconsole.log(customMap.get('name'));\ncustomMap.delete('name');\ncustomMap.iterate();\n\n\/\/ Linear Search using Function\nfunction linearSearch(arr, target) {\n    for (let i = 0; i &lt; arr.length; i++) {\n        if (arr[i] === target) return i;\n    }\n    return -1;\n}\n\n\/\/ Binary Search using Function\nfunction binarySearch(arr, target) {\n    let left = 0, right = arr.length - 1;\n    while (left &lt;= right) {\n        const mid = Math.floor((left + right) \/ 2);\n        if (arr[mid] === target) return mid;\n        else if (arr[mid] &lt; target) left = mid + 1;\n        else right = mid - 1;\n    }\n    return -1;\n}\n\n\/\/ KMP String Search using Function\nfunction KMPSearch(pattern, text) {\n    const lps = computeLPSArray(pattern);\n    let i = 0, j = 0;\n    while (i &lt; text.length) {\n        if (pattern[j] === text[i]) {\n            i++; j++;\n        }\n        if (j === pattern.length) {\n            console.log('Pattern found at index', i - j);\n            j = lps[j - 1];\n        } else if (i &lt; text.length &amp;&amp; pattern[j] !== text[i]) {\n            j !== 0 ? j = lps[j - 1] : i++;\n        }\n    }\n}\n\nfunction computeLPSArray(pattern) {\n    const lps = [0];\n    let len = 0, i = 1;\n    while (i &lt; pattern.length) {\n        if (pattern[i] === pattern[len]) {\n            len++;\n            lps[i] = len;\n            i++;\n        } else if (len !== 0) {\n            len = lps[len - 1];\n        } else {\n            lps[i] = 0;\n            i++;\n        }\n    }\n    return lps;\n}\n\n\/\/ Tree Node and Traversal using Class\nclass TreeNode {\n    constructor(value) {\n        this.value = value;\n        this.left = null;\n        this.right = null;\n    }\n}\n\nclass TreeTraversal {\n    static dfs(node) {\n        if (!node) return;\n        console.log(node.value);\n        this.dfs(node.left);\n        this.dfs(node.right);\n    }\n\n    static bfs(root) {\n        const queue = [root];\n        while (queue.length > 0) {\n            const node = queue.shift();\n            console.log(node.value);\n            if (node.left) queue.push(node.left);\n            if (node.right) queue.push(node.right);\n        }\n    }\n}\n\n\/\/ Bubble Sort using Function\nfunction bubbleSort(arr) {\n    const n = arr.length;\n    for (let i = 0; i &lt; n - 1; i++) {\n        for (let j = 0; j &lt; n - i - 1; j++) {\n            if (arr[j] > arr[j + 1]) {\n                [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];\n            }\n        }\n    }\n    return arr;\n}\n\nconst sampleArray = [5, 3, 8, 4, 2];\nconsole.log(bubbleSort(sampleArray));\n<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Got it! Here&#8217;s the updated 8-hour JavaScript DSA training plan with examples without using inbuilt functions like .push(), .pop(), .shift(), .split(), etc. \ud83d\ude80 8-Hour JavaScript DSA Training Plan (Without Inbuilt Functions) Hour 1: Introduction to DSA &amp; Complexity Analysis Topics: What is DSA? Time and Space Complexity (Big O Notation) Examples: Constant Time &#8211; O(1)O(1) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2807"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=2807"}],"version-history":[{"count":12,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2807\/revisions"}],"predecessor-version":[{"id":2823,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2807\/revisions\/2823"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=2807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=2807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=2807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}