<?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 Miras Baisbay on Medium]]></title>
        <description><![CDATA[Stories by Miras Baisbay on Medium]]></description>
        <link>https://medium.com/@mbaisbay?source=rss-daf884377020------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SO5jheOr8bsNHakB</url>
            <title>Stories by Miras Baisbay on Medium</title>
            <link>https://medium.com/@mbaisbay?source=rss-daf884377020------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:18:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mbaisbay/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[How to make Qorzhyn-Qalta? (revised version)]]></title>
            <link>https://medium.com/@mbaisbay/how-to-make-qorzhyn-qalta-revised-version-41d9936240c9?source=rss-daf884377020------2</link>
            <guid isPermaLink="false">https://medium.com/p/41d9936240c9</guid>
            <dc:creator><![CDATA[Miras Baisbay]]></dc:creator>
            <pubDate>Sun, 01 Oct 2023 13:00:30 GMT</pubDate>
            <atom:updated>2023-10-01T13:00:30.984Z</atom:updated>
            <content:encoded><![CDATA[<h3>Instructions</h3><h4>Step 1. Gather the materials needed</h4><p>To make a Qalta, we will need the following materials:</p><p>· Felt fabric (two colors), (102x62 cm and 60x40 cm)</p><p>· Hot glue</p><p>· Scissors, pencil, thread, needle, sewing pins</p><p>· Ruler — 60 cm long</p><p>· Decorative accessories (beads, self-adhesive crystals)</p><p>· Pre-printed stencils of Kazakh ornaments</p><p>· decorative ribbon or rope</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*g74wVUewmWGf7XGY.png" /></figure><h4>Step 2. Make markings and measurements</h4><p>Use a larger material with a size of 102x62 cm to make the base and pockets of the Qalta. For convenience, fold the fabric in half so that you end up with a double rectangle measuring 51x31 cm. Apply the markings on the felt sheet according to the measures shown on the scheme. All marks should be only on one side of the fabric so that the other side always remains clean.</p><ul><li>You can modify the dimensions shown in the diagram</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/0*d54Kyxy1o1qWJNRA.png" /></figure><h4>Step 3. Draw the forming lines</h4><p>Use a pencil and ruler to connect the measurement marks from the previous step. Draw two lines forming pockets on one side of the rectangle, the other rectangle will remain untouched. You can also draw a line on the fold separating the two rectangles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/0*0l-zv7oGyBCIS6Eb.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/0*_kBtMcRHwVVm74S2.png" /></figure><h4>Step 4. Cut the fabric</h4><p>Use a pencil and ruler to connect the measurement marks from the previous step. Draw two lines forming pockets on one side of the rectangle, and the other rectangle will remain untouched. You can also draw a line on the fold separating the two rectangles. Cut out the ornaments pre-printed on paper. Then transfer its shape to a fabric of a different color, tracing its contour with a pencil. If it is inconvenient for you to redraw the ornament on the fabric with paper, you can use cardboard or sewing pins to fix the paper. After that, cut the fabric along the lines of the ornament. You will need to prepare two identical ornaments, one for each pocket. Cut the fabric along the lines you prepared in the previous step. The photo above shows the result of the cutting process. At the end, you should have one big rectangle and two small ones.</p><h4>Step 5. Prepare decorative Kazakh ornaments</h4><p>Cut out the ornaments pre-printed on paper. Then transfer its shape to a fabric of a different color, tracing its contour with a pencil. If it is inconvenient to redraw the ornament on the fabric with paper, you can use cardboard or sewing pins to fix the paper. After that, cut the fabric along the lines of the ornament. You will need to prepare two identical ornaments, one for each pocket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/0*yHIbZPIN1W2yG1zF.png" /></figure><h4>Step 6. Stitch the fabric</h4><p>Sew the pockets with the base along the red lines, as shown in the diagram below. The middle, with the inner part where the gifts will be placed, remains open and does not need to be sewn. The needlepoint size should be with the smallest interval and the width of the sewing so that when the pockets are turned out, there is not much space left between the connection of the two materials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/0*L9qYkwbxqQPe5Fmk.png" /></figure><h4>Step 7. Turn pockets inside out</h4><p>Turn out both pockets of the Qalta inside out so that the stitching remains on the inside part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/0*e4zRwqbOqYJgBjei.png" /></figure><h4>Step 8. Decorate</h4><p>Ornaments can be decorated with adhesive rhinestones. But it will be stronger if you sew beads to the ornament. In general, the bag can be decorated with any elements at your discretion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*uWRyHJzrMQpJzq7n.png" /></figure><h4>Step 9. Glue the ornaments and decoration</h4><p>Glue the ornaments on both sides of the pockets of Qalta using a glue gun. Before glueing, it is necessary to plug the gun into the outlet and wait 5–7 minutes for the glue to heat up and flow out of it quickly. When using a gun, it is important to observe fire safety measures. Also, at your discretion, you can glue a decorative ribbon to the edges of the Qalta.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*WaPeI2AyBy1tuF1E.png" /></figure><h4>Step 10. Make a zigzag from the ribbon</h4><p>The final touch is to sew or glue the felt loops to the inner open side of the pockets and thread a ribbon as a zigzag through them. The loops are made from a thin rectangular piece of fabric folded in half. The number and thickness of the loops may vary depending on your ribbon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*s1x83mMGhE0SUdtE.png" /></figure><h3>Result:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Vu63LEyF0MK7feZC.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41d9936240c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make Qalta?]]></title>
            <link>https://medium.com/@mbaisbay/how-to-make-qalta-9454382997ea?source=rss-daf884377020------2</link>
            <guid isPermaLink="false">https://medium.com/p/9454382997ea</guid>
            <dc:creator><![CDATA[Miras Baisbay]]></dc:creator>
            <pubDate>Sun, 24 Sep 2023 05:46:51 GMT</pubDate>
            <atom:updated>2023-09-24T06:12:12.297Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Technical Instructions for Qorzhyn-Qalta</strong></h3><h4>Step 1. Gather the materials needed To make a Qalta, and we will need the following materials: </h4><ol><li>Felt fabric (at least two colors) </li><li>Hot glue</li><li>Scissors, pencil, ruler, thread, needle</li><li>Decorative accessories (beads, self-adhesive crystals)</li><li>Pre-printed stencils of Kazakh ornaments</li><li>Decorative ribbon or rope</li></ol><ul><li>Some materials may be replaced at your discretion</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFT6zgitvutL7m2MMstYBw.png" /></figure><h4>Step 2. Make markings and measurements</h4><p>The qalta consists of two pockets (21x31) sewn on two opposite sides of the rectangular base (51x31). Apply the markings on the felt sheet using a ruler and pencil. You need to make sketches for one large rectangle and two smaller ones.</p><ul><li>You can modify the dimensions shown in the diagram.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*lWbCH0_f8HBFAfYDHBd4DQ.png" /></figure><h4>Step 3. Draw the forming lines</h4><p>Use a pencil to connect the measurement marks from the previous step. Fold the felt sheet to get a double layer of fabric. Sketch a large rectangle on one layer and, on the second, a sketch of two pockets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*tW69Yu-e9jwVKHvTnGDDzQ.png" /></figure><h4>Step 4. Cut the fabric</h4><p>Cut the fabric along the lines you prepared in the previous step. The figure on the side shows the result of the cutting process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*od80QmLWvUDPiMeEtLFJgA.png" /></figure><h4>Step 5. Prepare a decorative Kazakh ornament</h4><p>Cut out the ornaments pre-printed on paper. Then, transfer the shape of the ornament to the fabric, tracing its contour with a pencil. After that, cut the fabric along the assigned lines of the ornament. You will need to prepare two identical ornaments, one for each pocket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*OnpPkiSQpGA5kNYmdIAJFA.png" /></figure><h4>Step 6. Stitch the fabric</h4><p>Sew parts of size 21x31 to the base of the Qalta to make two pockets for the bag while leaving the middle and the inside of the part where the gifts will be placed not sewn. The needlepoint size should be with the smallest interval and the width of the sewing so that when the pockets are turned out, there is not much space left between the connection of the two materials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*nDLvhjjQDnC1zbNjsg-XSg.png" /></figure><h4>Step 7. Turn pockets inside out</h4><p>Turn out both pockets of the Qalta inside out so that the stitching remains on the inside part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*cLHjrK6ntu2_JlxI53nNpw.png" /></figure><h4>Step 8. Decorate</h4><p>Decorate the edges of the Qalta with a stripe by glueing it with the glue gun. Ornaments can be adorned using adhesive rhinestones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*9FgOfUmMMRpR6VYIhA7vaA.png" /></figure><h4>Step 9. Glue the ornaments and decoration</h4><p>Glue the ornaments on both sides of the pockets of Qalta using a glue gun. Before glueing, it is necessary to plug the gun into the outlet and wait 5–7 minutes for the glue to heat up and flow out of it quickly. When using a gun, it is important to observe fire safety measures and not get burned, as the heated glue reaches a high temperature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*R9f3ixxp2R92QKXpUgHZow.png" /></figure><h4>Step 10. Make a zigzag from the ribbon</h4><p>The final touch is to sew the felt loops to the inner open side of the pockets and thread a ribbon in as a zigzag through them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*qVbX3DvVPgacZEhlfSwPpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*05SuAylyJaO86N8iuxzN9A.png" /></figure><h3><strong>Result:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcv31cMK2e2fJCytHfMYJw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9454382997ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cracking Hash Tables and Maps]]></title>
            <link>https://medium.com/@mbaisbay/cracking-hash-tables-and-maps-fa8a8a61e27e?source=rss-daf884377020------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa8a8a61e27e</guid>
            <dc:creator><![CDATA[Miras Baisbay]]></dc:creator>
            <pubDate>Thu, 27 Apr 2023 05:23:01 GMT</pubDate>
            <atom:updated>2023-04-27T05:23:01.888Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Intro to Hash Tables</strong></h3><h4><strong>Recall that the set data type is used to store items where:</strong></h4><ul><li>Insertion order doesn’t matter</li><li>Duplicates aren’t stored</li></ul><p>Main goal: Efficiency in insertion, deletion, and lookup</p><h4><strong>Naive implementation: Arrays</strong></h4><ul><li>While these are probably the easiest ways to implement sets, they are very inefficient — linear lookup, insertion, removal</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*1sedvYULUbHDk8sa3gve1w.png" /><figcaption>Array implementation</figcaption></figure><h4><strong>A better approach: Balanced BSTs</strong></h4><ul><li>Should only take Ө(log(n)) time for lookup, insertion, and removal</li><li>But can we do even better … maybe even Ө(1)?</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*0ijeH3nhTCJvyGTQJ15TyQ.png" /><figcaption>BST implementation</figcaption></figure><h4><strong>Hash Tables: The Basic Idea</strong></h4><ul><li>If we could store items in an array, and we always knew exactly where to find the item, lookup (and insertion &amp; removal) would take constant time</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*BI5-OlaxDpcLm1ns3TrBaQ.png" /></figure><p>abs(x) % 10 → index (we use mod 10 because there are 10 buckets)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*oLe6M2kfYQnO9rRKwuRSYQ.png" /></figure><h4><strong>Hash Functions:</strong></h4><ul><li>A hash function is used to determine what bucket index to use for the lookup, insertion, and removal of specific items of the given item type T</li></ul><p>hash: T → integer</p><p>bucket_index(x) = abs(hash(x)) % num_buckets</p><p>ASCII: ‘a’ = 97</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*bVp20JELUpFAlowUD1qNGQ.png" /></figure><h4><strong>Hashing problems:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*WCENuxmvbTvaVBQzOcWH0A.png" /><figcaption>This is hash collision when there are two or more items in one bucket_index</figcaption></figure><h4><strong>Potential problems and solutions:</strong></h4><ul><li>What if two different items belong in the same bucket? &lt;— Hash collision</li><li>What if we have more items than buckets?</li></ul><h4><strong>Collusion Resolution Approaches:</strong></h4><ul><li><strong>Closed addressing with Separate Chaining:</strong> Each bucket can store multiple items (often using a linked list)</li><li><strong>Open addressing: </strong>Items can be put in other buckets if their “home bucket” is occupied</li><li><strong>Linear probing </strong>— look for the next open bucket</li><li><strong>Double, triple, etc hashing </strong>— use a secondary, tertiary, etc. hash function if the first results in a collision</li></ul><h4>Insufficient buckets</h4><ul><li>If we don’t have enough buckets to hold all of the items, or if performance is diminished, then we can resize the hash table</li><li>Here, we increase the number of buckets, and re-hash and re-insert all of the elements (Warning!!!: Don’t do this too often, costly at Ө(n))</li></ul><h4>Separate Chaining Example:</h4><ul><li>Storing strings in a hash table with 10 buckets, and using the ASCII code of the first letter as the hash function (‘A’ = 65)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*2mgJ_ZUHlax3Ed1ZG5JiGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*4L3lkl2xup5ym1AfxMMTmQ.png" /></figure><h3>Hash Functions and performances</h3><h4>Hash function properties</h4><p><strong>Hash functions</strong></p><ul><li>Recall that hash functions are used to determine what bucket index in a hash table to use for a given item</li><li>Note that a hash function can’t produce different values for the same or equivalent items — this is an absolute requirement</li><li>However, a hash function does not have to produce different values for different items (though it should try to avoid this)</li></ul><p><strong>Hash Collisions</strong></p><ul><li>Recall that a hash collision is where two different items are supposed to go into the same bucket</li><li>Good hash functions try to minimize the number of hash collisions</li><li>This has the effect of “spreading around” the values to the different buckets (hopefully)</li></ul><p>To illustrate some of these ideas, suppose hash(“abc”) = 42 when you try to initially insert the string “abc” in your hash table, but then you try to look up “abc” later and hash(“abc”) = 43 at that time, then you will not be looking in the proper bucket. This bad behavior is completely forbidden for a hash function.</p><p>However, if hash(“abc”) = 42 and hash(“def”) = 42, and these values will never change for these strings, while it would have been preferable that they gave different values, it is not illegal for the hash function to do this. It is just the case that there will necessarily be a hash collision, and the hash table will have to resolve it somehow (either using separate chaining or open addressing.)</p><p><strong>Is it a “Good” hash function?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*Wypim5dTHJkiU5MHcV0Xpg.png" /></figure><p><strong>Hash functions for other types:</strong></p><ul><li>For items that have multiple members or fields, i.e, struct or class objects, each member or field should contribute to the hash function</li><li>However, sets are often not an appropriate way to store such things, since we have to know the entire state of an item to do a lookup</li><li>Maps are usually more appropriate for storing such things</li></ul><h4>Hash table statistics</h4><p>Common Hash Table Statistics:</p><ul><li><strong>Load factor: </strong>#entries / #buckets</li><li><strong>The standard deviation </strong>of bucket item counts (used with separate chaining)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/0*MgP-dLck-ZWabDkH.jpg" /><figcaption>here’s the formula for the (population) standard deviation for K values:</figcaption></figure><p><strong>Performance Evaluation</strong></p><ul><li>In the best case, lookup (and insertion and deletion) can take a constant Ө(1) time. For example, the target bucket is empty</li><li>In the worst case, lookup (and insertion and deletion) can take a constant Ө(n) time</li><li>Separate chaining — all n items are in the same bucket, and you might have to do all n comparisons</li><li>Open addressing — the first n buckets we look at (starting with the one you hashed to) are all filled with the n items, and you end up performing all n comparisons</li></ul><p><strong>Performance Evaluation — On Average</strong></p><ul><li>However, it only takes constant O(1) time on average, if</li><li>Our hash function is reasonable and we keep the load factor below a threshold through table resizing</li><li>Even though resizing is costly, we don’t have to do it frequently enough over time to impact the overall constant time performance</li></ul><p>It is true that for a single lookup, the worst-case time is O(n). However, things start to look better when we average things out over time, and we amortize to determine how much time we can expect to spend on average for such a lookup after a long sequence of operations on the hash table. If we assume that our hash function is “reasonable”, and that we use resizing (by say, doubling) when things get too crowded, then the average amount of time it takes over a large number of operations comes out to be O(1).</p><p>Now, let’s explain what we mean by a “reasonable” hash function, and why this is important to our analysis.</p><h4>Simple Uniform Hashing Assumption:</h4><ul><li>In our analysis, we assume that the hash function will distribute items uniformly</li><li>Thus, for the load factor alpha = n / <strong>B:</strong></li><li>With separate chaining, each bucket will have size alpha on average, so the average number of comparisons needed for lookup is alpha</li><li>With open addressing, the “filled probability” for any given bucket is alpha, so the number of buckets we need to look through will be bounded above by 1 + alpha + alpha² + alpha³+… = 1 / (1-alpha) In other words, this is a geometric sequence with the first term of 1 and r = alpha where r &lt; 1 (series converges)</li></ul><p>If we make the simple uniform hashing assumption about our hash function, no matter if we are using separate chaining or open addressing, we know that there is a fixed upper bound on the average lookup time (which we call <strong>λ</strong>) as long as we keep the load factor under a certain threshold. We accomplish this via resizing — doubling the number of buckets whenever the threshold is reached.</p><p>While doing a single resize is expensive (O(n)), we won’t need to do it enough to change the overall amortized average operation time of O(1) even if we do a large number of insertions. We will now show that this is indeed the case.</p><h4>Performance Evaluation — Resizing</h4><ul><li>If we keep inserting items, we will eventually have to resize the table to keep the load factor under the given threshold</li><li>Let this threshold be m/B for some fixed m, where B is the initial number of buckets</li><li>If we double the number of buckets on each resize, then we will have B, 2B, 4B, 8B, …, 2^k B buckets over 2^k m item insertions</li><li>We get a “resize penalty” at the points where we insert items m, 2m, 4m, 8m, …, 2^k m</li></ul><p><strong>Adding it up</strong></p><ul><li>Upper bound on total time to insert 2^k m items</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*9-95g1cSmDhaTI24qlapRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*6KyY2NlXzQzN2F_gRLfW1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*rqm14tqiMdhzfyaqbzQcIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*9aqHNPcDnOmKhqmP7yyw8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*7tteBUbrOWDwwxeC0Hf81g.png" /></figure><p>So again, what this shows is that the amortized average time for insertion, over a large number of insertions, is bounded above by a constant. Hence, O(1). Since an insertion can result in a resize penalty, while a remove or a simple lookup will not, we know that insertion will be a little more expensive on average, and so these other operations are also O(1) on average.</p><h3>Implementing Hash Tables in C++</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIvQNNzA1NzK7g2SC-XjoQ.png" /></figure><h3>Intro to Maps</h3><h4><strong>The Map Data Type</strong></h4><ul><li>Maps give us a way to bind values to the keys in a finite set, where the user provides the individual mappings;</li><li>Domain set = keys; Range set = values;</li><li>One key can map to only one value, but multiple keys can map to the same value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FQQlkAp_CI7ppzmhLHfuVA.png" /></figure><ul><li>A map’s content can be seen as a group of key-value pairs where no key is repeated</li></ul><p>{&lt;grapes, 7&gt;; &lt;apples, 3&gt;; &lt;figs, 7&gt;, &lt;bananas, 2&gt;} — our map</p><h4>Maps in Practice</h4><ul><li>Maps are used when:</li></ul><p>— We want to store a large number of records (the values) and look them up based on a single piece of information (the key)</p><p>— We want to store one or more properties (the values) that are associated with a set of given items (the keys)</p><ul><li>Similar to sets, in that the key operations are lookup-based, but maps don’t require we know the entire value of an item to look it up.</li><li>Note that:</li></ul><p>— Maps don’t allow for duplicate keys</p><p>— The key-value pairs are not necessarily stored in any particular order in the map</p><p>— To make a map efficiently, we want to focus on the fast lookup for the keys</p><h4>Implementing Map: Naive Approach</h4><ul><li>We could implement a map using an array or vector of key-value pairs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*cJnqC7V6Qq05FOfquapm3A.png" /></figure><h4>A better approach: BSTs</h4><ul><li>Here, we store the key-value pairs in the tree nodes and do a lookup on the keys.</li><li>We must define an ordering for the key type by implementing before (k1, k2) and equal (k1, k2)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJ5-wiNzQJJ_6wzDExNnXg.png" /></figure><h4>Another good approach: Hash Tables</h4><ul><li>Similarly, we can use hash tables, where hashing and equality comparison are implemented for the key type</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_ya8zme_ZSd206poxRmQA.png" /></figure><p>Here, note that the different map implementations have the same performance as their corresponding set implementations since the lookup is performed in virtually the same way. With a balanced BST version, we can get logarithmic performance. With a hash table version that uses resizing via doubling when the load factor hits a fixed threshold, and assuming the hash function for the keys is reasonable, we can get average amortized constant time.</p><h4>Map Functions and Operations</h4><p><strong>Map Function: Insert()</strong></p><ul><li>Adds the given key and value to the map and returns true if the key isn&#39;t already in the map. Otherwise, the map isn&#39;t modified, and false is returned</li></ul><p>bool insert (const keyT&amp;, const valueT&amp;);</p><ul><li>For the assignment, you will be implementing the following:</li></ul><p>bool insert (const std:: string&amp;, unsigned int);</p><p><strong>Map Insertion</strong></p><ul><li>Defining a new key-value pair adds it to the map:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2yGWAi_g-y5j7t-Up6s0A.png" /></figure><p><strong>Insertion Shouldn’t Overwrite</strong></p><ul><li>However, we do not change the value for a given key using insert if it is already there</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*370uOpxkHzwDgI9ULB3wtA.png" /></figure><h4>Map Accessor Function: at()</h4><ul><li>Provides (a reference to) the value that is associated with the given key. If the map must be const, then the value cannot be modified. An std::out_of_range exception is thrown if the key is not in the map.</li></ul><p>valueT&amp; at( const keyT&amp; );</p><p>const valueT&amp; at (constkeyT&amp; ) const;</p><ul><li>For the assignment, you will be implementing the following:</li></ul><p>unsigned int&amp; at (const std:: string&amp;);</p><p>unsigned int at (const std:: string&amp; ) const;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8WOiPACpDy9ZzR9c6L_aoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ji8359MOtbj0ORXXY2CnCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lXQt0h3hOK4n3GgJXLNbfw.png" /></figure><h4>Map Operator: [] Accessor</h4><ul><li>Similar to at(), the [] operator provides a reference to the value that is associated with the given key. However, if the key is not on the map, a default value for that key will be added to the map.</li></ul><p>valueT&amp; operator[] (const keyT&amp;);</p><ul><li>For the assignment, you will be implementing the following:</li></ul><p>unsigned int&amp; operator[] (const std:: string&amp;);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHEJXrxgWwwM8wxEnvRdrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b-FY1Ky7DKNKek1II-Wajg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lMXYHUaipmVMthYY-6gvrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPC3BSkZOusoqvXkiGhTDA.png" /></figure><p>Map Function: erase()</p><ul><li>Removes the key-value pair from the map for the given key if it is there and returns true</li><li>Otherwise, the map isn&#39;t modified, and false is returned</li></ul><p>bool erase (const keyT&amp;);</p><ul><li>For the assignment, you will be implementing the following:</li></ul><p>bool erase (const std:: string&amp;);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QyPlih4V0gZCEcIpetMpeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-40L3VIrtiGCAjUaJ0SJaQ.png" /></figure><h4>Map Function: contains()</h4><ul><li>Returns true, if and only if the map contains the given key</li></ul><p>bool contains (const keyT&amp;) const;</p><ul><li>For the assignment, you will be implementing the following:</li></ul><p>bool contains (const std:: string&amp;) const;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvNnkYEB0XV_Kp2l5GONMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQMj2utJhd3sZdOKNUGXYw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa8a8a61e27e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>