<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohammad Mazharul Hoque  on Medium]]></title>
        <description><![CDATA[Stories by Mohammad Mazharul Hoque  on Medium]]></description>
        <link>https://medium.com/@mohammad.mazharul.hoque.007?source=rss-8c6be40c731b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Xs39Gm121-y0nKJg</url>
            <title>Stories by Mohammad Mazharul Hoque  on Medium</title>
            <link>https://medium.com/@mohammad.mazharul.hoque.007?source=rss-8c6be40c731b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:35:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohammad.mazharul.hoque.007/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Binary search implementation with javaScript]]></title>
            <link>https://medium.com/@mohammad.mazharul.hoque.007/binary-search-implementation-with-javascript-d172615022f?source=rss-8c6be40c731b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d172615022f</guid>
            <dc:creator><![CDATA[Mohammad Mazharul Hoque ]]></dc:creator>
            <pubDate>Sun, 22 Jan 2023 14:20:06 GMT</pubDate>
            <atom:updated>2023-01-22T14:47:41.409Z</atom:updated>
            <content:encoded><![CDATA[<p>Binary search doesn’t follow linear approach like linear search. It follows slightly different approach.</p><p>We apply binary searching technique to find out specific element from an array or list, just like linear searching.</p><p>However, main condition of binary search is the array/ list must be sorted in ascending or descending order. If data are not sorted in ascending or descending order, then we have to sort them before performing binary search.</p><h4><strong>Steps of binary search:</strong></h4><p>Let’s assume, we have a sorted array.</p><p><strong>let numbers = [10,20,30,40,50,60,70,80,90,100,110,115,119,120];</strong></p><p>We have to find the number <strong>119</strong></p><p>Then we have to iterate through the <strong>numbers</strong> array to find out our desired number.</p><p>As we can’t say how many times the loop will run, we will use while loop here and insert condition as well.</p><p>We will get to know what the condition in loop will be at end.</p><p>In this case, we have to start comparing with the midst array indices value at first to find out whether it is our target element or not.</p><p>So we will sum up first index <strong>0</strong> and last index <strong>13</strong> and then will divide by 2 to find out midst index.</p><p><strong><em>Note:</em></strong><em> </em>If quotient comes in fraction. we can make it integer with help of js built in method <strong>parseInt()/ Math.floor()</strong></p><p>Here, we can store <strong>starIndex</strong> and <strong>lastIndex</strong> of array with 2 variables and can calculate <strong>midIndex</strong> later.</p><pre>let startIndex = 0;<br>let lastIndex = numbers.length - 1;<br>let midIndex = Math.floor((startIndex + lastIndex) / 2);<br></pre><p>Firstly, we would compare <strong>midIndex</strong> value with <strong>119</strong> to see whether they are same or not.</p><p>If <strong>midIndex</strong> value equals 119, then we will return index of <strong>119</strong></p><p>Here, midIndex count is <strong>7</strong> and value is 7<strong>0</strong>. As the array is sorted, this means the values resided left of <strong>midIndex</strong> value <strong>70 </strong>are all smaller than <strong>70</strong> and smaller than our target element <strong>119</strong> as well. In this case, we can skip all values set left of <strong>midIndex</strong> value.</p><p>Next, we will check whether our <strong>midIndex</strong> value is smaller than our target element. If <strong>midIndex</strong> value is smaller than our target element, then we will update,</p><p><strong>startIndex= midindex + 1</strong></p><p><strong>lastIndex</strong> won’t change.</p><pre>if (arr[midIndex] &lt; target) startIndex = midIndex + 1;</pre><p>If <strong>midIndex</strong> value is greater than our target element, then we will we will subtract <strong>1</strong> from <strong>midIndex</strong> and update <strong>lastIndex</strong> value. In this case, <strong>startIndex</strong> value won’t be updated.</p><p>Moreover, our condition will kept running in loop until our <strong>startIndex</strong> value becomes less than or equal to <strong>lastIndex</strong>.</p><h4>Binary search code:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Xtsx3L_sFIrON0G8MDSVA.png" /><figcaption>Fig: binary search</figcaption></figure><h4><strong>Time complexity:</strong></h4><p>Time complexity of binary search is <strong>O(log2 n)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d172615022f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[বাইনারি সার্চ ইমপ্লিমেন্টেশন ইন জাভাস্ক্রিপ্ট]]></title>
            <link>https://medium.com/@mohammad.mazharul.hoque.007/%E0%A6%AC%E0%A6%BE%E0%A6%87%E0%A6%A8%E0%A6%BE%E0%A6%B0%E0%A6%BF-%E0%A6%B8%E0%A6%BE%E0%A6%B0%E0%A7%8D%E0%A6%9A-%E0%A6%87%E0%A6%AE%E0%A6%AA%E0%A7%8D%E0%A6%B2%E0%A6%BF%E0%A6%AE%E0%A7%87%E0%A6%A8%E0%A7%8D%E0%A6%9F%E0%A7%87%E0%A6%B6%E0%A6%A8-%E0%A6%87%E0%A6%A8-%E0%A6%9C%E0%A6%BE%E0%A6%AD%E0%A6%BE%E0%A6%B8%E0%A7%8D%E0%A6%95%E0%A7%8D%E0%A6%B0%E0%A6%BF%E0%A6%AA%E0%A7%8D%E0%A6%9F-c894411031ec?source=rss-8c6be40c731b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c894411031ec</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[bangla]]></category>
            <dc:creator><![CDATA[Mohammad Mazharul Hoque ]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 14:03:45 GMT</pubDate>
            <atom:updated>2022-11-21T04:46:59.252Z</atom:updated>
            <content:encoded><![CDATA[<p>বাইনারি সার্চ মুলত লিনিয়ার সার্চের মত লিনিয়ার এপ্রোচ ফলো করে না, একটু ডিফ্রেন্ট এপ্রোচ ফলো করে।</p><p>লিনিয়ার সার্চ এর মতো বাইনারি সার্চিং টেকনিকও আমরা অ্যারে কিংবা লিস্ট থেকে স্পেসিফিক এলিমেন্ট খুঁজে বের করার জন্য এপ্লাই করে থাকি।</p><p>তবে বাইনারি সার্চের মূল শর্ত হচ্ছে যেই অ্যারে বা লিস্ট দেয়া থাকবে সেটা ছোট থেকে বড় কিংবা বড় থেকে ছোট ক্রমানুসারে সাজানো থাকতে হবে। তবে অনেক সময় ডাটা যদি ছোট থেকে বড় কিংবা বড় থেকে ছোট ক্রমানুসারে সাজানো না থাকে তাহলে সাজিয়ে নিয়ে তারপর বাইনারি সার্চ করা যায়।</p><h3>বাইনারি সার্চের স্টেপসঃ</h3><p>ধরে নিই, আমাদের কাছে একটা সরটেড অ্যারে আছে</p><p><strong>let numbers= [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 115, 119, 200];</strong></p><p>এবং আমাদেরকে <strong>119</strong> খুঁজে বের করতে হবে।</p><p>numbers array টার উপর লুপ চালিয়ে আমাদের কে আমাদের কাঙ্ক্ষিত নাম্বারটা খুঁজে বের করতে হবে।</p><p>যেহেতু আমরা জানি না লুপ টা কতক্ষণ পর্যন্ত চলবে সেই ক্ষেত্রে আমরা এখানে While loop use করবো এবং কন্ডিশনটা দিয়ে দিবো।</p><p>লুপের ভেতর কি কন্ডিশন হবে সেটা আমরা শেষে জেনে নিবো।</p><p>এই ক্ষেত্রে আমাদের কে প্রথমে অ্যারের মাঝের ইন্ডেক্স এর সাথে কম্পারিজন করতে হবে যে সেটা আমাদের টারগেট এলিমেন্ট কিনা।</p><p>মাঝের ইন্ডেক্স বের করার জন্য আমরা আমাদেরকে প্রথম ইন্ডেক্স 0 এবং সর্বশেষ ইনডেক্স 13 যোগ করে ২ দিয়ে ভাগ দিতে হবে।</p><p>নোটঃ ভাগফল যদি ফ্র্যাকশন আসে সেই ক্ষেত্রে আমরা চাইলে <strong>JS built in method parseInt() / Math.floor() </strong>এর সাহায্যে পূর্ণসংখ্যা বানিয়ে নিতে পারি।</p><p>সেইক্ষেত্রে আমরা ২ টা ভেরিয়েবলে startIndex এবং অ্যারের lastIndex টা স্টোর করে নিতে পারি এবং পরবর্তীতে midIndex হিসাব করে নিতে পারি।</p><pre>let startIndex = 0;<br>let lastIndex = numbers.length - 1;<br>let midIndex = Math.floor((startIndex + lastIndex) / 2);</pre><p>প্রথম স্টেপ হিসেবে আমরা midIndex এর ভ্যালুর সাথে কম্পেয়ার করবো ১১৯ কে। midIndex এবং ১১৯ সমান কিনা।</p><p>যদি সমান হয় তাহলে আমরা ১১৯ এর ইনডেক্স রিটার্ন করে দিব।</p><p>এখানে, মাঝের ইনডেক্স হচ্ছে ৭, যেটার ভ্যালু ৮০। যেহেতু অ্যারে টা Sorted, তার মানে ৭ নম্বর ইনডেক্স এর ভ্যালু ৮০ এর বাম পাশের সবগুলো ভ্যালুই ৮০ থেকে ছোট এবং আমাদের টারগেট এলিমেন্ট ১১৯ থেকেও ছোট। সেক্ষেত্রে midIndex থেকে বাম পাশের সব ভ্যালু কে আমরা বাদ দিয়ে দিতে পারি।</p><p>এক্ষেত্রে চলে আসবে ২য় ধাপ,</p><p>২য় ধাপে আমরা চেক করবো আমাদের midIndex এর ভ্যালু আমাদের টারগেট এলিমেন্ট থেকে ছোট কিনা, যদি ছোট হয় সেই ক্ষেত্রে আমরা আমাদের <strong>startIndex = midIndex + 1</strong> এভাবে আপডেট করে নিব। এবং <strong>lastIndex</strong> এর কোন পরিবর্তন হবে না।</p><pre>if (arr[midIndex] &lt; target) startIndex = midIndex + 1;</pre><p>আর যদি এমন হয় midIndexএর ভ্যালু আমাদের টারগেট এলিমেন্ট থেকে বড় সেই ক্ষেত্রে আমরা <strong>midIndex</strong> থেকে ১ বিয়োগ করে আমাদের <strong>lastIndex</strong> ভ্যালু টা আপডেট করে নিব এবং সেক্ষেত্রে</p><p><strong>startIndex</strong> এর ভ্যালু আপডেট হবেনা।</p><p>এবং লুপের ভেতর আমাদের কন্ডিশন টা ততক্ষণ চলবে যতক্ষণ না পর্যন্ত আমাদের <strong>startIndex</strong> এর ভ্যালু <strong>lastIndex</strong> এর চেয়ে ছোট বা সমান না হয়।</p><h3>বাইনারি সার্চ কোড ইন জাভাস্ক্রিপ্ট:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37i1-rHNFPDl2mGu2XZPfw.png" /></figure><h3>টাইম কমপ্লেক্সিটিঃ</h3><p>বাইনারি সার্চের টাইম কমপ্লেক্সিটি হলো O(log2 n)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c894411031ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>