<?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 Jeff Chiu on Medium]]></title>
        <description><![CDATA[Stories by Jeff Chiu on Medium]]></description>
        <link>https://medium.com/@jeffchiu2?source=rss-70b61c661a6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*p1SijFaRVAicuxCXZdZ6eg.png</url>
            <title>Stories by Jeff Chiu on Medium</title>
            <link>https://medium.com/@jeffchiu2?source=rss-70b61c661a6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 19 May 2026 04:11:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jeffchiu2/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[React Tutorial for Google Map Places library]]></title>
            <link>https://medium.com/@jeffchiu2/react-tutorial-for-google-map-places-library-4ff95300fe9f?source=rss-70b61c661a6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ff95300fe9f</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jeff Chiu]]></dc:creator>
            <pubDate>Mon, 28 May 2018 06:13:03 GMT</pubDate>
            <atom:updated>2018-05-28T06:14:41.141Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi.</p><p>Another day I was learning how to implement Google Map Places API to my React App. And I found this tutorial created by Ari Lerner very helpful. That I decide to cite a lot of his open source github website fullstackreact.com and build a tutorial based on that.</p><h3>Tutorial: Intro To React Google Map</h3><h3>What We’re Building</h3><p>Today, we’re going to build a simple React App with Google Map API</p><p>If you like, you can check out the final result here:</p><p><a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/">Fullstack React: How to Write a Google Maps React Component</a></p><p>Resources come from fullstackReact</p><p><a href="https://github.com/fullstackreact/google-maps-react">fullstackreact/google-maps-react</a></p><h3>Prerequisites</h3><p>We’ll assume some familiarity with HTML and JavaScript, but you should be able to follow along even if you haven’t used them before.</p><p>If you need a refresher on JavaScript, we recommend reading <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript">this guide</a>. Note that we’re also using some features from ES6, a recent version of JavaScript. In this tutorial, we’re using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">classes</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let">let</a>, and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const">const</a> statements. You can use the <a href="https://babeljs.io/repl/#?presets=react&amp;code_lz=MYewdgzgLgBApgGzgWzmWBeGAeAFgRgD4AJRBEAGhgHcQAnBAEwEJsB6AwgbgChRJY_KAEMAlmDh0YWRiGABXVOgB0AczhQAokiVQAQgE8AkowAUAcjogQUcwEpeAJTjDgUACIB5ALLK6aRklTRBQ0KCohMQk6Bx4gA">Babel REPL</a> to check what ES6 code compiles to.</p><p><strong>Table of Contents</strong></p><ol><li><a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/#">Loading a Google-based Component</a></li><li><a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/#">Adding props to the Map Component</a></li><li><a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/#">Adding state to the Map Component</a></li><li><a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/#">Using the Browser’s Current Location</a></li></ol><h3>Dragging the Map Around with addListener</h3><p>Since we have our Map component set, the we can interact with it in a lot of ways. The google map api is rich with opportunities for handling events that happen within the map (just check out the extensive <a href="https://developers.google.com/maps/documentation/javascript/events">documentation</a>). We can set up callbacks to call when these events occur within the map instance itself.</p><p>For instance, when the google map has been moved or dragged around, we can fire a callback. For instance, let’s set up a callback to run when the map itself has been dragged around.</p><p>To add event handlers, we need the map to be listening for events. We can add listeners pretty easily with the Google API using the addListener() function on our Map.</p><p>After we create our map, in the loadMap() function, we can add our event listeners. Let&#39;s handle the dragend event that will be fired when the user is done moving the map to a new location.</p><pre>export class Map extends React.Component {<br>  loadMap() {<br>    if (this.props &amp;&amp; this.props.google) {<br>      // ...<br>      this.map = new maps.Map(node, mapConfig);</pre><pre>      this.map.addListener(&#39;dragend&#39;, (evt) =&gt; {<br>        this.props.onMove(this.map);<br>      })<br>    }<br>    // ...<br>  }<br>}<br>Map.propTypes = {<br>  // ...<br>  onMove: React.PropTypes.func<br>}<br>Map.defaultProps = {<br>  onMove: function() {} // default prop<br>}</pre><p>When our user is done moving around the map, the dragend event will be fired and we&#39;ll call our onMove() function we passed in with the props.</p><p>One issue with the way we’re handling callbacks now is that the dragend event is fired a LOT of times. We don&#39;t necessarily need it to be called every single time it&#39;s dragged around, but at least once at the end. We can create a limit to the amount of times we&#39;ll call the onMove() prop method by setting up a simple timeout that we can clear when the event is fired again.</p><pre>export class Map extends React.Component {<br>  loadMap() {<br>    if (this.props &amp;&amp; this.props.google) {<br>      // ...<br>      this.map = new maps.Map(node, mapConfig);</pre><pre>      let centerChangedTimeout;<br>      this.map.addListener(&#39;dragend&#39;, (evt) =&gt; {<br>        if (centerChangedTimeout) {<br>          clearTimeout(centerChangedTimeout);<br>          centerChangedTimeout = null;<br>        }<br>        centerChangedTimeout = setTimeout(() =&gt; {<br>          this.props.onMove(this.map);<br>        }, 0);<br>      })<br>    }<br>    // ...<br>  }<br>}</pre><h3>Handling More Events</h3><p>Although we are only handling the dragend event above, we can handle other events as well in a similar fashion, but this can get really cumbersome, really fast. We can be a little bit more clever and more programatic about building our interactivity into our component.</p><p>Let’s say we want to handle two events, the dragend event and the click event. Rather than copy+pasting our code from above for every single event, let&#39;s build this up programmatically.</p><p>First, let’s create a list of the events we want to handle:</p><pre>const evtNames = [&#39;click&#39;, &#39;dragend&#39;];</pre><p>With our evtNames list, let&#39;s replace our addListener() funcitonality from above with a loop for each of the evtNames:</p><pre>export class Map extends React.Component {<br>  loadMap() {<br>    if (this.props &amp;&amp; this.props.google) {<br>      // ...<br>      this.map = new maps.Map(node, mapConfig);</pre><pre>      evtNames.forEach(e =&gt; {<br>        this.map.addListener(e, this.handleEvent(e));<br>      });<br>    }<br>    // ...<br>  }</pre><pre>  handleEvent(evtName) {</pre><pre>  }<br>}</pre><p>As the addListener() function expects us to return an event handler function, we&#39;ll need to return a function back, so we can start our handleEvent() function like:</p><pre>export class Map extends React.Component {<br>  handleEvent(evtName) {<br>    let timeout;<br>    return (e) =&gt; {<br>      // ...<br>    }<br>  }<br>}</pre><p>We’ll basically copy+paste our timeout functionality into our new handleEvent()function.</p><pre>export class Map extends React.Component {<br>  handleEvent(evtName) {<br>    let timeout;<br>    const handlerName = evtName;</pre><pre>    return (e) =&gt; {<br>      if (timeout) {<br>        clearTimeout(timeout);<br>        timeout = null;<br>      }<br>      timeout = setTimeout(() =&gt; {<br>        if (this.props[handlerName]) {<br>          this.props[handlerName](this.props, this.map, e);<br>        }<br>      }, 0);<br>    }<br>  }<br>}</pre><p>Now, any time we pass a prop with the event name, like click it will get called whenever we click on the map itself. This isn&#39;t very React-like, or JS-like for that matter. Since it&#39;s a callback, a better naming scheme would be onClick and onDragend.</p><p>Since we’re going meta in the first place, let’s make our propName be a camelized word starting with on and ending with the capitalized event name.</p><p>A simple camelize() helper function might look something similar to:</p><pre>const camelize = function(str) {<br>  return str.split(&#39; &#39;).map(function(word){<br>    return word.charAt(0).toUpperCase() + word.slice(1);<br>  }).join(&#39;&#39;);<br>}<br>camelize(&#39;i love you&#39;); // ILoveYou<br>camelize(&#39;say hello&#39;); // SayHello</pre><p>With our camelize() helper function, we can replace the handlerName from our handleEvent function:</p><pre>export class Map extends React.Component {<br>  handleEvent(evtName) {<br>    let timeout;<br>    const handlerName = `on${camelize(evtName)}`;</pre><pre>    return (e) =&gt; {<br>      if (timeout) {<br>        clearTimeout(timeout);<br>        timeout = null;<br>      }<br>      timeout = setTimeout(() =&gt; {<br>        if (this.props[handlerName]) {<br>          this.props[handlerName](this.props, this.map, e);<br>        }<br>      }, 0);<br>    }<br>  }<br>}</pre><p>Lastly, because we are good React-citizens, let’s add these properties to our propTypes:</p><pre>evtNames.forEach(e =&gt; Map.propTypes[camelize(e)] = T.func)</pre><h3>Handling Custom Events on Map</h3><p>We can also fire our own custom events along with the google map instance. Allowing us to listen for our own custom events is an incredibly useful feature that gives us the ability to react to custom functionality using the same event handling mechanism we just set up.</p><p>An example of this is giving the our &lt;Map /&gt; callback to trigger a ready event.</p><p>Let’s add the &#39;ready&#39; string to our evtNames so we handle the onReady prop (if passed in):</p><pre>const evtNames = [&#39;ready&#39;, &#39;click&#39;, &#39;dragend&#39;];</pre><p>To trigger an event, like the ready event we can use the google.maps.event object&#39;s trigger() function.</p><p>For handling the case after the map is ready (at the end of our loadMap() function), we can call the trigger() function <em>on</em> the map instance with the event name.</p><pre>export class Map extends React.Component {<br>  loadMap() {<br>    if (this.props &amp;&amp; this.props.google) {<br>      // ...<br>      this.map = new maps.Map(node, mapConfig);</pre><pre>      evtNames.forEach(e =&gt; {<br>        this.map.addListener(e, this.handleEvent(e));<br>      });</pre><pre>      maps.event.trigger(this.map, &#39;ready&#39;);<br>    }<br>    // ...<br>  }<br>}</pre><p>Since we’ve already set the rest of the event handlers up, this will <em>just work</em>.</p><h3>Adding Markers to the Map</h3><p>What good is a Google Map without markers indicating location spots on the map, eh? Let’s add a method for our users to place a marker on our map. We <em>could</em> set up our Map component to accept a list of places and be responsible for setting up the markers itself, or we can build the Map component in the <em>React Way</em> and build custom components to manipulate the calendar as children.</p><p>Let’s build a MarkerComponent using the <em>React Way</em>. As we previously did, let&#39;s build the usage first and then build the implementation.</p><p>The <em>React Way</em> is to write our Marker components as children of the Map component.</p><pre>export class Container extends React.Component {<br>  render() {<br>    const style = {<br>      width: &#39;100vw&#39;,<br>      height: &#39;100vh&#39;<br>    }<br>    const pos = {lat: 37.759703, lng: -122.428093}<br>    return (<br>      &lt;div style={style}&gt;<br>        &lt;Map google={this.props.google}&gt;<br>          &lt;Marker /&gt;<br>          &lt;Marker position={pos} /&gt;<br>        &lt;/Map&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}<br>// ...</pre><p>We’ll build our &lt;Marker /&gt; component as a child of the Map component so that they are independent of the Map itself, but still can be interdependent upon the Mapcomponent being available.</p><p>When we place a &lt;Marker /&gt; inside the &lt;Map /&gt; component, we&#39;ll want to pass through some custom props that the Map contains, including the map instance object to it&#39;s children.</p><p>React gives us a convenient method for handling updating the props of children objects of a component. First, let’s update our Map.render() method to include rendering children:</p><p>In this post, we’ll look at how we to connect the Google API and build a Google Maps Component.</p><h3>Demo</h3><p>Before we can integrate with Google Maps, we’ll need to sign up at Google to get an API key.</p><p>Show For more information about signing up for a Google Key of your own, check the instructions here.</p><h3>Loading a Google-based Component</h3><p>In order to use Google within our components, we’ll need to handle two technical boundaries:</p><ol><li>Loading the Google API</li><li>Handling access to the Google API within our components.</li></ol><p>Our goal here is to create an independent component that can handle these two tasks for us. Let’s build a GoogleApiComponent to handle taking care of this for us (alternatively, we&#39;ve wrapped this into an <a href="https://www.npmjs.com/package/google-maps-react">npm module ( </a><a href="https://www.npmjs.com/package/google-maps-react">google-maps-react)</a>. Feel free to grab this npm module and head to the <a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/#the-map-container-component">next section</a>).</p><p>With our key in hand, we’ll need to load up the Google API on our page. We can handle this in multiple ways, including directly including the &lt;script&gt; tag on our page through asynchronously loading the script using JavaScript. We try to keep our dependencies limited to the scripts we directly need on a page as well as define our dependencies in JavaScript, so we&#39;ll take the latter method of loading our window.google object using a React component.</p><p>First, grab the ScriptCache.js script <a href="https://gist.github.com/auser/1d55aa3897f15d17caf21dc39b85b663">from this gist</a>.</p><p>There are 3 scripts included in the gist. The scripts:</p><ul><li>ScriptCache.js - The backbone of this method which asynchronously loads JavaScript &lt;script&gt; tags on a page. It will only load a single &lt;script&gt; tag on a page per-script tag declaration. If it&#39;s already loaded on a page, it calls the callback from the onLoad event immediately.</li></ul><p>Sample usage:</p><pre>this.scriptCache = cache({<br>  google: &#39;https://api.google.com/some/script.js&#39;<br>});</pre><ul><li>GoogleApi.js is a script tag <em>compiler</em>. Essentially, this utility module builds a Google Script tag link allowing us to describe the pieces of the Google API we want to load in using a JS object and letting it build the endpoint string.</li></ul><p>Sample usage:</p><pre>GoogleApi({<br>  apiKey: apiKey,<br>  libraries: [&#39;places&#39;]<br>});</pre><ul><li>GoogleApiComponent.js - The React wrapper which is responsible for loading a component and passing through the window.google object after it&#39;s loaded on the page.</li></ul><h3>Source from React fullstackreact.com</h3><p>On<a href="https://github.com/fullstackreact/google-maps-react"> the Github repo</a></p><h3>Ari Lerner by <a href="https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/">https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ff95300fe9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Quick Sort visually quickly]]></title>
            <link>https://medium.com/@jeffchiu2/quick-sort-in-python-d1cc19294c28?source=rss-70b61c661a6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1cc19294c28</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Jeff Chiu]]></dc:creator>
            <pubDate>Wed, 13 Dec 2017 19:59:53 GMT</pubDate>
            <atom:updated>2018-08-12T00:15:12.305Z</atom:updated>
            <content:encoded><![CDATA[<p>So you wanted to learn sorting. Here’s a good sorting algorithm called Quick Sort.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPgBzjlCcFvc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPgBzjlCcFvc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPgBzjlCcFvc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/328430bbef03a1c2d7eb85a9fcb4e14a/href">https://medium.com/media/328430bbef03a1c2d7eb85a9fcb4e14a/href</a></iframe><h3>What is Quick Sort?</h3><p>The Quick sort algorithm is based on the idea of choosing an element in the array as a pivot and <strong>partitioning</strong> the array around it such that the left side of the pivot holds all the elements that are less than it and the right side of the pivot holds all the elements that are greater than it. Then we repeat the same process on each partition . [Khan Academy]</p><p>Quick sort uses divide and conquer, and it’s a good algorithm to learn. How Partitions work in QuickSort:</p><ol><li><strong>Divide</strong> by choosing any element in the array as the pivot, which is any element in the array as the pivot</li></ol><p>2. Use the pivot to divide the partitions into two parts:</p><ul><li>The pivot goes between the two lists</li><li>Divide all other elements (except the pivot) into two partitions.</li><li><strong>All elements less than the pivot must be in the first partition.</strong></li><li><strong>All elements greater than the pivot must be in the second partition.</strong></li><li>Repeat on both partitions, until all elements are sorted</li></ul><p>Here is an example I drew to illustrate the partitioning:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpORB6xvuRspmegndgLyeA.jpeg" /><figcaption>This picture illustrate the steps on choosing a pivot on QuickSort</figcaption></figure><p><strong>Conquer:</strong></p><ol><li>After having 2 partitions, we can use recursion to sort both partitions.</li><li>Finally, join the first sorted partition, the pivot, and the second sorted partition.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*cyVnXD7ymdoQ0DrUeG_icg.png" /><figcaption>Visualization for quick sort from <a href="http://www.codeido.com/2010/12/recursive-quicksort-algorithm-written-in-c-language-with-example-step-by-step/">Codeido</a></figcaption></figure><p>Now, let’s take a look of some implementation done in python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d4f642fdb8bd2aa31dbfb2abe0f0ebf/href">https://medium.com/media/7d4f642fdb8bd2aa31dbfb2abe0f0ebf/href</a></iframe><p><strong>The Big O notation:</strong></p><p>The worst case for quick sort is Θ(n²), it happens when we have a sorted array.</p><p>But what about the average case?</p><p>Since we are dividing an array into two halves in each stage, it has log(n) operation, and each partition loops through the whole array, taking O(n) time — so in total, <strong>t<em>he average running time is O(n*log(n)).</em></strong></p><p>The average-case run time complexity: Θ(n log(n)), which is as good as merge sort’s.</p><p>And its worst-case run time complexity is as bad as selection sort’s and insertion sort’s:</p><p>Although it’s a space sorting algorithm, we are calling each operation recursively, so we have <strong>extra stack frames space</strong>:<em> log(n)</em>, hence,<strong> the <em>average space is O(log(n)).</em></strong></p><p><strong>Best Practice: Quick sort works really well with a list with only a few unique items, cause it would group similar items together fast and reduce the redundant comparison.</strong></p><ol><li><a href="http://www.geeksforgeeks.org/quick-sort/">Quicksort</a>: GeekForGeek,</li><li><a href="https://www.youtube.com/watch?v=aMb5GHPGQ1U&amp;t=112s">Quick Sort</a>, Udacity</li><li><a href="https://www.khanacademy.org/computing/computer-science/algorithms/quick-sort/a/overview-of-quicksort">QuickSort</a>, Khan Academy</li><li><a href="https://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/">Computer science in JavaScript: Quicksor</a>t, Nicholas C. Zakas</li><li>Is <a href="https://stackoverflow.com/questions/22028117/is-quicksort-in-place-or-not">Quick-Sort In place</a> or not, StackOverflow:</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1cc19294c28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Search Algorithms in Python]]></title>
            <link>https://medium.com/@jeffchiu2/binary-search-algorithms-in-python-8d3a0e2ceed6?source=rss-70b61c661a6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d3a0e2ceed6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Jeff Chiu]]></dc:creator>
            <pubDate>Tue, 05 Dec 2017 20:37:23 GMT</pubDate>
            <atom:updated>2018-04-30T07:01:13.127Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Given that we have a list of 10 entries: </strong><strong>[1,2,3,4,5,6,7,8,9,10] and we want to find if the number 5 is in the list.</strong></h4><p>One way to solve this problem is through linear search. And it will help us to find the item 5 on the list. Here’s python code for linear search algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/371188a016830ebc2539b03cc101fdf1/href">https://medium.com/media/371188a016830ebc2539b03cc101fdf1/href</a></iframe><p>The Big O notation of linear search is O(n) since we go through entire list. But can we do better than linear search. We can perform <strong>Binary Search</strong>.</p><p><a href="https://en.wikipedia.org/wiki/Binary_search_algorithm"><strong>Binary Search Algorithm</strong></a> “search through sorted array by repeatedly dividing the search interval in half” (GeekForGeek). If the value of the target item is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.</p><p>We can break down the process into these steps:</p><ol><li>Find the Middle element of the list</li><li>Compare the target item value with the middle element, if its the same, we stop since we found the item</li><li>If the middle element is less than the target value, we know that we can eliminate the lower half. Our new list to be the upper half of the old list, and repeat the whole process from step 2.</li><li>If the middle element is greater than the target value, we know that it’s on the lower half of list and eliminate the upper half list. And repeat the whole process from step 2.</li></ol><p>Now let’s turn them into some python code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd62d9aee815258c932556ebd74e9490/href">https://medium.com/media/fd62d9aee815258c932556ebd74e9490/href</a></iframe><p>This code is the iterative solution of binary search. This method only works on problems in which the list is already sorted. I include comments explain that we can identify he middle item value of the list by taking the sum of the beginning and end of the list and divide by 2. And we do the comparison and search through the item on a list. If the item is not the list, then we will return None.</p><p>Picture example:</p><p><a href="https://www.topcoder.com/wp-content/media/2017/07/binary-search.png">https://www.topcoder.com/wp-content/media/2017/07/binary-search.png</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*GZg7uqn8Diej1DRbd2nAHA.png" /><figcaption>Picture Source: GeekForGeek. Picture Link: <a href="http://www.geeksforgeeks.org/binary-search/">http://www.geeksforgeeks.org/binary-search/</a></figcaption></figure><p>In this example, We are searching for <strong>23</strong> inside a list of 10 element.</p><p>First iteration: We middle element is <strong>16</strong>. And we compare and find 23 &gt; 16, so we takes the <strong>upper half </strong>as our new list.</p><p>Second iteration: New middle element is <strong>56</strong>, We compare and find 23 &lt; 56, so we takes the <strong>lower half </strong>as our new list.</p><p>Third Iteration: New middle element is <strong>23</strong> and <strong>we found the item 23!</strong></p><p><strong>Big O Notation of Binary Search.</strong></p><p>Since the cut is always a percentage of the list instead of an exact amount of the list the Big O of this approach is O(log n).</p><p>We can test the code of our above example here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3372a0e5068ad912adade3dcf9d7bfc3/href">https://medium.com/media/3372a0e5068ad912adade3dcf9d7bfc3/href</a></iframe><p>More resource:</p><p><a href="https://www.khanacademy.org/computing/computer-science/algorithms/binary-search/a/binary-search">1.Khan Academy: Binary Search</a></p><p>2. <a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures/lecture-9/">MIT: Binary Search: Professor Eric Grimson, Prof. John Guttag</a></p><p>3. <a href="http://www.geeksforgeeks.org/binary-search/">GeekForGeek: Binary Search</a></p><p>4. <a href="https://www.youtube.com/watch?v=0VN5iwEyq4c">Udacity: Binary Search</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d3a0e2ceed6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>