<?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 Yohan Hyunsung Yi on Medium]]></title>
        <description><![CDATA[Stories by Yohan Hyunsung Yi on Medium]]></description>
        <link>https://medium.com/@YOHANYI?source=rss-227b1568038e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eocX01v4xN8fHIcGuRjZRw.jpeg</url>
            <title>Stories by Yohan Hyunsung Yi on Medium</title>
            <link>https://medium.com/@YOHANYI?source=rss-227b1568038e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:37:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@YOHANYI/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[Strategies for non computer science majored in ChatGPT era]]></title>
            <link>https://medium.com/@YOHANYI/strategies-for-non-computer-science-majored-in-chatgpt-era-54bbde3bf453?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/54bbde3bf453</guid>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Tue, 27 Dec 2022 05:02:04 GMT</pubDate>
            <atom:updated>2022-12-27T05:02:44.059Z</atom:updated>
            <content:encoded><![CDATA[<h3>Strategies for non-CS majored in ChatGPT era</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C_WNyxjv8Jrot5K6" /><figcaption>Photo by <a href="https://unsplash.com/fr/@deepmind?utm_source=medium&amp;utm_medium=referral">DeepMind</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The ChatGPT era is an exciting time for the field of computer science and technology, as advances in natural language processing and machine learning continue to push the boundaries of what is possible in terms of human-computer interactions. However, for those who are not computer science majors, it can be intimidating to try and break into this field, especially if you have little to no experience with programming languages or computer science concepts.</p><p>As a non-major, it is important to recognize that you may have some challenges when it comes to competing with your more experienced peers in the job market. However, this does not mean that you cannot succeed in a ChatGPT era. In fact, there are several strategies that you can use to make the most of your unique perspective and skills as a non-major, and to stand out in a crowded job market.</p><p>One of the key strengths of being a non-major is that you may have diverse experiences and knowledge in other fields, which can be valuable in developing creative solutions to problems. Whether you have a background in business, marketing, psychology, or any other discipline, you can use your unique perspective to bring fresh ideas and approaches to the table.</p><p>In addition to your diverse background, it is important to highlight any skills or experiences that may be relevant to a career in computer science. This could include things like data analysis, problem-solving, or even just a strong aptitude for learning new technologies. If you have any internships or part-time jobs that have given you exposure to computer science or technology, make sure to highlight these experiences on your resume and in your cover letter.</p><p>Another key to success in a ChatGPT era is continuous learning and skill development. While it is not necessary to have a degree in computer science to work in this field, it is important to have a basic understanding of programming languages and computer science concepts. Consider taking online courses or workshops to learn these skills, or seek out mentors or colleagues who can help you get up to speed.</p><p>Finally, it is important to stay up-to-date with the latest advancements and trends in the field. This may involve reading industry blogs and articles, attending conferences and events, or even just following relevant accounts on social media. By staying current with the latest developments, you can position yourself as a valuable asset to potential employers.</p><p>In summary, as a non-major in a ChatGPT era, it is important to recognize your unique strengths and experiences, and to use them to your advantage. By continuously learning and developing your skills, staying current with industry trends, and highlighting relevant experiences, you can succeed in a competitive job market and make a valuable contribution to the field of computer science.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54bbde3bf453" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[13. Disjoint Set (Union/Find)]]></title>
            <link>https://medium.com/journey-to-tech-company/13-disjoint-set-union-find-a5edcce451e4?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5edcce451e4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 22:08:34 GMT</pubDate>
            <atom:updated>2018-06-07T22:08:47.093Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*McdBghtWOEngecBB" /><figcaption>Photo by <a href="https://unsplash.com/@simonfitall?utm_source=medium&amp;utm_medium=referral">Simon Fitall</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>-</h4><p>A disjoint set is a data structure that stores and manipulates information about elements that are divided into non-overlapping subsets. Disjoint sets are often used to partition constituent elements so that they do not overlap when there is an entire set. Let’s take a look at some of these terms.</p><ul><li>A set is a set of objects. (Unlike lists and the order is not considered)</li><li>When all the elements of set A are included in set B, A is called a subset of B. Here B is called A superset of A.</li><li>A and B are mutually disjoint when there is no element shared by A and B.</li><li>Partitioning an arbitrary set means to split the set so that each subset is a disjoint set satisfying the following two properties. (1) When the partitioned subset is combined, it becomes the original set. (2) Partitioned subsets are mutually disjoint, ie there are no overlapping elements.</li></ul><p>For example, if S = 1,2,3,4 and A = 1,2, B = 3,4, C = 2,3,4, D = 4 then A and B are partitions of S. A and B are disjoint sets. But A and C are not partitions of S. This is because there are overlapping elements. A and D are also not partitions of S. It is because it does not become S when both are combined.</p><h4>Operations</h4><ul><li>make-set (x): Makes a new set with x as its only element.</li><li>union (x, y): Combines the set to which x belongs and the set to which y belongs.</li><li>find (x): Returns the representative value (root node value) of the set to which x belongs.</li></ul><p>Let’s take an example. Let’s say that a disjoint set of A = 3, 4 is already created. In this case, the first entry element, 3, becomes the root node, and 3 is the value representing A. It is as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*AU5RUEmUFlfnZp5B_MuBaQ.png" /></figure><p>find (4) means to print the representative value of the set to which 4 belongs. So in this example, it will be 3. Similarly, find (3) and the output is 3.</p><p>Let’s say we have another disjoint set, B = 1,2. The representative value of B is the root node 3. When joining A and B, the root nodes are connected. It is as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*O3ycXGQnz3yMu1o8p5m9Qw.png" /></figure><p>The root node of the newly created disjoint set is 1. So, for example, if you perform find (4) to output a representative value of a set containing 4, the result is 1.</p><h4>Implemented as an array</h4><p>Let’s implement the three basic operations of a disjoint set as an array. Let A = 3,4, B = 1,2 Let’s say that two disjoint sets have already been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*s-Dk23hXWbiLCgxtvlChOw.png" /></figure><p>If you implement it as an array: N refers to the input elements. S indicates whether the input element is the root node or where the parent node is. For example, 3 and 1 are root nodes, so the value of S corresponding to them is 0. The parent node of 4 is marked as the first element of N, that is, 3. Similarly, the parent node of 2 is the third element of N,</p><p>N = [3,4,1,2]<br>S = [0, 1, 0, 3]<br>If union operation is performed, S changes as follows.</p><p>S=[0,1,1,3]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*O3ycXGQnz3yMu1o8p5m9Qw.png" /></figure><p>So what is the computational complexity of the union (x, y) operation? There are three main stages to consider.</p><ol><li>You need to find the disjoint set that x belongs to: find (x)</li><li>You need to find the set to which y belongs: find (y)</li><li>Combine the found sets.</li></ol><p>However, the computational complexity of the find operation is O (logn) when the number of elements in the disjoint set is n. Repeatedly traversing the parent node to find the root node. For example, if there is a disjoint set consisting of 3–4–5–2–1 in a row from the leaf node to the root, find (3) must traverse the edge four times as high as the tree, I can find it. The path compression is the way to perform the find operation more efficiently, but I will take a little time to deal with it.</p><p>Let’s say you’ve run the find operation twice to find the join set. Now it is time to combine these two. There are union-by-size and union-by-height methods to combine, which we’ll cover in the next section.</p><h4>Union</h4><p>When combining any two disjoint sets, it is efficient to combine sets with fewer elements into many sets of subtrees (union-by-size). Similarly, a set with a small height of the tree must be combined into a large set of subtrees (union-by-height). In order to improve the efficiency of the find operation, it is necessary to perform the find operation in the next union operation. The number of elements and the height of the tree tend to be proportional and the computational complexity of the find operation is highly dependent on them.</p><p>Implementing union-by-size and union-by-height is straightforward. You can change the root node information of array S. In the root node, we replace it with the following, unlike the old one,</p><ul><li><em>union-by-size</em> : −size of tree</li><li><em>union-by-height</em> : −height of tree</li></ul><p>In short, the two disjoint sets found in the find operation are compared in terms of the number of atoms or the height of the disjoint sets. This allows subsequent find operations to be performed more efficiently.</p><p>The computational complexity of union-by-size and union-by-height is O (1). Because find has already found the root node of two disjoint sets in the find operation, it compares the number of atoms or heights stored in these two root node locations in S. Replace the value of S corresponding to the root node of the smaller of the two to point to the index of the larger root node. All these operations correspond to O (1).</p><h4>Path compression</h4><p>path compression is to make all nodes point to the root as follows: S stores the root node instead of the parent node index. When you perform a find operation, you need to go back as far as the height of the tree to find the root node. This is to alleviate this inefficiency. Once you perform path compression, you can reduce the computational complexity of the find operation that finds the root node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*jqw5wRSpfnqbmFshYLoobw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5edcce451e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/13-disjoint-set-union-find-a5edcce451e4">13. Disjoint Set (Union/Find)</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10. Bitmask]]></title>
            <link>https://medium.com/journey-to-tech-company/10-bitmask-91d0051d7a87?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/91d0051d7a87</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 21:57:58 GMT</pubDate>
            <atom:updated>2018-06-07T21:57:58.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bAaCvBko-RiAVHkN" /><figcaption>“Colorful software or web code on a computer monitor” by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>-</h4><h4>Basic knowledge</h4><p>Computers represent all integer variables in binary numbers.<br>At this time, one digit of binary number is expressed as bit.<br>For example, an unsigned integer from 0 to 255 can be represented with 8 bits.<br>0 = 00000000<br>255 = 11111111<br>- For unsigned N-bit integers,<br>2 ⁰ is the least significant bit,<br>2 ^ (N-1) is called the most significant bit.<br>The value of a particular bit may be 0 or 1,<br>1: “On”<br>0: “off”</p><h4>Bitwise operator</h4><p>The following operations are possible for values ​​where all digits are bits (0 or 1).</p><ul><li>AND operation (symbol: a &amp; b): only 1 if both are 1, even if only one of them is 0, the result is 0.<br>ex) 111 &amp; amp; 101 = 101<br>ex) 101 &amp; amp; 100 = 100<br>ex) 001 &amp; 100 = 0</li><li>OR operation (symbol: a | b): only 0 if both are 0, only one of them results in 1 if the value is 1.<br>ex) 101 | 100 = 101<br>ex) 011 | 100 = 111<br>ex) 1000 | 0101 = 1101</li><li>XOR operation (symbol: a ^ b): 0 if they are the same value (11 or 00) and 1 if they are different values ​​(10 or 01)<br>ex) 101 | 111 = 010<br>ex) 1011 | 0100 = 1111<br>ex) 1011 | 1100 = 0111</li><li>NOT operation (symbol: ~ a): This operation applies to a single bit value, not an operation on two bit values. Invert each digit to the opposite value. That is, when the value is 0, the value is changed to 1, and when the value is 1, the value is changed to 0.<br>ex) to (1011) = 0100<br>ex) to (0011) = 1100</li><li>LEFT SHIFT operation (symbol: a &lt;&lt; b): Pushes the bits of all the digits of the value a to the left by b times. (With 0 on the right)<br>ex) 1 &lt;&lt; 5 = 100000<br>ex) (1 &lt;&lt; 5) — 1 = 11111<br>ex) 1011 &lt;&lt; 2 = 101100</li><li>RIGHT SHIFT operation (symbol: a &gt;&gt; b): Pushes the bits of all the digits of the value a to the right by b times. (With 0 on the left)<br>ex) 1101101 &gt;&gt; 2 = 11011<br>ex) 110010 &gt;&gt; 5 = 1</li></ul><h4>Playing with bits</h4><p>The above is a computation that should be studied while studying logic or mathematics.<br>The problem is how to use bits effectively with these operations.<br>From now on, each digit of the 10-digit bit (0–9) will think about the addition of different toppings of the pizza,<br>Let’s take a look at the available methods, assuming that the pizza is represented by a 10-digit bit value.<br>In other words, the value of 0100100100 will be the pizza with 3 toppings due to the ²², ²⁵, and ²⁸ digits set to 1.</p><ul><li>Obtaining empty sets and full sets<br>= Find a pizza that does not have any toppings, and a pizza that is full of toppings.<br>Pizza without topping: int emptyPizza = 0<br>Pizza full of toppings: int fullPizza = (1 &lt;&lt; 10) - 1</li><li>Adding elements<br>= Add n toppings to pizza a (where 0 &lt;= n &lt;10)<br>If you want to change only a specific value from 0 to 1 for the current pizza.<br>If you already have that topping, just keep it at 1.<br>a = a | (1 &lt;&lt; n)<br>That is,<br>a | = (1 &lt;&lt; n)</li><li>Check whether element is included<br>= Check if the pth a has the nth number of toppings (where 0 &lt;= n &lt;10)<br>Let&#39;s say the pepperoni topping number is n.<br>if (a &amp; (1 &lt;&lt; n)) cout &lt;&lt; &quot;Pepperoni is included !!!&quot; &lt;&lt; endl;<br>Note that the red part returns 0 or (1 &lt;&lt; n). (True if true, or 1 if misunderstood)</li><li>Delete the element<br>= You want to subtract the nth topping from pizza a. (Where 0 &amp; lt; = n &amp; lt; 10)<br>a = a &amp; ~ (1 &lt;&lt; n)<br>In short<br>a &amp; = ~ (1 &lt;&lt; n)</li><li>Toggle the element<br>= Add the nth topping of pizza a if it does not exist, remove it if there is one.<br>a = a ^ (1 &lt;&lt; n)<br>In short<br>a ^ = (1 &lt;&lt; n)</li><li>6. Other set operations<br>int added = (a | b); // Union<br>int intersection = (a &amp; b) // intersection<br>int removed = (a &amp; ~ b) // Difference set a — b<br>int toggled = (a ^ b) // A set of elements only in one of a and b (the union of a and b minus the intersection)</li><li>Find the least significant bit<br>= Find out what is the smallest number of toppings in pizza a<br>int leastSignificantTopping = a &amp; -a<br>ex) Let’s say for example a five-digit number 40<br>-40 is (01100) as follows using the two’s complement arithmetic method.<br>10100 = 40<br>01011 + 1 = 01100 = (-40)<br>10100 &amp; 01100 = 00100 (²³)</li><li>Clearing the minimum bit<br>= Topping minus the number of toppings in pizza a<br>int removedToppings = a &amp; (a — 1)<br>ex) When 10110 = a,<br>10110 &amp; amp; 10101 = 10100</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91d0051d7a87" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/10-bitmask-91d0051d7a87">10. Bitmask</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[9. Greedy Algoritm]]></title>
            <link>https://medium.com/journey-to-tech-company/9-greedy-algoritm-10520511a917?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/10520511a917</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 04:43:21 GMT</pubDate>
            <atom:updated>2018-06-07T04:43:21.485Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7XzWb7ZtomuZFipV." /><figcaption>Photo by <a href="https://unsplash.com/@sharonmccutcheon?utm_source=medium&amp;utm_medium=referral">Sharon McCutcheon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>-</p><ul><li>How to choose the most reasonable answer in current situation.</li><li>Mainly applied to combinatorial optimization problem with retraction search and dynamic programming</li></ul><p>How to solve the problem by making the decisions that are best judged from the point of view up to now</p><h4>Steps</h4><ol><li>Selection Procedure: A selection that selects one of the specific candidates to determine whether this is the solution to a given problem. In this case, the method of selecting the solution is the best one only in the current situation.</li><li>Feasibility Check: Checks whether the selected answer is valid.</li><li>Solution Check: Check that the solutions you have selected up to this time meet the requirements of the problem.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOMbOga35PxWC3Kjjbn4MQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10520511a917" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/9-greedy-algoritm-10520511a917">9. Greedy Algoritm</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mathematics 1]]></title>
            <link>https://medium.com/journey-to-tech-company/mathematics-1-e3381739b0c1?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3381739b0c1</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Thu, 31 May 2018 03:18:18 GMT</pubDate>
            <atom:updated>2018-05-31T03:19:50.647Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mQumhjOTxairy8h7." /><figcaption>Photo by <a href="https://unsplash.com/@antoine1003?utm_source=medium&amp;utm_medium=referral">Antoine Dautry</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>-</h4><h4>4. 1. Permutation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iU3h9lRcX5i0TwkT4QAe2Q.gif" /></figure><pre>func perm(_ array:[Int],_ depth:Int,_ n:Int,_ k:Int) {<br>    var array = array<br>    <br>    if depth == k {<br>        print(array)<br>    } else {<br>        for i in depth ..&lt; n {<br>            //SWAP 1<br>            (array[i],array[depth]) = (array[depth],array[i])<br>            <br>            //Resursion<br>            perm(array, depth + 1, n, k)<br>            <br>            //SWAP 2<br>            (array[i],array[depth]) = (array[depth],array[i])<br>        }<br>    }<br>}</pre><h4>4. 2. Combination</h4><p>Combinations: Unordered lists</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*KTqj2-LzLO7E9mksFXiexQ.png" /></figure><pre>func combination(_ array:[Int],_ index:Int,_ n:Int,_ r:Int,_ target:Int) {<br>    var array = array<br>    <br>    if (r == 0) {<br>        print(array[0..&lt;index])<br>    } else if target != n {<br>        array[index] = target<br>        combination(array, index + 1, n, r - 1, target + 1)<br>        combination(array, index, n, r, target + 1)<br>    }<br>}</pre><pre>combination([0,1,2,3,4], 0, 5, 3, 0)</pre><h4>4. 3. Prime Number</h4><ul><li>If num is divided by i, it is not a prime number.</li><li>If it divided, escape the loop</li><li>divide the prime number smaller than the input number</li></ul><pre>func getPrime(_ num:Int) {   <br>    var prime:[Int] = [2]<br>    <br>    for i in 2...num {<br>        for j in 0 ..&lt; prime.count {<br>            // Not a prime number<br>            if i % prime[j] == 0 {<br>                break<br>            } else if j + 1 == prime.count { // it is prime number<br>                prime.append(i)<br>            }<br>        }<br>    }<br>    print(prime)<br>}</pre><pre>getPrime(10)</pre><h4>4. 4. Eratostheneen seula</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*ZCDjSI5Qnc4Xah6VfqB_9Q.gif" /></figure><p>Let’s say you want to find all prime number to 120.</p><p>After putting them all in the array from 2 to 120, check everything that is not a prime number. <br>Check all multiples of 2 except 2. <br>Check all multiples of 3 except 3. <br>4 is skip because it was checked before. <br>Check for multiples of all 5 except 5. … … <br>There are prime numbers of unchecked numbers.</p><p><em>When checking, use the loop only as many times as you want to check without having to check all the numbers. And does not find a multiple of the number already checked to zero. Because the multiples of the checked number are already checked.</em></p><pre>func getPrimeNumberEratostheneen(_ num:Int) -&gt; [Int] {<br>    var array = [Int]()<br>    var result = [Int]()<br>    <br>    //init the array<br>    for i in 0...num {<br>        array.append(i)<br>    }<br>    <br>    for i in 2...num {<br>        if array[i] != 0 {<br>            var j = i + i<br>            while j &lt;= num {<br>                array[j] = 0<br>                j += i<br>            }<br>        }<br>    }<br>    <br>    for i in 2...num {<br>        if array[i] != 0 {<br>            result.append(i)<br>        }<br>    }<br>    <br>    return result<br>}</pre><pre>print(getPrimeNumberEratostheneen(100))</pre><h4>4. 5. GCD Euclideon Algorithm</h4><pre>func GCD(_ n:Int,_ m:Int) -&gt; Int {<br>  if n &gt; m {<br>    if (n % m == 0) {<br>      return m<br>    } else {<br>      return GCD(m, n % m)<br>    }<br>  } else {<br>    if (m % n == 0) {<br>      return n<br>    } else {<br>      return GCD(n, m % n)<br>    }<br>  }<br>}</pre><pre>GCD(25,3)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3381739b0c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/mathematics-1-e3381739b0c1">Mathematics 1</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[11. String]]></title>
            <link>https://medium.com/journey-to-tech-company/11-string-d364ce5a2daa?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d364ce5a2daa</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Sun, 20 May 2018 11:31:05 GMT</pubDate>
            <atom:updated>2018-05-20T11:31:59.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mU5veFKkEjJJHBfa." /><figcaption>Photo by <a href="https://unsplash.com/@davideragusa?utm_source=medium&amp;utm_medium=referral">davide ragusa</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>-</p><h3>11. 1. Palindrome</h3><p>A palindrome is a word or phrase that is spelled the exact same when reading it forwards or backward. Palindromes are allowed to be lowercase or uppercase, contain spaces, punctuation, and word dividers.</p><p>Algorithms that check for palindromes are a common programming interview question.</p><p>The word racecar is a valid palindrome, as it is a word spelled the same when backgrounds and forwards. The examples below shows valid cases of the palindrome racecar.</p><pre>|     |<br>racecar -&gt; r == r<br><br> |   |<br>racecar -&gt; a == a<br><br>  | |<br>racecar -&gt; c == c<br><br>   |<br>racecar -&gt; left index == right index -&gt; return true</pre><p>To check for palindromes, a string’s characters are compared starting from the beginning and end then moving inward toward the middle of the string while maintaining the same distance apart. In this implementation of a palindrome algorithm, recursion is used to check each of the characters on the left-hand side and right-hand side moving inward.</p><pre>func isPalindrome(_ str: String) -&gt; Bool {<br>    let strippedString = str.replacingOccurrences(of: &quot;\\W&quot;, with: &quot;&quot;, options: .regularExpression, range: nil)<br>    let length = strippedString.count<br>    <br>    if length &gt; 1 {<br>        return palindrome(strippedString.lowercased(), left: 0, right: length - 1)<br>    }<br>    <br>    return false<br>}</pre><pre>private func palindrome(_ str: String, left: Int, right: Int) -&gt; Bool {<br>    if left &gt;= right {<br>        return true<br>    }<br>    <br>    let lhs = str[str.index(str.startIndex, offsetBy: left)]<br>    let rhs = str[str.index(str.startIndex, offsetBy: right)]<br>    <br>    if lhs != rhs {0<br>        return false<br>    }<br>    <br>    return palindrome(str, left: left + 1, right: right - 1)<br>}</pre><h4>11. 2. Manacher’s Algorithm</h4><p>Manacher’s algorithm is an algorithm for finding a palindrome in a string, and the time complexity is O (n) (where n is the length of the string)</p><p>The algorithm takes the string S as input and returns:</p><ul><li>An integer array A having the same length as the string S, and the element A [i] of each A is the length of the longest radial radius of the i-th string (ie, S[(i−A[i])⋯(i+A[i])] is a sold string and S[(i−A[i]−1)⋯(i+A[i]+1)] is not a sold string )</li></ul><p>For example, for the input S = ‘banana’, the result of A is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*IfmRSjco6OA9Z_aN8iXzoQ.png" /></figure><p><strong>The algorithm is as follows:</strong></p><ol><li>i proceeds from 0 to n-1 (n = | S |)</li><li>R = max (j + A [j]) for all j with j &lt; i, Let j be p. (R = p + A [p])</li><li>the initial value of A [i] is determined depending on whether or not i ≤ R</li></ol><ul><li>If i&gt; R, the initial value of A [i] is zero.</li><li>If i ≤ R, then i is a soldin dump centered on p. At this time, we obtain the symmetric point i ‘of i around p. The initial value of A [i] is min (R-i, A [i ‘])</li></ul><p>4. From the initial value of A [i], A [i] is incremented until S [i-A [i]] and S [i + A [i]] are equal, and then to i.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*DyYjoypEiUShl4aVLkp1GQ.png" /><figcaption>Pseudo Code of Manacher’s Algorithm</figcaption></figure><h4>11. 3. Trie</h4><p>Means an ordered set of tree data structures used to store dynamic sets or associative arrays with strings. Unlike a binary search tree, nodes on a tree do not store keys associated with that node. Instead, the position on the tree represents the current key. Every descendant of a particular node has the same prefix as the node, and the root node has an empty string. The value does not exist in all nodes, but exists only at the leaf nodes or the inner node corresponding to the specific key. To optimize the space usage of the prefix tree, a compact prefix tree was envisioned. The word trie comes from the word reTRIEval. Edward Fredkin, who created this word, pronounces the word the same as ‘tree’, but others pronounce it as ‘trai’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*w6Vh-_c5kb3q-6s9Nnttfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*HCSph87chyZ2GaDR1QJHLA.png" /></figure><p>Why should I use TRIE?<br>To quickly and efficiently search large amounts of text information<br>So Trie is a data structure that can effectively retrieve dictionary or Internet autocompletion.<br><br>As mentioned earlier, the name TRIE came from TREE RETRIEVAL. The most typical characteristic is that the keyword information has only the last node, the remaining nodes have no information and only the link.</p><h4>11. 4. Suffix Tree</h4><p>Suffix tree is a trie shaped data structure that represents all suffixes of a string.<br>The trie is called a prefix tree. The difference between the data structures is that when there is a word banana, the trie stores only the word banana, but the suffix tree is like banana, anana, nana, ana, na, a It saves the number of all cases that can come from the word banana. The reason for storing all of the cases in vain is because you need to search for strings. In the case of the Trie data structure, you can find the complete word banana as a partial word such as ban, ba, but you can not find banana with the words nan, ana. To solve this problem, it seems to be a suffix tree that improved the trie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*E6-Y-_lR8HCkrg_2rzzZAw.png" /></figure><p>Since the edge can have a string label, a distinction must be made between the two meanings of ‘depth’. The first is node depth. The node depth refers to how many edges must pass from the root to the node. The second is Label depth. This is the total length of the edge label for the edge in the path from root to node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*rtkqxV4lqI_i60DgY18CWA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d364ce5a2daa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/11-string-d364ce5a2daa">11. String</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7. Searching 2]]></title>
            <link>https://medium.com/journey-to-tech-company/7-searching-2-1806780306d2?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1806780306d2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Sun, 20 May 2018 10:50:47 GMT</pubDate>
            <atom:updated>2018-05-31T03:15:05.926Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H1ldXd1KBiY2bx88." /><figcaption>“An overhead shot of two people planning a trip with a map and a laptop on a wooden surface” by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>-</p><h4>7. 2. Brute-Force</h4><p>Brute: Animals, animals<br>Force: Force<br>As you can see from the name, it is a very simple ignorant algorithm.<br>In order to solve the problem, it is a way to do it all in all possible cases.<br>If the problem gets a bit more complicated, the bigger the number, the more time it takes.<br>So the brute force algorithm is very inefficient in terms of time.<br>However, the brute force algorithm is as easy to create.<br><br>Beyond that, the advantages of the brute force algorithm are different.<br>It helps before thinking about other algorithms.<br>This is the starting point to think of a more advanced algorithm.</p><h4>7. 3. Jump Point Search</h4><p>This section and the next describe the mechanical details and algorithmic properties of Jump Point Search. If you don’t care for such things, feel free to jump ahead and check out some screenshots.<br>JPS can be described in terms of two simple pruning rules which are applied recursively during search: one rule is specific to straight steps, the other for diagonal steps. The key intuition in both cases is to prune the set of immediate neighbours around a node by trying to prove that an optimal path (symmetric or otherwise) exists from the parent of the current node to each neighbour and that path does not involve visiting the current node. Figure 1 outlines the basic idea.</p><h4>7. 4. Linear Search</h4><p>There is a disadvantage in that it is not necessary to sort or touch data, it is easy, but when the amount of data increases, the time required for search increases proportionally and each one is compared inefficiently. For example, if you have a set of data like this, you need 10 comparisons to find 4. If you have 1 million data and the data you are looking for is one million times, then you have to make one million comparisons. This situation is called Worst Case. The best case is called a good situation.</p><h4>7. 5. Power Set</h4><p>To list all subsets of {a, b, c, d, e, f}</p><ul><li>List all subsets of {b, c, d, e, f} except a.</li><li>List sets that add {a} to all subsets of {b, c, d, e, f}.</li></ul><pre><strong>def</strong> <strong>power_set_1</strong>(set_):<br>    <strong>def</strong> <strong>k_subsets</strong>(k, start_ind):<br>        <strong>if</strong> k <strong>==</strong> 0:<br>            <strong>return</strong> [[]]<br>        <strong>else</strong>:<br>            subsets <strong>=</strong> []<br>            <strong>for</strong> ind <strong>in</strong> xrange(start_ind, len(set_) <strong>-</strong> k <strong>+</strong> 1):<br>                <strong>for</strong> subset <strong>in</strong> k_subsets(k <strong>-</strong> 1, ind <strong>+</strong> 1):<br>                    subsets<strong>.</strong>append(subset <strong>+</strong> [set_[ind]])<br>            <strong>return</strong> subsets<br><br>    subsets <strong>=</strong> []<br>    <strong>for</strong> k <strong>in</strong> xrange(len(set_) <strong>+</strong> 1):<br>        <strong>for</strong> subset <strong>in</strong> k_subsets(k, 0):<br>            subsets<strong>.</strong>append(subset)<br>    <strong>return</strong> subsets</pre><h4>7. 6. Optimization Problem</h4><p>The optimal algorithm is one in which all algorithms that solve the same problem do not have algorithms that perform fewer major operations than the algorithm.</p><ul><li>Step 1: We devise a W (n) algorithm that is considered efficient for a given problem. The algorithm finds the workload needed in the worst case. Where n represents the size of the input data.</li><li>Step 2: For function F, any kind of algorithm that can solve a given problem proves that a workload of at least F (n) is absolutely necessary.</li><li>Step 3: If an algorithm satisfies W (n) = F (n), then the algorithm is the optimal algorithm to solve the problem.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1806780306d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/7-searching-2-1806780306d2">7. Searching 2</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3. Trees 1]]></title>
            <link>https://medium.com/journey-to-tech-company/3-trees-1-18a1632d22a3?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/18a1632d22a3</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Fri, 18 May 2018 23:55:42 GMT</pubDate>
            <atom:updated>2018-05-18T23:55:42.108Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z-Dx5dtaXSUTl0Ho." /><figcaption>Photo by <a href="https://unsplash.com/@akummur?utm_source=medium&amp;utm_medium=referral">Adarsh Kummur</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Express hierarchical structure.</p><h4>3. 1. Heap</h4><ul><li>It should be a complete binary tree.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZmCttD-vBc_97P5BCu23qQ.png" /></figure><ul><li>Heap Property must be satisfied. (Max Heap or Min Heap)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQRG0UTJy2-YfFaAEmrdPw.png" /></figure><p>Heap can be expressed in a one-dimensional array. A[1…n]</p><ul><li>Root Node = A[1]</li><li>Parent of A [i] = A [i / 2]</li><li>Left child of A [i] = A [2i]</li><li>Right child of A [i] = A [2i + 1]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIESKok_wSwD4fkMvBaeyQ.png" /></figure><h4>3. 2. Max Heap / Min Heap</h4><ul><li>Max Heap — Parent is greater than or equal to child.</li><li>Min Heap — The parent is less than or equal to the child.</li></ul><p><strong>Heapify — O(logN)</strong></p><p>If the left sub tree and the right sub tree are both Heap and the Root Node does not satisfy the Heap, the operation method that makes the entire tree Heap.</p><ul><li>If the larger of the two children is greater than or equal to the Exchange,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yNqYKAI3Aszcw584EP289g.png" /></figure><pre>func maxHeapify(_ i:Int,_ n:Int){<br>    var left : Int? = nil<br>    var right : Int?  = nil<br>    var k = 0<br>    <br>    if i*2 &lt;= n {<br>        left = data[i*2]<br>    }<br>    <br>    if i*2+1 &lt;= n {<br>        right = data[i*2+1]<br>    }<br>    <br>    if left == nil &amp;&amp; right == nil {<br>        return<br>    }<br>    <br>    if right == nil || left! &gt; right! {<br>        k = i*2<br>    } else {<br>        k = i*2+1<br>    }<br>    <br>    if data[i] &gt;= data[k] {<br>        return<br>    } else {<br>        let temp = data[i]<br>        data[i] = data[k]<br>        data[k] = temp<br>    }<br>    <br>    maxHeapify(k, n)<br>}</pre><h4>3. 3. Segment Tree</h4><p>When the entire section is [0, N-1], that is, when there are N spaces<br>Thus, leaf nodes have each interval of length 1, the parent nodes have the sum of its child’s intervals, and all the intervals must be contiguous.<br>The root will contain the entire section.<br>This is a data structure in which each node stores information about a section or its section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*JDNHODurWq5ETRRH07VfdQ.png" /></figure><p>Normally, a complete binary tree is used so that the entire recursive structure is repeated. If the number of values ​​is not 2^n, fill the remaining interval with meaningless values ​​and use it in the form of a saturated binary tree.<br>This ensures that when the value is N, the height of the tree is balanced to O (logN).<br>And as with the heap, the root index starts at 1, making it easy to access your parent, left / right child, by node numbering in the order of the level order.<br>That is, 1 for [0, 7], 2 for [0, 3], 3 for [4, 7], 4 for [0, 1], and leaf nodes are 8, 9, 10, …15 ,(get N ~ 2N-1). You might think of the number as an index.</p><h4>3. 4. Binary Index Tree</h4><p>In a binary tree, each node has a maximum of two children.<br>Each child node is specified whether it is the left child or the right child of the parent.</p><p>Linked Structure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yCKvpJmvJpecM6IJF9DgfQ.png" /></figure><h4>Traversal of Binary Tree</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*MM3GZBTIZiRuyCmA7WPXtQ.png" /></figure><ul><li><strong>Inorder Traversal O(N):</strong></li></ul><p>1 traverse TL, 2 traverse Root, and 3 traverse TR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79z_V2FCeT8MrszXqLr9Ug.png" /><figcaption>pseudo code of In Order Traversal for Binary Tree</figcaption></figure><ul><li><strong>Preorder Traversal:</strong></li></ul><p>1 traverse Root, 2 traverse TL , and 3 traverse TR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*pyMLUdqxS8j50qSg3VJsEw.png" /><figcaption>pseudo code of Pre Order Traversal for Binary Tree</figcaption></figure><ul><li><strong>Postorder Traversal:</strong></li></ul><p>1 traverse TL, 2 traverse TR, and 3 traverse Root</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*-g3fVOFjYWwDKp1mVY3D5g.png" /><figcaption>pseudo code of Post Order Traversal for Binary Tree</figcaption></figure><ul><li><strong>Level-order Traversal:</strong></li></ul><p>Use queue. Visits in order of level, from left to right in the same level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*C2qUsmh6Q0XnLV9xvLSbTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*QIa3opotWCJrhSBs-vpjwA.png" /><figcaption>Sudo Code of Level Order Traversal for Binary Tree</figcaption></figure><pre>public func traverseInOrder(process: (T) -&gt; Void) {<br>    left?.traverseInOrder(process: process)<br>    process(value)<br>    right?.traverseInOrder(process: process)<br>  }<br><br>  public func traversePreOrder(process: (T) -&gt; Void) {<br>    process(value)<br>    left?.traversePreOrder(process: process)<br>    right?.traversePreOrder(process: process)<br>  }<br><br>  public func traversePostOrder(process: (T) -&gt; Void) {<br>    left?.traversePostOrder(process: process)<br>    right?.traversePostOrder(process: process)<br>    process(value)<br>  }</pre><h4>3. 5.Binary Search Tree (BST)</h4><blockquote><strong>Search Structure (Dynamic Set)</strong></blockquote><blockquote>Store multiple keys</blockquote><blockquote>Insert — Insert new key<br>Search — key navigation<br>Delete — Delete key</blockquote><p>An implementation of Search Structure in the form of a Tree. Generally, search, insert, and delete operations have time complexity proportional to the height of the tree.</p><p>A tree that satisfies the following three conditions is called an advanced search tree.</p><ul><li>Binary tree</li><li>Store one key on each node</li><li>For each node v, the keys in the left subtree of that node are less than or equal to key [v], and the value in the right subtree is equal to or greater than.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*l4RGwfEysJpBoTQDcFbNSg.png" /><figcaption>Example of Binary Search Tree</figcaption></figure><ul><li><strong>Search — O(h)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*jnWgRI_dmdMFv2BNNv8_wg.png" /><figcaption>pseudo code of Binary Search Tree</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*BQt3yHVdz8tGpCbqMh6Rog.png" /></figure><pre>public func search(x: T) -&gt; BinarySearchTree? {<br>    switch self {<br>    case .Empty:<br>      return nil<br>    case .Leaf(let y):<br>      return (x == y) ? self : nil<br>    case let .Node(left, y, right):<br>      if x &lt; y {<br>        return left.search(x)<br>      } else if y &lt; x {<br>        return right.search(x)<br>      } else {<br>        return self<br>      }<br>    }<br>  }</pre><ul><li><strong>Successor — O(H)</strong></li></ul><p>A value with the size immediately following node x</p><p>Case 1: If the right subtree of node x exists, the minimum value of the right subtree<br>Case 2: If there is no right subtree, the value of the node y whose maximum value of the left subtree is x. (A node that becomes the first child of someone else to go up to the root along the parent)<br>Case 3: There is no successor if node y does not exist. (That is, x is the maximum value)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*bqGLADuVq9E9_WOXfqBPNw.png" /><figcaption>pseudo code for finding successor</figcaption></figure><pre>public func successor() -&gt; BinarySearchTree&lt;T&gt;? {<br>    if let right = right {<br>      return right.minimum()<br>    } else {<br>      var node = self<br>      while let parent = node.parent {<br>        if parent.value &gt; value { return parent }<br>        node = parent<br>      }<br>      return nil<br>    }<br>  }</pre><ul><li><strong>Insert — O(H)</strong></li></ul><p>When adding a new node, the position of existing nodes is not changed.</p><p>It is implemented using two pointers, X and Y. Y is always positioned after one of the X’s so that the current position can be remembered even if X becomes Nil.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*uJzx_TPmlWAeCjcuVsYrUw.png" /><figcaption>pseudo code of Insert Function</figcaption></figure><pre>public func insert(newValue: T) -&gt; BinarySearchTree {<br>    switch self {<br>    case .Empty:<br>      return .Leaf(newValue)<br><br>    case .Leaf(let value):<br>      if newValue &lt; value {<br>        return .Node(.Leaf(newValue), value, .Empty)<br>      } else {<br>        return .Node(.Empty, value, .Leaf(newValue))<br>      }<br><br>    case .Node(let left, let value, let right):<br>      if newValue &lt; value {<br>        return .Node(left.insert(newValue), value, right)<br>      } else {<br>        return .Node(left, value, right.insert(newValue))<br>      }<br>    }<br>  }</pre><ul><li><strong>Delete — O(H)</strong></li></ul><p>Case 1: If there are no child nodes, just delete them.<br>Case 2: If there is one child, it links its child node to its original location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*vIzI0BInXK1RXSp1CaPn4g.png" /></figure><p>Case 3: <br>If there are two children, leave only their own node and delete only their own data. Then, move the data of the Successor node to original node. Since the successor node does not have the left child and has 0 or 1 child, delete the successor node by Case 1 or Case 2 method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*Al6ewNfpJfoY_HFRkE1bdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*lanjF1q94B91MEqF2Glzgg.png" /><figcaption>pseudo code of delete function</figcaption></figure><pre>private func reconnectParentTo(node: BinarySearchTree?) {<br>    if let parent = parent {<br>      if isLeftChild {<br>        parent.left = node<br>      } else {<br>        parent.right = node<br>      }<br>    }<br>    node?.parent = parent<br>  }</pre><pre>public func minimum() -&gt; BinarySearchTree {<br>    var node = self<br>    while let next = node.left {<br>      node = next<br>    }<br>    return node<br>  }<br><br>  public func maximum() -&gt; BinarySearchTree {<br>    var node = self<br>    while let next = node.right {<br>      node = next<br>    }<br>    return node<br>  }</pre><pre>@discardableResult public func remove() -&gt; BinarySearchTree? {<br>    let replacement: BinarySearchTree?<br><br>    // Replacement for current node can be either biggest one on the left or<br>    // smallest one on the right, whichever is not nil<br>    if let right = right {<br>      replacement = right.minimum()<br>    } else if let left = left {<br>      replacement = left.maximum()<br>    } else {<br>      replacement = nil<br>    }<br><br>    replacement?.remove()<br><br>    // Place the replacement on current node&#39;s position<br>    replacement?.right = right<br>    replacement?.left = left<br>    right?.parent = replacement<br>    left?.parent = replacement<br>    reconnectParentTo(node:replacement)<br><br>    // The current node is no longer part of the tree, so clean it up.<br>    parent = nil<br>    left = nil<br>    right = nil<br><br>    return replacement<br>  }</pre><h4>3. 6. Red Black Tree — O(logN)</h4><p>One of Binary Search Tree. <br>A tree that balances the tree‘s height so that the height maintains logN.<br>Insert and delete operations O (logN) even in the worst case.</p><ul><li>Each node stores the address of one Key, Left, Right, and P</li><li>If there is no child node, there is a special node called Nil node.</li><li>Therefore, every leaf node is a Nil node</li><li>It is assumed that the parent of the root is also a Nil node</li><li>Nodes are classified as internal nodes and Nil nodes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JGc9puKriGxB4gNqM8DvUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NoxKQtKLE8yPHzEoZB8-Ow.png" /></figure><p>Red-Black Tree is a Binary Search Tree that satisfies the following conditions.</p><ul><li>Each node is red or black.</li><li>The root node is black.</li><li>All leaf nodes (Nil nodes) are black.</li><li>The child nodes of the red node are all black. (That is, red nodes do not appear consecutively)</li><li>For all nodes, there are the same number of black nodes in all paths from that node to the descendant leaf node.</li></ul><blockquote><em>The black height (BH) of the node with the height H is BH ≥ H/2</em></blockquote><blockquote><em>An arbitrary Subtree rooted at node X contains at least 2 ^ BH (x) -1 internal nodes</em></blockquote><blockquote><em>The height of the red black tree having N internal nodes is 2 log (N + 1) or less.</em></blockquote><h4>Search : Same as Binary Search Tree</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*YvGy2BaHvV47nq3r_sNuZw.png" /><figcaption><em>Left and Right Rotation</em></figcaption></figure><blockquote><em>Left and Right Rotation- O(1)</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3k9OmcUVL8ze_IEnTbd3Q.png" /><figcaption>pseudo code of left rotation</figcaption></figure><h4>Insert</h4><ul><li>Insert nodes as in normal BST.</li><li>Let the new node z be the red node.</li><li>Call RB-Insert-Fixup.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*Q2hl5du-DKehxet3A0Tl0Q.png" /><figcaption>pseudo code of insert function</figcaption></figure><h4>RB-Insert-Fixup</h4><p>If the z node is the root node, change it to black.<br>If the parent node of the z node is red, follow the rules below.</p><ul><li><strong>case 1</strong>: When P [z] is the left child of P [P [z]], &amp;&amp; z’s uncle (grandfather’s right child) is red -&gt; change parents and uncle to black, change grandfather to red, .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdvEv8nXqrViZRSfvqPQxg.png" /></figure><ul><li><strong>case 2</strong>: When P [z] is the left child of P [P [z]] &amp;&amp; If my uncle is Black &amp;&amp; z is the right child -&gt; Left-rotate P [z] and set P [z] to z -&gt; Run case 3.</li><li><strong>case 3</strong>: When P [z] is the left child of P [P [z]] &amp;&amp; If my uncle is Black &amp;&amp; z is the left child -&gt; Change P [z] to black, and P [P [z]] to red -&gt; Right-rotate P [P [z]]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dgvhgVIrBY6B5jJ1FZeMKQ.png" /></figure><ul><li>case 4~6 : same as case 1~3 with changing left to right</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*epHhvn1dZwgg13tWtM8q9A.png" /><figcaption>pseudo code of RB-Insert-Fixup</figcaption></figure><h4>Delete</h4><ul><li>Delete as usual binary search.</li><li>If the deleted node y was red, then exit.</li><li>Call RB-DELETE-Fixup when y is black.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*I6Mgdlgvxi-ewThwlJeCsA.png" /><figcaption>pseudo code of delete function</figcaption></figure><h4>3. 7. Treap</h4><p>Like Red-Black and AVL Trees, Treap is a Balanced Binary Search Tree, but not guaranteed to have height as O(Log n). The idea is to use Randomization and Binary Heap property to maintain balance with high probability. The expected time complexity of search, insert and delete is O(Log n).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*_VRI2hU3vQdeF5v4t7mn7Q.png" /></figure><p>Every node of Treap maintains two values.<br>1) Key Follows standard BST ordering (left is smaller and right is greater)<br>2) Priority Randomly assigned value that follows Max-Heap property.</p><h4>Search</h4><p>Perform standard BST Search to find x.</p><h4><strong>Insert</strong></h4><p>1)Create new node with key equals to x and value equals to a random value.<br>2) Perform standard BST insert.<br>3) Use rotations to make sure that inserted node’s priority follows max heap property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*sFQFXNOGAfmoVAs__fl_dg.png" /></figure><p><strong>Delete</strong><br>1) If node to be deleted is a leaf, delete it.<br>2) Else replace node’s priority with minus infinite ( -INF ), and do appropriate rotations to bring the node down to a leaf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*f_xK2YeUf86qqdaxx-5cNw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18a1632d22a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/3-trees-1-18a1632d22a3">3. Trees 1</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[6. Sorting 2]]></title>
            <link>https://medium.com/journey-to-tech-company/sorting-2-5dbf08a3d904?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dbf08a3d904</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Wed, 16 May 2018 21:18:32 GMT</pubDate>
            <atom:updated>2018-05-21T01:23:28.042Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JITcQWQTExhOT8KE." /><figcaption>“Bowl of seasoned pistachios and nuts for a salty snack” by <a href="https://unsplash.com/@whitney_wright?utm_source=medium&amp;utm_medium=referral">Whitney Wright</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>6. 6. Heap Sort — O(NlogN)</h4><p>No additional array required.</p><p><strong>(1) Make the array you want to sort on Heap. (Heapify) — O(N)</strong><br>The subtree rooted at the first node, not the leaf node, performs a Heapify operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*jSPcj9nYZZQ-j3hmBL26ug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*H4CumNPV8sX4gvOEnY9M7Q.png" /></figure><pre>func buildMaxHeap(_ n:Int){<br>    for i in (1...(n/2)).reversed(){<br>        maxHeapify(i, n)<br>    }<br>}</pre><p><strong>(2) In the heap, change the maximum value (root node) to the last value.<br>(3) The size of the heap is assumed to be reduced by one. That is, the last value is not considered part of the heap.<br>(4) Heapify (1) for the root node.<br>(5) Repeat steps 2 to 4.</strong></p><pre>func heapSort(_ n:Int){<br>    buildMaxHeap(n)<br>    for i in (1...n).reversed(){<br>        let temp = data[1]<br>        data[1] = data[i]<br>        data[i] = temp<br>        maxHeapify(1,i-1)<br>    }<br>}</pre><h4>6. 7. Radix Sort</h4><p>Default assumption: number of values ​​are n and d-digit integers.</p><p>We sort from the last digit. Each digit is sorted by a stable sorting (counting sort, bucket sort) algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*07OnAV6tPaHGr3GcuzCiGA.png" /></figure><pre>func radixSort(_ array: inout [Int] ) {<br>    let radix = 10  //Here we define our radix to be 10<br>    var done = false<br>    var index: Int<br>    var digit = 1  //Which digit are we on?<br>  <br>    while !done {  //While our  sorting is not completed<br>        done = true  //Assume it is done for now<br>        var buckets: [[Int]] = []  <br>        //Our sorting subroutine is bucket sort, <br>        //so let us predefine our buckets<br>    <br>        for _ in 1...radix {<br>            buckets.append([])<br>        }</pre><pre>        for number in array {<br>            index = number / digit  //Which bucket will we access?<br>            buckets[index % radix].append(number)<br>            <br>            if done &amp;&amp; index &gt; 0 {  <br>            //If we arent done, continue to finish, <br>            //otherwise we are done<br>            done = false<br>            }<br>        }</pre><pre>        var i = 0</pre><pre>        for j in 0..&lt;radix {<br>            let bucket = buckets[j]<br>            for number in bucket {<br>                array[i] = number<br>                i += 1<br>            }<br>        }</pre><pre>        digit *= radix  //Move to the next digit<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dbf08a3d904" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/sorting-2-5dbf08a3d904">6. Sorting 2</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2. List-Based Collections]]></title>
            <link>https://medium.com/journey-to-tech-company/2-list-based-collections-fa813f981ffe?source=rss-227b1568038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa813f981ffe</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Yohan Hyunsung Yi]]></dc:creator>
            <pubDate>Tue, 15 May 2018 03:59:19 GMT</pubDate>
            <atom:updated>2018-05-16T21:20:09.508Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3pdZOaPuboNSWUX4." /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>-</p><h4>2. 1. Array</h4><p>Contiguous area of memory consisting of equal-size elements indexed by contiguous integers.</p><p><strong>Adding values<br></strong>You can add elements to the end of an array using the append method.</p><pre>// create a empty array of integers<br>var numbers: [Int] = []</pre><pre>for i in 1...5 {<br>    numbers.append(i)<br>    print(numbers)<br>    // [1]<br>    // [1, 2]<br>    // [1, 2, 3]<br>    // [1, 2, 3, 4]<br>    // [1, 2, 3, 4, 5]<br>}</pre><pre>print(numbers)<br>// [1, 2, 3, 4, 5]</pre><p>To insert an item into the array at a specified index, call the array’s insert(at:) method.</p><pre>var numbers: [Int] = [1, 2, 3]</pre><pre>numbers.insert(0, at: 0) // numbers will be [0, 1, 2, 3]<br>numbers.insert(9, at: 1) // numbers will be [0, 9, 1, 2, 3]</pre><p>You can also append another array using the += operator.</p><pre>var numbers: [Int] = [1, 2, 3]</pre><pre>numbers += [4, 5, 6] // numbers will be [1, 2, 3, 4, 5, 6]</pre><pre>// or just one value<br>numbers += [7] // numbers will be [1, 2, 3, 4, 5, 6, 7]</pre><p><strong>Removing Values<br></strong>To remove an item from a specific index call the remove(at:) method.</p><pre>var numbers: [Int] = [1, 2, 3]</pre><pre>numbers.remove(at: 0) // numbers will be [2, 3]</pre><p><strong>Multi Dimensional Array</strong></p><pre>// Create a two-dimensional array with nested brackets.<br>var points: [[Int]] = [[10, 20], [30, 40]]</pre><pre>// Access all individual elements.<br>print(points[0][0])<br>print(points[0][1])<br>print(points[1][0])<br>print(points[1][1])</pre><pre>// append an item to one of the arrays<br>points[1].append(50)</pre><pre>print(points)</pre><h4>2. 2. Linked List</h4><p>The definition of Linked List is a data structure that stores data in such a way that each node has data and pointers and is connected in a single line.<br>The types of Linked List are as follows<br>- Singly Linked List<br>- Doubly Linked List<br>- Circular Linked List</p><p>Features of Linked List The common characteristics of the basic list data structure are as follows. <br>- List data structures store data side by side. It does not prevent storing duplicate data. <br>- Basic Principles of Linked Lists Dynamically allocate structure variables one at a time and link them as needed.</p><pre>public class Node {<br>    var value: String<br>    <br>    init(value: String) {<br>        self.value = value<br>    }<br>    <br>    var next: Node?<br>    weak var previous: Node?<br>}</pre><pre>public class LinkedList {<br>    fileprivate var head: Node?<br>    private var tail: Node?<br>    <br>    public var isEmpty: Bool {<br>        return head == nil<br>    }<br>    <br>    public var first: Node? {<br>        return head<br>    }<br>    <br>    public var last: Node? {<br>        return tail<br>    }<br>    <br>    public func append(value: String) {<br>        let newNode = Node(value: value)</pre><pre>if let tailNode = tail {<br>            newNode.previous = tailNode<br>            tailNode.next = newNode<br>        }<br>        else {<br>            head = newNode<br>        }<br>        tail = newNode<br>    }<br>    <br>    <br>    public func nodeAt(index: Int) -&gt; Node? {<br>        if index &gt;= 0 {<br>            var node = head<br>            var i = index<br>            while node != nil {<br>                if i == 0 { return node }<br>                i -= 1<br>                node = node!.next<br>            }<br>        }<br>        return nil<br>    }<br>    <br>    public func remove(node: Node) -&gt; String {<br>        let prev = node.previous<br>        let next = node.next<br>        <br>        if let prev = prev {<br>            prev.next = next<br>        } else {<br>            head = next<br>        }<br>        next?.previous = prev<br>        <br>        if next == nil {<br>            tail = prev<br>        }</pre><pre>node.previous = nil<br>        node.next = nil</pre><pre>return node.value<br>    }<br>    <br>    public func removeAll() {<br>        head = nil<br>        tail = nil<br>    }</pre><pre>public var description: String {<br>        var text = &quot;[&quot;<br>        var node = head<br>        while node != nil {<br>            text += &quot;\(node!.value)&quot;<br>            node = node!.next<br>            if node != nil { text += &quot;, &quot; }<br>        }<br>        return text + &quot;]&quot;<br>    }<br>}</pre><h4>2. 3. Stack</h4><ul><li>The data that is inserted later is first subtracted and processed.</li><li>Push and Pop in the same direction: behind the array</li><li>LIFO: Last In First Out</li><li>Application: Function, recursive call</li></ul><pre>struct Stack {<br>    fileprivate var array: [String] = []<br>    <br>    mutating func push(_ element: String) {<br>        array.append(element)<br>    }</pre><pre>mutating func pop() -&gt; String? {<br>        return array.popLast()<br>    }</pre><pre>func peek() -&gt; String? {<br>        return array.last<br>    }<br>}</pre><h4>2. 4. Queue/Dequeue</h4><ul><li>First, the inserted data is first subtracted and processed.</li><li>Insert and delete different directions.</li><li>Enqueue: Behind array</li><li>Dequeue: before array</li><li>FIFO: First In First Out</li></ul><pre>public struct Queue {<br>    fileprivate var list = LinkedList&lt;Int&gt;()<br>    <br>    public mutating func enqueue(_ element: Int) {<br>        list.append(value: element)<br>    }<br>    <br>    public mutating func dequeue() -&gt; Int? {<br>        guard !list.isEmpty, let element = list.first else { return nil }<br>        list.remove(node: element)<br>        return element.value<br>    }<br>    <br>    public func peek() -&gt; Int? {<br>        return list.first?.value<br>    }<br>    <br>    public func description() -&gt; String {<br>        var result = &quot;[&quot;<br>        var i = 0<br>        <br>        while (true) {<br>            let node = list.nodeAt(index: i)!<br>            result = result + String(node.value)<br>            if (node.next == nil) { break } else { result += &quot;,&quot; }<br>            i += 1<br>        }<br>        return result + &quot;]&quot;<br>    }<br>}</pre><h4>2. 5. Priority Queue</h4><p>Insert (x): Insert new element x (Enqueue)</p><pre>func insert(_ x:Int,_ n:Int){<br>    <br>    data.append(x)<br>    var size = n+1<br>    while (size&gt;1 &amp;&amp; data[size/2] &lt; data[size]){<br>        let temp = data[size]<br>        data[size] = data[size/2]<br>        data[size/2] = temp<br>        size = size/2<br>    }<br>}</pre><p>Extract_Max (): Deletes and returns the element with the highest priority value (Dequeue)</p><pre>func Extract_Max(_ n:Int)-&gt; Int{<br>    var result = data[1]</pre><pre>let temp = data[n]<br>    data[n] = data[1]<br>    data[1] = temp</pre><pre>data.removeLast()</pre><pre>maxHeapify(1, n-1)</pre><pre>return result<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa813f981ffe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/journey-to-tech-company/2-list-based-collections-fa813f981ffe">2. List-Based Collections</a> was originally published in <a href="https://medium.com/journey-to-tech-company">Journey to Tech Company</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>