<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Heap on Michele Bologna</title>
    <link>https://www.michelebologna.net/tags/heap/</link>
    <description>Recent content in Heap on Michele Bologna</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 02 Feb 2016 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.michelebologna.net/tags/heap/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Spotify puzzles: round two</title>
      <link>https://www.michelebologna.net/2016/spotify-puzzles-round-two/</link>
      <pubDate>Tue, 02 Feb 2016 00:00:00 +0000</pubDate>
      <guid>https://www.michelebologna.net/2016/spotify-puzzles-round-two/</guid>
      <description>&lt;p&gt;Some months ago, &lt;a href=&#34;https://www.michelebologna.net/2015/05/spotify-puzzles-round-one/&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;I began challenging myself with &lt;strong&gt;Spotify puzzles&lt;/strong&gt;&lt;/a&gt;: at that time I was dealing with an easy problem; now, the difficulty has increased. The round two consists in the typical &amp;ldquo;&lt;em&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Selection_algorithm&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Selection problem&lt;/a&gt;&lt;/em&gt;&amp;rdquo;: given an array of values, find the max (or min) &lt;code&gt;k&lt;/code&gt; values. I decided to still use Python and to use its &lt;strong&gt;heapq&lt;/strong&gt; module to store values in a binary max-heap data structure, and then remove exactly &lt;code&gt;k&lt;/code&gt; values from the top of the heap. This approach will guarantee that the total time complexity of the algorithm will be &lt;code&gt;O(n log k)&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
