Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Runtime Complexity of Python List Methods [Easy Table Lookup]

#1
Runtime Complexity of Python List Methods [Easy Table Lookup]

<div><p><strong>What’s the runtime complexity of various list methods? </strong></p>
<p>The following table summarizes the runtime complexity of all list methods.</p>
<p>Assume that the length of the data type is defined as <code>n</code> (that is—<code>len(data_type)</code>). You can now categorize the asymptotic complexity of the different complexity functions as follows:</p>
<figure class="wp-block-table is-style-stripes">
<table>
<thead>
<tr>
<th>Operation</th>
<th>Example</th>
<th>Complexity</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://blog.finxter.com/python-list-index/" target="_blank" rel="noreferrer noopener">Index</a></td>
<td><code>l[i]</code></td>
<td><em>O(1)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/resolve-indexerror-list-assignment-index-out-of-range/" target="_blank" rel="noreferrer noopener">Store</a></td>
<td><code>l[i] = 42</code></td>
<td><em>O(1)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-length-whats-the-runtime-complexity-of-len/" target="_blank" rel="noreferrer noopener">Length</a></td>
<td><code>len(l)</code></td>
<td><em>O(1)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-append/" target="_blank" rel="noreferrer noopener">Append</a></td>
<td><code>l.append(42)</code></td>
<td><em>O(1)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-pop/" target="_blank" rel="noreferrer noopener">Pop</a></td>
<td><code>l.pop()</code></td>
<td><em>O(1)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-clear/" target="_blank" rel="noreferrer noopener">Clear</a></td>
<td><code>l.clear()</code></td>
<td><em>O(1)</em></td>
</tr>
<tr>
<td><a rel="noreferrer noopener" href="https://blog.finxter.com/introduction-to-slicing-in-python/" target="_blank">Slicin</a><a href="https://blog.finxter.com/introduction-to-slicing-in-python/" target="_blank" rel="noreferrer noopener">g</a></td>
<td><code>l[a:b]</code></td>
<td><em>O(b-a)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-extend/" target="_blank" rel="noreferrer noopener">Extend</a></td>
<td><code>l1.extend(l2)</code></td>
<td><em>O(len(l1)+len(l2))</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-lists/" target="_blank" rel="noreferrer noopener">Constructor</a></td>
<td><code>list(iter)</code></td>
<td><em>O(len(iter))</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-string-contains/" target="_blank" rel="noreferrer noopener">Equality</a></td>
<td><code>l1 == l2</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-slice-assignment/" target="_blank" rel="noreferrer noopener">Slice Assign</a></td>
<td><code>l[a:b] = ...</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-remove/" target="_blank" rel="noreferrer noopener">Delete</a></td>
<td><code>del l[i]</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-remove/" target="_blank" rel="noreferrer noopener">Remove</a></td>
<td><code>l.remove(...)</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-lists/" target="_blank" rel="noreferrer noopener">Membership</a></td>
<td><code>x in l / x not in l</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-copy/" target="_blank" rel="noreferrer noopener">Copy</a></td>
<td><code>l.copy()</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-pop/" target="_blank" rel="noreferrer noopener">Pop</a></td>
<td><code>l.pop(0)</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/how-to-find-the-minimum-of-a-list-of-lists-in-python/" target="_blank" rel="noreferrer noopener">Min</a></td>
<td><code>min(l)</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/how-to-find-the-max-of-list-of-lists-in-python/" target="_blank" rel="noreferrer noopener">Max</a></td>
<td><code>max(l)</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-reverse/" target="_blank" rel="noreferrer noopener">Reverse</a></td>
<td><code>l.reverse()</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-loops/" target="_blank" rel="noreferrer noopener">Iterate</a></td>
<td><code>for x in l:</code></td>
<td><em>O(n)</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-sort/" target="_blank" rel="noreferrer noopener">Sort</a></td>
<td><code>l.sort()</code></td>
<td><em>O(n log(n))</em></td>
</tr>
<tr>
<td><a href="https://blog.finxter.com/python-list-concatenation-add-vs-inplace-add-vs-extend/" target="_blank" rel="noreferrer noopener">Multiply</a></td>
<td><code>l*k</code></td>
<td><em>O(n k)</em></td>
</tr>
</tbody>
</table>
</figure>
<p>Need to learn more about these methods? Watch me giving you a quick overview of all Python list methods:</p>
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio">
<div class="wp-block-embed__wrapper">
<div class="ast-oembed-container"><iframe title="Python List Methods" width="1400" height="788" src="https://www.youtube.com/embed/4j8B9a_kZY4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>
</div>
</figure>
<p><a rel="noreferrer noopener" href="https://blog.finxter.com/python-list-methods/" target="_blank">You can read more about all methods in my detailed tutorial on the Finxter blog.</a></p>
<p>Here’s your free PDF cheat sheet showing you all Python list methods on one simple page. Click the image to download the high-resolution PDF file, print it, and post it to your office wall:</p>
<div class="wp-block-image">
<figure class="aligncenter size-large"><a href="https://blog.finxter.com/wp-content/uploads/2020/04/Python-List-Methods-Cheat-Sheet.pdf" target="_blank" rel="noopener noreferrer"><img src="https://blog.finxter.com/wp-content/uploads/2020/04/Python-List-Methods-Cheat-Sheet.jpg" alt="" class="wp-image-7544" srcset="https://blog.finxter.com/wp-content/uploads/2020/04/Python-List-Methods-Cheat-Sheet.jpg 670w, https://blog.finxter.com/wp-content/uplo...31x300.jpg 231w" sizes="(max-width: 670px) 100vw, 670px" /></a></figure>
</div>
<div class="wp-block-buttons aligncenter">
<div class="wp-block-button"><a class="wp-block-button__link has-background has-vivid-cyan-blue-background-color" href="https://blog.finxter.com/wp-content/uploads/2020/04/Python-List-Methods-Cheat-Sheet.pdf" style="border-radius:9px" target="_blank" rel="noreferrer noopener">Instant PDF Download [100% FREE]</a></div>
</div>
<h2>Where to Go From Here?</h2>
<p>Enough theory, let’s get some practice!</p>
<p>To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?</p>
<p><strong>Practice projects is how you sharpen your saw in coding!</strong></p>
<p>Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?</p>
<p>Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.</p>
<p>Join my free webinar <a rel="noreferrer noopener" href="https://blog.finxter.com/webinar-freelancer/" target="_blank">“How to Build Your High-Income Skill Python”</a> and watch how I grew my coding business online and how you can, too—from the comfort of your own home.</p>
<p><a href="https://blog.finxter.com/webinar-freelancer/" target="_blank" rel="noreferrer noopener">Join the free webinar now!</a></p>
</div>


https://www.sickgaming.net/blog/2020/05/...le-lookup/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016