<?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 Ayub Gholami on Medium]]></title>
        <description><![CDATA[Stories by Ayub Gholami on Medium]]></description>
        <link>https://medium.com/@gholami.ayub73?source=rss-a899d8fe8a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1ocUaG2pL70-WCZ1mKUkZw.jpeg</url>
            <title>Stories by Ayub Gholami on Medium</title>
            <link>https://medium.com/@gholami.ayub73?source=rss-a899d8fe8a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:35:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gholami.ayub73/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[A Power-Packed Light Reading on Data Structures]]></title>
            <link>https://medium.com/@gholami.ayub73/a-power-packed-light-reading-on-data-structures-fa3bed092cc2?source=rss-a899d8fe8a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa3bed092cc2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ayub Gholami]]></dc:creator>
            <pubDate>Sun, 29 May 2022 06:35:36 GMT</pubDate>
            <atom:updated>2022-05-29T06:35:36.326Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GuGjm6woROpyx68MUo2l0Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@alpridephoto?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Андрей Сизов</a> on <a href="https://unsplash.com/s/photos/algorithm?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When we talk about data structure and algorithms, it’s very important to know concepts like <strong>Big O Notation</strong> and <strong>Time Complexity</strong>.<br>These concepts help us to choose the right data structure and to know<br>them very vital, these are metrics which we use to choose the right data<br>structure. and things like how memory , linked list, and array works, they<br>help us to have a better understanding of the speed and performance of a<br>data structure..</p><h3>Why Do We Need to Know Time Complexities?</h3><p>A developer must choose the right data structures for the job. Choosing<br>the right data structure is often ignored and it ends up badly impacting<br>the performance of the application. In this tutorial, I want to teach<br>you some important concepts in the data structure.at first, I want to<br>talk about <strong>Big O Notation</strong></p><h3>What does Big O Notation Mean?</h3><p><strong>Big O-Notation</strong> is a special notation that tells you how fast an algorithm is. It’s called <strong>Big O-Notation</strong> because you put a “big O” in front of the number of operations (it sounds like a joke, but it’s true!). <strong>Big O Notation</strong> of the key operations of data structure</p><p>The number of operations is performed in an algorithm. These operations could include iterating over a collection, <strong>copying</strong> an item or the entire collection, <strong>appending</strong> an item into a collection, <strong>inserting</strong> an item at the start or end of a collection, <strong>deleting</strong> an item, or updating an item in a collection. <strong>Big O Notation</strong> is a way to measure the performance of an operation based on the <strong>input size</strong></p><h3>Common Big O Notation</h3><p>Let’s consider <strong>n</strong> to be the <strong>size</strong> of the <strong>input</strong> collection</p><p><strong>O(1):</strong> does not depend on the <strong>input size</strong>, the time it takes to perform an operation is <strong>constant</strong>. Example: get the length in <strong>python list</strong></p><pre>&gt;&gt;&gt; numbers  =  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]<br>&gt;&gt;&gt; len(numbers)<br>15</pre><p><strong>O(log n):</strong> When the <strong>size</strong> of a collection <strong>increases</strong>, the time it takes to perform an operation increases <strong>logarithmically. </strong>Example: Binary search.</p><p><strong>O(n):</strong> The time it takes to perform an operation is directly related to the <strong>number of items in the collection</strong>. Example: <strong>max </strong>&amp; <strong>min</strong> operation in <strong>python list</strong></p><pre>&gt;&gt;&gt; numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]<br>&gt;&gt;&gt; max(numbers)<br>15</pre><p><strong>O(n square): </strong>Quadratic A slow sorting algorithm. Example selection sort</p><p><strong>O(n!): </strong>A really slow algorithm, Example: the traveling salesperson</p><h3>Examples to have better understanding:</h3><p>looking through a list in python for a particular item is <strong>O(n)</strong>. to better understand this concept, let’s take look at the following example:</p><pre>&gt;&gt;&gt; def function(n):<br>...            for i in range(n):<br>...                    print(i)</pre><p>In the preceding function, the <strong>print</strong> statement will be executed <strong>n(</strong>input size<strong>)</strong> times. Loop speed will depend on <strong>n </strong>, so its complexity that’s expressed using the <strong>big O notation</strong> will be <strong>O(n)</strong>.</p><p>If the function has conditions, the correct notation to keep is the highest one, as follows:</p><pre>&gt;&gt;&gt; def function(n, print_count=False):<br>...         if print_count:   <br>...                 print(&#39;count: &#39;, n)    <br>...         else:<br>...                 for i in range(n):<br>...                         print(i)<br>...</pre><p>In this example, the function could be <strong>O(1)</strong> or <strong>O(n)</strong>, depending on the value of the <strong>print_count</strong> argument. The worst case is <strong>O(n)</strong>, so the whole function complexity is <strong>O(n)</strong>.</p><p><strong>O(1)</strong> is <strong>fast</strong>. <strong>O(n square)</strong> is <strong>slow</strong>. <strong>O(n!)</strong> is <strong>very slow</strong>.</p><h3>Big O Establishes a Worst-Case Run Time</h3><p>Suppose you’re using simple search to look for a person in the phone book. You know that simple search takes <strong>O(n)</strong> time to run, which means in the <strong>worst case</strong>, you’ll have to look through every single entry in your phone book.</p><p>In this case, you’re looking for Ayoub. This handsome guy is the first<br>entry in your phone book. So you didn’t have to look at every entry you<br>found it on the first try. Did this algorithm take <strong>O(n)</strong> time? Or did it take <strong>O(1)</strong> time because you found the person on the first try? Simple search still takes <strong>O(n) </strong>time. In this case, you found what you were looking for instantly. That’s the <strong>best-case scenario</strong>. But <strong>Big O notation</strong> is about the <strong>worst-case scenario</strong>. So you can say that, in the <strong>worst case</strong>, you’ll have to look at every entry in the phone book once. That’s <strong>O(n)</strong> time. It’s a reassurance.you know that simple search will never be slower than <strong>O(n) </strong>time.</p><h3>How Memory Works?</h3><p>Imagine you have a big drawer in your home, and each drawer can hold one<br>item in it and you want to store two things, so you ask your mother<br>which drawer you can put your items in and your mom tells you which one<br>to put them ! This is basically how your computer’s memory works. Your<br>computer looks like a giant set of drawers, and each drawer has an<br>address.whenever you want to store an item in memory, you ask the<br>computer for some spaces, and it gives you an address where you can<br>store your item. If you want to store multiple items, there are two<br>basic ways to do so: <strong>arrays </strong>and <strong>lists</strong>.<br>I’ll talk about arrays and lists next, as well as the pros and cons of<br>each. There isn’t one right way to store items for every use case, so<br>it’s important to know the differences.</p><h3>What is Linked-List and Array?</h3><p>Sometimes you need to store a list of elements in memory. Suppose you’re<br>writing an app to manage your todos. You’ll want to store the todos as a<br>list in memory. Should you use an <strong>array</strong>, or a <strong>linked list</strong>? Let’s store the todos in an array first, because it’s easier to grasp. Using an array means all your tasks are stored <strong>contiguously</strong><br>(right next to each other) in memory.Now suppose you add three task and<br>you want to add a fourth task. But the next drawer is taken up by<br>someone else’s stuff!It’s like going to a movie with your friends and<br>finding a place to sit but another friend joins you, and there’s no<br>place for them. You have to move to a new spot where you all fit .In<br>this case, you need to ask your computer for a different chunk of memory<br>that can fit four tasks. Then you need to move all your tasks there If<br>another friend comes by, you’re out of room again and you all have to<br>move a second time! What a pain. Similarly, adding new items to an array<br>can be a big pain. If you’re out of space and need to move to a new<br>spot in memory every time, adding a new item will be really slow. One<br>easy fix is to “hold seats”: even if you have only 3 items in your task<br>list, you can ask the computer for 10 slots, just in case. Then you can<br>add 10 items to your task list without having to move. This is a good<br>workaround, but you should be aware of a couple of downsides</p><ul><li><em>You may not need the extra slots that you asked for, and then that memory will be wasted. You aren’t using it, but no one else can use it either</em></li><li><em>You may add more than 10 items to your task list and have to move anyway. So it’s a good workaround, but it’s not a perfect solution. Linked lists solve this problem of adding items</em></li></ul><h3>Linked Lists</h3><p>With linked lists, your items can be anywhere in memory. Each item<br>stores the address of the next item in the list. A bunch of random<br>memory addresses are linked together. It’s like a treasure hunt. You go<br>to the first address, and it says, “The next item can be found at<br>address 123.” So you go to address 123, and it says, “The next item can<br>be found at address 847,” and so on. Adding an item to a linked list is<br>easy: you stick it anywhere in memory and store the address with the<br>previous item. <strong>With linked lists, you never have to move your items</strong>.<br>You also avoid another problem. Let’s say you go to a popular movie<br>with five of your friends. The six of you are trying to find a place to<br>sit, but the theater is packed. There aren’t six seats together. Well,<br>sometimes this happens with arrays. Let’s say you’re trying to find<br>10,000 slots for an array. Your memory has 10,000 slots, but it doesn’t<br>have 10,000 slots together. You can’t get space for your array! A linked<br>list is like saying, “Let’s split up and watch the movie.” If there’s<br>space in memory, you have space for your linked list. If linked lists<br>are so much better at inserts, what are arrays good for?</p><h3>Arrays</h3><p>Websites with top-10 lists use a scummy tactic to get more pages.<br>views. Instead of showing you the list on one page, they put one item on<br>Each page and make you click Next to get to the next item in the list.<br>For example, Top 10 Best TV Villains won’t show you the entire list on<br>one page. Instead, you start at #10 (Newman), and you have to click Next.<br>on each page to reach #1 (Gustavo Fring). This technique gives the<br>websites 10 whole pages on which to show you ads, but it’s boring to<br>Click Next 9 times to get to #1. It would be much better if the whole<br>The list was on one page and you could click each person’s name for more.<br>info. Linked lists have a similar problem. Suppose you want to read the<br>last item in a linked list. You can’t just read it, because you don’t<br>Know what address it’s at. Instead, you have to go to item #1 to get the<br>address for item #2. Then you have to go to item #2 to get the address.<br>for item #3. And so on, until you get to the last item. <strong>Linked lists are great, if you’re going to read all the items one at a time</strong>: you can read one item, follow the address to the next item, and so on. <strong>But if you’re going to keep jumping around, linked lists are terrible</strong>. Arrays<br>are different. You know the address for every item in your array. For<br>For example, suppose your array contains five items, and you know it starts<br>at address 00. What is the address of item #5? Simple math tells you:<br>It’s 04.<strong>Arrays are great if you want to read random elements, because you can look up any element in your array instantly</strong>. With<br>a linked list, the elements aren’t next to each other, so you can’t<br>instantly calculate the position of the fifth element in memory you have<br>to go to the first element to get the address to the second element,<br>then go to the second element to get the address of the third element,<br>And so on until you get to the fifth element.</p><h3>summary</h3><p>This article was about the Big-O notation of the key operations of data<br>structures . The big-o notation is essentially a way to measure the time<br>complexity of an operation. The article also illustrated linked list<br>and array and how these manage data in memory.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa3bed092cc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>