<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>devkuma – Data Structure</title>
    <link>https://www.devkuma.com/en/tags/data-structure/</link>
    <image>
      <url>https://www.devkuma.com/en/tags/data-structure/logo/180x180.jpg</url>
      <title>Data Structure</title>
      <link>https://www.devkuma.com/en/tags/data-structure/</link>
    </image>
    <description>Recent content in Data Structure on devkuma</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>kc@example.com (kc kim)</managingEditor>
    <webMaster>kc@example.com (kc kim)</webMaster>
    <copyright>The devkuma</copyright>
    
	  <atom:link href="https://www.devkuma.com/en/tags/data-structure/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Explanation of the Stack Data Structure</title>
      <link>https://www.devkuma.com/en/docs/data-structure/stack/</link>
      <pubDate>Sun, 10 Apr 2022 01:49:00 +0900</pubDate>
      <author>kc@example.com (kc kim)</author>
      <guid>https://www.devkuma.com/en/docs/data-structure/stack/</guid>
      <description>
        
        
        &lt;h2 id=&#34;concept-of-a-stack&#34;&gt;Concept of a Stack&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A stack means a pile of things.&lt;/li&gt;
&lt;li&gt;It is a LIFO(Last In First Out) data structure where data can be inserted and removed only from one end.
&lt;ul&gt;
&lt;li&gt;The most recently added data is removed first.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;structure-of-a-stack&#34;&gt;Structure of a Stack&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Top of stack: top&lt;/li&gt;
&lt;li&gt;Bottom of stack: not needed&lt;/li&gt;
&lt;li&gt;Element, item&lt;/li&gt;
&lt;li&gt;Insert/delete operations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/stack-1.png&#34; alt=&#34;Stack&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;stack-operations&#34;&gt;Stack Operations&lt;/h2&gt;
&lt;p&gt;A stack follows LIFO(Last In First Out). In other words, the item most recently added to the stack is the first item to be removed.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;push(x): adds the given element x to the top of the stack.&lt;/li&gt;
&lt;li&gt;pop(): if the stack is not empty, removes and returns the top element.&lt;/li&gt;
&lt;li&gt;isEmpty(): returns true if the stack is empty, otherwise false.&lt;/li&gt;
&lt;li&gt;peek(): if the stack is not empty, returns the top element without removing it.&lt;/li&gt;
&lt;li&gt;isFull(): returns true if the stack is full, otherwise false.&lt;/li&gt;
&lt;li&gt;size(): returns the number of all elements in the stack.&lt;/li&gt;
&lt;li&gt;display(): outputs all elements in the stack.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;uses-of-a-stack&#34;&gt;Uses of a Stack&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Function calls&lt;/li&gt;
&lt;li&gt;Stacks are useful when using recursive algorithms.
&lt;ul&gt;
&lt;li&gt;Recursive algorithms
&lt;ul&gt;
&lt;li&gt;When functions must be called recursively, temporary data is pushed onto the stack.&lt;/li&gt;
&lt;li&gt;When returning from recursive functions and performing backtracking, the temporary data pushed onto the stack must be popped.&lt;/li&gt;
&lt;li&gt;A stack makes this sequence of actions intuitive.&lt;/li&gt;
&lt;li&gt;A stack also makes it possible to implement recursive algorithms in an iterative form.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Web browser history(back button)&lt;/li&gt;
&lt;li&gt;Undo&lt;/li&gt;
&lt;li&gt;Creating reversed strings&lt;/li&gt;
&lt;li&gt;Checking parentheses in expressions(parentheses checks for operator precedence)
&lt;ul&gt;
&lt;li&gt;Example: determining a Valid Parenthesis String(VPS)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Calculators(postfix notation calculation)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/stack-2.png&#34; alt=&#34;Stack use cases&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://gmlwjd9405.github.io/2018/08/03/data-structure-stack.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Data Structure | What Is a Stack?&lt;i class=&#34;fas fa-external-link-alt&#34;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </description>
      
      <category>Data Structure</category>
      
      <category>Stack</category>
      
    </item>
    
    <item>
      <title>Bloom Filter Data Structure Explained Simply</title>
      <link>https://www.devkuma.com/en/docs/data-structure/bloom-filter/</link>
      <pubDate>Fri, 23 Jun 2023 14:14:30 +0900</pubDate>
      <author>kc@example.com (kc kim)</author>
      <guid>https://www.devkuma.com/en/docs/data-structure/bloom-filter/</guid>
      <description>
        
        
        &lt;h2 id=&#34;what-is-a-bloom-filter&#34;&gt;What Is a Bloom Filter?&lt;/h2&gt;
&lt;p&gt;A Bloom Filter is an efficient &lt;strong&gt;probabilistic data structure&lt;/strong&gt;. It is used to test whether an element is a member of a set.
Bloom filters are not as commonly used as binary trees or hash maps, but they are used from time to time.&lt;/p&gt;
&lt;p&gt;The basic concept is very simple and is especially useful in the following situation.&lt;/p&gt;
&lt;p&gt;When there is a Set and an Element, a Bloom filter can quickly tell whether a specific Element exists in that Set. When asked whether a specific Element exists in a specific Set, a Bloom filter can give two answers.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The specific Element does not exist in the specific Set.&lt;/li&gt;
&lt;li&gt;The specific Element may exist in the specific Set.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These two answers mean that when an Element does not exist in the filter, the answer can be given with certainty, but when it appears to exist, the answer is not certain.&lt;/p&gt;
&lt;p&gt;The reason it is used despite being inexact is that a Bloom Filter is a space-efficient data structure. The memory area it uses can be fixed from the beginning.
The unit of a Bloom Filter element is a bit. On a 32-bit machine, an integer can contain up to 32 elements.&lt;/p&gt;
&lt;h2 id=&#34;bloom-filter-structure&#34;&gt;Bloom Filter Structure&lt;/h2&gt;
&lt;p&gt;Now let&amp;rsquo;s explain how a Bloom filter works. A Bloom filter consists of one array of bits and n hash functions.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/bloom-filter-0.png&#34; alt=&#34;bloom-filter&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;n Hash functions&lt;/strong&gt;&lt;br&gt;
A Bloom Filter uses multiple hash functions.
A hash function takes a value and turns it into one number among the indexes of an array.
The number of hash functions can be set to several, and each function uses a different hashing method.&lt;/p&gt;
&lt;p&gt;The functions are used for the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add a new Element to a Set.&lt;/li&gt;
&lt;li&gt;Check whether an input Element exists in a Set.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Array with multiple values&lt;/strong&gt;&lt;br&gt;
A Bloom filter is made of an array with multiple values. A value is passed through hash functions, and the resulting indexes are changed to numbers.
The example uses a Bloom Filter with an array size of 20.&lt;/p&gt;
&lt;h3 id=&#34;adding-a-new-element-to-a-bloom-filter&#34;&gt;Adding a New Element to a Bloom Filter&lt;/h3&gt;
&lt;p&gt;For &amp;ldquo;Element 1&amp;rdquo;, the Bloom filter gets indexes through three functions and changes the values at those indexes from 0 to 1.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/bloom-filter-1.png&#34; alt=&#34;bloom-filter&#34;&gt;&lt;/p&gt;
&lt;p&gt;For the second value, &amp;ldquo;Element 2&amp;rdquo;, it does the same: gets indexes through three functions and changes the values at those indexes from 0 to 1.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/bloom-filter-2.png&#34; alt=&#34;bloom-filter&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;checking-a-new-element-in-a-bloom-filter&#34;&gt;Checking a New Element in a Bloom Filter&lt;/h3&gt;
&lt;p&gt;To check whether &amp;ldquo;Element 3&amp;rdquo; exists, pass it through three functions.
&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/bloom-filter-3.png&#34; alt=&#34;bloom-filter&#34;&gt;&lt;/p&gt;
&lt;p&gt;Hash functions A, B, and C point to 0, 1, and 0 respectively. If even one of them includes 0, the input &amp;ldquo;Element 3&amp;rdquo; does not exist.&lt;/p&gt;
&lt;p&gt;This time, pass &amp;ldquo;Element 4&amp;rdquo; through three functions to check whether it exists.
&lt;img src=&#34;https://www.devkuma.com/docs/data-structure/bloom-filter-4.png&#34; alt=&#34;bloom-filter&#34;&gt;&lt;/p&gt;
&lt;p&gt;Functions A, B, and C all point to values of 1, but in reality only &amp;ldquo;Element 1&amp;rdquo; and &amp;ldquo;Element 2&amp;rdquo; exist, and &amp;ldquo;Element 4&amp;rdquo; does not.&lt;/p&gt;
&lt;p&gt;In this way, a Bloom filter can say with certainty that a non-existing Element does not exist, but for an Element that appears to exist, it can only answer probabilistically and not exactly.&lt;/p&gt;
&lt;h2 id=&#34;examples-of-using-a-bloom-filter&#34;&gt;Examples of Using a Bloom Filter&lt;/h2&gt;
&lt;p&gt;Why use something that is not certain? The reason is that a Bloom filter is very memory efficient and fast.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at two cases where Bloom filters are used.&lt;/p&gt;
&lt;h3 id=&#34;cdn&#34;&gt;CDN&lt;/h3&gt;
&lt;p&gt;A CDN stores data requested by many users in CDN servers close to users so that it can be downloaded easily.&lt;/p&gt;
&lt;p&gt;The CDN will cache requests. Suppose it immediately caches data on the first request.
Then it would cache everything even for resources requested only once, which is inefficient.&lt;/p&gt;
&lt;p&gt;According to Akamai, a company in the CDN business, about three-quarters of data is requested only once.
The idea they came up with was this: when the first request arrives, mark it only in the Bloom filter and deliver the resource to the user without caching it in the CDN.
When the same resource is requested again, the Bloom filter can be checked to see whether it was requested before.
This makes it possible to know that the resource has been requested multiple times, and caching begins at that point.&lt;/p&gt;
&lt;h3 id=&#34;key-value-store&#34;&gt;Key Value Store&lt;/h3&gt;
&lt;p&gt;When fetching a Key from a key-value store, it checks whether the Row exists.
If the Key does not exist, every Row may need to be checked, which is the slowest worst case. If the Key exists, it may be found quickly by checking an index, or after looking at the index several times.
However, if the Key does not exist, in the worst case all existing indexes and datasets must be checked to confirm that it is absent.&lt;/p&gt;
&lt;p&gt;In this worst case, a Bloom filter can be used in preparation for requests for non-existing keys. With a Bloom Filter, you can quickly check whether a Key does not exist or may exist, though a small error is possible.&lt;/p&gt;
&lt;p&gt;The following data stores are said to use Bloom Filters.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Google Bigtable&lt;/li&gt;
&lt;li&gt;HBase&lt;/li&gt;
&lt;li&gt;Redis&lt;/li&gt;
&lt;li&gt;Cassandra&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;/ul&gt;

      </description>
      
      <category>Data Structure</category>
      
    </item>
    
    <item>
      <title>Data Structure</title>
      <link>https://www.devkuma.com/en/docs/data-structure/</link>
      <pubDate>Sun, 10 Apr 2022 01:49:00 +0900</pubDate>
      <author>kc@example.com (kc kim)</author>
      <guid>https://www.devkuma.com/en/docs/data-structure/</guid>
      <description>
        
        
        
      </description>
      
      <category>Data Structure</category>
      
    </item>
    
  </channel>
</rss>
