<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>LFU on Ito Archives</title>
    <link>https://itoschum.me/tags/lfu/</link>
    <description>Recent content in LFU on Ito Archives</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 04 Sep 2021 17:22:00 -0400</lastBuildDate>
    <atom:link href="https://itoschum.me/tags/lfu/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>C&#43;&#43; Implementation of LRU &amp; LFU Cache</title>
      <link>https://itoschum.me/logs/log_07/</link>
      <pubDate>Sat, 04 Sep 2021 17:22:00 -0400</pubDate>
      <guid>https://itoschum.me/logs/log_07/</guid>
      <description>&lt;h2 id=&#34;lru-least-recently-used-cache&#34;&gt;LRU (Least Recently Used) Cache&lt;/h2&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Referring to LeetCode Q146 &lt;a href=&#34;https://leetcode.com/problems/lru-cache/&#34;&gt;https://leetcode.com/problems/lru-cache/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h3 id=&#34;description&#34;&gt;Description&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;LRUCache(int capacity)&lt;/code&gt; Initialize the LRU cache with positive size capacity.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;int get(int key)&lt;/code&gt; Return the value of the key if the key exists, otherwise return -1.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;void put(int key, int value)&lt;/code&gt; Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used&lt;/li&gt;&#xA;&lt;li&gt;The functions &lt;code&gt;get&lt;/code&gt; and &lt;code&gt;put&lt;/code&gt; must each run in &lt;code&gt;O(1)&lt;/code&gt; average time complexity.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;data-structure-used&#34;&gt;Data Structure Used&lt;/h3&gt;&#xA;&lt;p&gt;To satisfy the &lt;code&gt;O(1)&lt;/code&gt; average time complexity for &lt;code&gt;get&lt;/code&gt; and &lt;code&gt;put&lt;/code&gt;,&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
