<?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 Onur Uzun on Medium]]></title>
        <description><![CDATA[Stories by Onur Uzun on Medium]]></description>
        <link>https://medium.com/@nonuruzun?source=rss-a6ca17ff373e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4H0ODfki7vFk5mWf2YMZrw.jpeg</url>
            <title>Stories by Onur Uzun on Medium</title>
            <link>https://medium.com/@nonuruzun?source=rss-a6ca17ff373e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:02:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nonuruzun/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[kth smalles/largest element]]></title>
            <link>https://nonuruzun.medium.com/kth-smalles-largest-element-ba29f8e7f294?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba29f8e7f294</guid>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 10:55:50 GMT</pubDate>
            <atom:updated>2021-01-21T10:57:05.858Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using Min Heap</h4><p>We can easily solve this problem in O(nlogk) by using a min-heap. The idea is to construct a min-heap of size k and insert first k elements of array (<em>A[0..k-1]</em>) into the heap. Then for each of the remaining elements of the array (A[k..n-1]), if that element is more than the root of the heap, we replace the root with current element. We repeat this process till the array is exhausted. Now we will be left with k largest elements of the array in the min-heap and k’th largest element will reside at the root of the min-heap.</p><pre>#include &lt;iostream&gt;<br>#include &lt;vector&gt;<br>#include &lt;queue&gt;<br>using namespace std;<br> <br>// Function to find the K&#39;th largest element in the<br>// array using min-heap<br>int FindKthLargest(vector&lt;int&gt; const &amp;A, int k)<br>{<br>    // create a min-heap using std::priority_queue and insert<br>    // first k elements of the array into the heap<br>    // std::greater is used as the comparison function for min-heap<br>    priority_queue&lt;int, vector&lt;int&gt;, greater&lt;&gt;&gt; pq(A.begin(), A.begin() + k);<br> <br>    // do for remaining array elements<br>    for (int i = k; i &lt; A.size(); i++)<br>    {<br>        // if current element is more than the root of the heap<br>        if (A[i] &gt; pq.top())<br>        {<br>            // replace root with the current element<br>            pq.pop();<br>            pq.push(A[i]);<br>        }<br>    }<br> <br>    // return the root of min-heap<br>    return pq.top();<br>}<br> <br>// Find K&#39;th largest element in an array<br>int main()<br>{<br>    vector&lt;int&gt; A  = { 7, 4, 6, 3, 9, 1 };<br>    int k = 2;<br> <br>    cout &lt;&lt; &quot;K&#39;th largest element in the array is &quot; &lt;&lt;<br>            FindKthLargest(A, k);<br> <br>    return 0;<br>}</pre><p>Source: <a href="https://www.techiedelight.com/find-kth-largest-element-array/">https://www.techiedelight.com/find-kth-largest-element-array/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba29f8e7f294" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Struct vs Union]]></title>
            <link>https://nonuruzun.medium.com/struct-vs-union-f7100a3c408a?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7100a3c408a</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Fri, 08 May 2020 07:37:33 GMT</pubDate>
            <atom:updated>2020-05-08T07:37:33.114Z</atom:updated>
            <content:encoded><![CDATA[<p>A structure is a user-defined data type available in C that allows to combining data items of different kinds.</p><p>A union is a special data type available in C that allows storing different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple purposes.</p><p><strong>The purpose of union is <em>to save memory</em> by using the same memory region for storing different objects at different times.</strong></p><pre>struct [structure name]<br>   {<br>       member definition;<br>       member definition;<br>       ...<br>       member definition;<br>   };</pre><pre>union [union name]<br>    {<br>       member definition;<br>       member definition;<br>       ...<br>       member definition;<br>    };</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*JcFPuqT2MzFhmEBpvaQacw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7100a3c408a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices]]></title>
            <link>https://nonuruzun.medium.com/microservices-230e81a09428?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/230e81a09428</guid>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Tue, 10 Dec 2019 13:28:11 GMT</pubDate>
            <atom:updated>2019-12-10T13:28:11.866Z</atom:updated>
            <content:encoded><![CDATA[<h3>Monolithic Applications</h3><p><strong>Too complex</strong></p><p>One major problem is that the application is overwhelmingly complex. It’s simply too large for any single developer to fully understand. As a result, fixing bugs and implementing new features correctly becomes difficult and time consuming.</p><p><strong>Longer start-up time</strong></p><p>The sheer size of the application will also slow down development. The larger the application, the longer the start‑up time is. For example, in a recent survey some developers reported start‑up times as long as 12 minutes.</p><p><strong>It is an obstacle to continuous deployment</strong></p><ul><li>You must redeploy the entire application in order to update any one part of it.</li><li>You have to do extensive manual testing.</li></ul><p><strong>Difficult to scale</strong></p><p>Monolithic applications can also be difficult to scale when different modules have conflicting resource requirements.</p><p>For example, one module might implement CPU‑intensive image processing logic and would ideally be deployed in Amazon <a href="https://aws.amazon.com/about-aws/whats-new/2013/11/14/announcing-new-amazon-ec2-compute-optimized-instances/">EC2 Compute Optimized instances</a>. Another module might be an in‑memory database and best suited for <a href="https://aws.amazon.com/about-aws/whats-new/2014/04/10/r3-announcing-the-next-generation-of-amazon-ec2-memory-optimized-instances/">EC2 Memory‑optimized instances</a>. However, because these modules are deployed together you have to compromise on the choice of hardware.</p><p><strong>Another problem with monolithic applications is reliability.</strong></p><p>Because all modules are running within the same process, a bug in any module, such as a memory leak, can potentially bring down the entire process.</p><p><strong>Monolithic applications make it extremely difficult to adopt new frameworks and languages.</strong></p><p>You are stuck with whatever technology choices you made at the start of the project.</p><h3>Microservices — Tackling the Complexity</h3><p>Many organizations, such as Amazon, eBay, and <a href="https://www.nginx.com/blog/microservices-at-netflix-architectural-best-practices/">Netflix</a>, have solved this problem by adopting what is now known as the <a href="https://microservices.io/patterns/microservices.html">Microservices Architecture pattern</a>. Instead of building a single monstrous, monolithic application, the idea is to split your application into set of smaller, interconnected services.</p><p>A service typically implements a set of distinct features or functionality, such as order management, customer management, etc. Each microservice is a mini‑application that has its own hexagonal architecture consisting of business logic along with various adapters. Some microservices would expose an API that’s consumed by other microservices or by the application’s clients. Other microservices might implement a web UI. At runtime, each instance is often a cloud VM or a Docker container.</p><h3>The Drawbacks of Microservices</h3><p>A major drawback of microservices is the complexity that arises from the fact that a microservices application is a distributed system. Developers need to choose and implement an inter‑process communication mechanism based on either messaging or RPC. Moreover, they must also write code to handle partial failure since the destination of a request might be slow or unavailable. While none of this is rocket science, it’s much more complex than in a monolithic application where modules invoke one another via language‑level method/procedure calls.</p><p>Another challenge with microservices is the partitioned database architecture. Business transactions that update multiple business entities are fairly common. These kinds of transactions are trivial to implement in a monolithic application because there is a single database. In a microservices‑based application, however, you need to update multiple databases owned by different services.</p><p>Testing a microservices application is also much more complex. For example, with a modern framework such as Spring Boot it is trivial to write a test class that starts up a monolithic web application and tests its REST API. In contrast, a similar test class for a service would need to launch that service and any services that it depends upon (or at least configure stubs for those services). Once again, this is not rocket science but it’s important to not underestimate the complexity of doing this.</p><p>Another major challenge with the Microservices Architecture pattern is implementing changes that span multiple services. For example, let’s imagine that you are implementing a story that requires changes to services A, B, and C, where A depends upon B and B depends upon C. In a monolithic application you could simply change the corresponding modules, integrate the changes, and deploy them in one go. In contrast, in a Microservices Architecture pattern you need to carefully plan and coordinate the rollout of changes to each of the services. For example, you would need to update service C, followed by service B, and then finally service A. Fortunately, most changes typically impact only one service and multi‑service changes that require coordination are relatively rare.</p><p>Deploying a microservices‑based application is also much more complex. A monolithic application is simply deployed on a set of identical servers behind a traditional load balancer. Each application instance is configured with the locations (host and ports) of infrastructure services such as the database and a message broker. In contrast, a microservice application typically consists of a large number of services. For example, Hailo has 160 different services and Netflix has over 600 according to <a href="https://twitter.com/adrianco">Adrian Cockcroft</a> <em>[Editor — Hailo has been acquired by MyTaxi.]</em>. Each service will have multiple runtime instances. That’s many more moving parts that need to be configured, deployed, scaled, and monitored. In addition, you will also need to implement a service discovery mechanism (discussed in a later post) that enables a service to discover the locations (hosts and ports) of any other services it needs to communicate with. Traditional trouble ticket‑based and manual approaches to operations cannot scale to this level of complexity. Consequently, successfully deploying a microservices application requires greater control of deployment methods by developers, and a high level of automation.</p><p>One typical starting point is to use a clustering solution, such as <a href="https://kubernetes.io/">Kubernetes</a>, in conjunction with a technology such as Docker.</p><h3>Summary</h3><p>Building complex applications is inherently difficult. A Monolithic architecture only makes sense for simple, lightweight applications. You will end up in a world of pain if you use it for complex applications. The Microservices architecture pattern is the better choice for complex, evolving applications despite the drawbacks and implementation challenges.</p><p>Source: <a href="https://www.nginx.com/blog/introduction-to-microservices/">https://www.nginx.com/blog/introduction-to-microservices/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=230e81a09428" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Compression]]></title>
            <link>https://nonuruzun.medium.com/data-compression-f6ffd50d9713?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6ffd50d9713</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Thu, 01 Aug 2019 09:54:31 GMT</pubDate>
            <atom:updated>2019-08-01T10:15:20.927Z</atom:updated>
            <content:encoded><![CDATA[<h3>LZ77 and LZ78</h3><p>LZ = Lempel Ziv</p><p>Replaces repeated occurrences of data with references.</p><h3>Huffman Coding</h3><p>The algorithm is based on the frequency of occurrence of the data item(byte). The most frequent data items will represented and encoded with a lower number of bits.</p><p>The main idea of the algorithm is create a binary tree, called Huffman tree, based on the bytes frequency on the data, where the leafs are the bytes symbols, and the path from the root to a leaf determines the new representation of that leaf byte.</p><p>Using the text <strong>ABCBAACD </strong>as<strong> </strong>example and applying those steps, we have the following tree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/0*j5a8ymebWw_lb1_G.png" /></figure><p>So the new representation of the bytes on the text are:</p><ul><li>A: 0</li><li>B: 10</li><li>C: 111</li><li>D: 110</li></ul><h4>Conclusion</h4><p>The original representation has 8 bytes(64 bits) and the new representation have only 9 bits, that is <strong>86%</strong> <strong>smaller</strong> than the original.</p><p><a href="https://medium.com/stantmob/data-compression-with-huffman-coding-ad7bcb07c5d5">https://medium.com/stantmob/data-compression-with-huffman-coding-ad7bcb07c5d5</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6ffd50d9713" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Trees]]></title>
            <link>https://nonuruzun.medium.com/binary-trees-992ade3ca39d?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/992ade3ca39d</guid>
            <category><![CDATA[binary-tree]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Mon, 08 Jul 2019 10:58:39 GMT</pubDate>
            <atom:updated>2019-07-09T11:27:47.204Z</atom:updated>
            <content:encoded><![CDATA[<p>A binary tree is made of nodes, where each node contains a “left” reference, a “right” reference, and a data element. The topmost node in the tree is called the root.</p><h4>Advantages of trees</h4><p>Trees are so useful and frequently used, because they have some very serious advantages:</p><ul><li>Trees reflect structural relationships in the data</li><li>Trees are used to represent hierarchies</li><li>Trees provide an efficient insertion and searching</li><li>Trees are very flexible data, allowing to move sub-trees around with minimum effort</li></ul><h4>Traversals</h4><p>A traversal is a process that visits all the nodes in the tree. Since a tree is a nonlinear data structure, there is no unique traversal. We will consider several traversal algorithms with we group in the following two kinds</p><ul><li>depth-first traversal</li><li>breadth-first traversal</li></ul><p>There are three different types of depth-first traversals, :</p><ul><li>PreOrder traversal — visit the parent first and then left and right children;</li><li>InOrder traversal — visit the left child, then the parent and the right child;</li><li>PostOrder traversal — visit left child, then the right child and then the parent;</li></ul><h4>BFS vs DFS for Binary Tree</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/0*vdBUUWVk5oWiyRuz.gif" /></figure><pre>BFS and DFSs of above Tree</pre><pre>Breadth First Traversal : 1 2 3 4 5</pre><pre>Depth First Traversals:<br>      Preorder Traversal : 1 2 4 5 3 <br>      Inorder Traversal  :  4 2 5 1 3 <br>      Postorder Traversal : 4 5 2 3 1</pre><p><strong>Is there any difference in terms of Time Complexity?</strong><br>All four traversals require O(n) time as they visit every node exactly once.</p><p><strong>Is there any difference in terms of Extra Space?</strong><br>There is difference in terms of extra space required.</p><ol><li>Extra Space required for Level Order Traversal is O(w) where w is maximum width of Binary Tree. In level order traversal, queue one by one stores nodes of different level.</li><li>Extra Space required for Depth First Traversals is O(h) where h is maximum height of Binary Tree. In Depth First Traversals, stack (or function call stack) stores all ancestors of a node.</li></ol><p><strong>How to Pick One?</strong></p><ol><li>Extra Space can be one factor (Explained above)</li><li>Depth First Traversals are typically recursive and recursive code requires function call overheads.</li><li>The most important points is, BFS starts visiting nodes from root while DFS starts visiting nodes from leaves. So if our problem is to search something that is more likely to closer to root, we would prefer BFS. And if the target node is close to a leaf, we would prefer DFS.</li></ol><h4>Types of Binary Trees</h4><p>There are 3 different types of binary trees which will be discussed in this lesson: 1) full, 2) complete and 3) perfect.</p><ul><li><strong>Full binary tree</strong>: Every node other than leaf nodes has 2 child nodes.</li><li><strong>Complete binary tree</strong>: All levels are filled except possibly the last one, and all nodes are filled in as far left as possible.</li><li><strong>Perfect binary tree</strong>: All nodes have two children and all leaves are at the same level.</li></ul><p><a href="https://www.geeksforgeeks.org/binary-tree-set-3-types-of-binary-tree/">Binary Tree | Set 3 (Types of Binary Tree) - GeeksforGeeks</a></p><h3>Binary Search Trees</h3><p>We consider a particular kind of a binary tree called a Binary Search Tree (BST), sometimes called <strong>ordered</strong> or <strong>sorted binary trees</strong>. The basic idea behind this data structure is to have such a storing repository that provides the efficient way of data sorting, searching and retrieving.</p><ul><li>The left subtree of a node contains only nodes with keys lesser than the node’s key.</li><li>The right subtree of a node contains only nodes with keys greater than the node’s key.</li><li>The left and right subtree each must also be a binary search tree.</li></ul><p>On average, binary search trees with <em>n</em> nodes have <a href="https://en.wikipedia.org/wiki/Big_O_notation">O</a>(log <em>n</em>)height. However, in the worst case, binary search trees can have O(<em>n</em>) height, when the unbalanced tree resembles a <a href="https://en.wikipedia.org/wiki/Linked_list">linked list</a> (<a href="https://en.wikipedia.org/wiki/Binary_Tree#Types_of_binary_trees">degenerate tree</a>).</p><ul><li><strong>Searching:</strong> For searching element 1, we have to traverse all elements (in order 3, 2, 1). Therefore, searching in binary search tree has worst case complexity of O(n). In general, time complexity is O(h) where <strong>h</strong> is height of BST.</li><li><strong>Insertion:</strong> For inserting element 0, it must be inserted as left child of 1. Therefore, we need to traverse all elements (in order 3, 2, 1) to insert 0 which has worst case complexity of O(n). In general, time complexity is O(h).</li><li><strong>Deletion:</strong> For deletion of element 1, we have to traverse all elements to find 1 (in order 3, 2, 1). Therefore, deletion in binary tree has worst case complexity of O(n). In general, time complexity is O(h).</li></ul><h3>AVL Tree</h3><ul><li>AVL tree is a height balanced tree.</li><li>It is a self-balancing binary search tree.</li></ul><p>AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than 1 (one) for all nodes.</p><p><strong>Why AVL Trees?</strong><br>Most of the BST operations (e.g., search, max, min, insert, delete.. etc) take O(h) time where h is the height of the BST. The cost of these operations may become O(n) for a skewed Binary tree. If we make sure that height of the tree remains O(Logn) after every insertion and deletion, then we can guarantee an upper bound of O(Logn) for all these operations. The height of an AVL tree is always O(Logn) where n is the number of nodes in the tree.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=992ade3ca39d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scam emails I’ve received during apartment search in Germany]]></title>
            <link>https://nonuruzun.medium.com/scam-emails-i-received-during-apartment-search-in-germany-da9da93d9458?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/da9da93d9458</guid>
            <category><![CDATA[email-scam]]></category>
            <category><![CDATA[real-estate]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Thu, 30 Aug 2018 08:29:48 GMT</pubDate>
            <atom:updated>2019-07-04T14:29:06.435Z</atom:updated>
            <content:encoded><![CDATA[<p>If you search a flat in Germany, you will receive tons of scam emails. This one is the first and last(so far) scam mail I actually replied.</p><pre>Good evening,</pre><pre>Thank you for your request in regard to my place (38m², 3rd floor, no elevator!) from Occamstraße 17, Schwabing-Freimann 80802, Munich.<br><br>The rent is 580 €, including the water, TV licence &amp; WIFI and the Kaution is 1160 €.<br><br>The cost for electricity/heating is paid separately, according to your consumption of course. The heating works on electricity (central heating), so the bill may vary between 30-70€ (warm/cold months).<br><br>The move-in date and the contract&#39;s length are up to discussion, as I am flexible with dates, although I would prefer signing a permanent contract.<br><br>Thank you,</pre><pre>Rosanna</pre><p>I didn’t see anything suspicious (Actually I did. The rent was very low for Munich, but who knows maybe I was lucky) so I replied;</p><pre>Hello Rosanna,<br><br>The room and location is perfect for me. I&#39;m interested in your flat and I would be very happy to arrange a visit. We can sign a contract starting from October if it&#39;s suitable for you.</pre><pre>Best,<br>Onur</pre><p>I received the below email and thought “well.. this is a scam obviously because nobody writes that long without boring him/herself”. Nevertheless I gave it a chance. This was the first scam mail I got from a fake mother who is talking about how rude some people are… She’s trying to build trust.</p><pre>Hello,<br><br>I am able to set up a viewing <strong>next week</strong>, as per your convenience.<br><br>The apartment is furnished and equipped. I have the option of moving the furniture into storage, if you want to bring your own (we have a keller in the basement).<br><br>My daughter spent a couple of years in Munich, studying and working for an international sales company. I&#39;m renting the place, as she is starting a new business on her own in our home country Greece.<br><br>I am the owner of the place, therefore you can register at our address (<strong>Anmeldung</strong>) without any problem.<br><br>This is the second time when I try to rent my apartment, I almost had a &quot;deal&quot; with a &quot;nice couple&quot; before, who said that they would definitely rent the apartment and convinced me to come over to Germany. So I got a plane ticket and they didn&#39;t show up. I lost money and precious time on their promise.<br><br>So don&#39;t get me wrong and don&#39;t take it personally, but I don&#39;t want to fall for it once more. I just need to be sure of your seriousness.<br><strong><br>I am interested in knowing how long of a lease are you looking for, and with whom are you going to live in the apartment.</strong><br><br>Also where are you from?<br><br>Cordial greetings,</pre><pre>Rosanna</pre><p>I sent an email to convince her that I’m not wasting her time and thinking very serious about renting her apartment…</p><pre>Hello Rosanna,<br><br>I&#39;m very serious about renting this apartment because the location is very convenient for me. I will start working in a robotic company located in Garching. I was looking for a place somewhere between Munich and Garching and this apartment is very close to U6 line that goes to Garching. I will live in the apartment by myself so 1 room and 38m^2 is enough living space for me. I&#39;m thinking to make a contract for a year first then maybe extend it more later. I would like to bring a couple of furniture (especially my bed) but I can use all the other furniture in the flat.</pre><pre>I&#39;m from Antalya, Turkey. I was living last 6 years in Istanbul then I moved to Stuttgart last year for work purposes.</pre><pre>I can come to Munich this week on 14.08 Tuesday or 16.08 Thursday or next week 21.08 Tuesday or 24.08 Friday between 18:00-19:00.</pre><pre>Best,<br>Onur.</pre><p>And finally she replied with the keyword <strong>Western Union. </strong>But interestingly she’s asking to send some money to myself to prove that I have the money. Of course she (or probably he) can easily collect the money with a fake ID from western union.</p><pre>Dear Onur,<br><br>If you are really interested and decided, you can secure the apartment from now on, and I would keep it available for you until we meet.<br><br>It is unfortunate that my past bitter experience of inviting people to come and view my apartment without any form of confirmation of their financial ability and not keeping up to time as at when scheduled, has brought about great loss to me.<br><br>I&#39;m sure you are honest person so please don&#39;t understand me wrong but some tenants are not really decided or do not have the money to pay the rent and yet they disturb me to arrange a viewing with their friends.<br><br>My husband and I have decided to carry out a simple test on seriousness and financial ability before coming for viewing.<br><br>I want to be sure that when we&#39;ll meet in Munich, it might be a chance that we&#39;ll do the renting papers, sign the renting contract, give you the keys and return to my home if you really like the flat conditions. I will not ask for money in advance before moving in, I don&#39;t need any deposit from you or pay me any money at all.  <br><br>But as a warranty that you really can afford to rent my apartment, I require that you arrange a money transfer, <strong>on your name</strong>!<br>Because I used this system with my daughter when she lived in Munich, here is what I propose:<br><br>Ask a family member to find the nearest Western Union agency, and send you a money transfer with the cost of the security deposit + first month&#39;s rent ( 1160 € + 580 € = 1740 € ) sent to you, and on your name.<br><br>This transfer will be a warranty, so I can be sure that you will wait for me in Munich when I will arrive.<br><br>Example of transfer:<br><br>sender’s name :  <strong>family member</strong>&#39;s name<br><br><br>receiver’s name :    <strong>Onur Uzun</strong><br>receiver’s address : Munich, Germany<br><br>After the transfer is done, you will receive a receipt. You have to take a picture of it and send it to me attached trough e-mail, as evidence. This proof will be enough for me to see that your interest in renting my apartment is real. <br><br>At my turn, I will book the flight ticket immediately and send you a copy of it. Then, we will set up a place and a time when we should meet in Munich.<br> <br>After we meet, you will inspect the apartment and if you want to keep it, we will go to a notary office and do all the needed paperwork. Then, we’ll go together to a bank branch that has a Western Union office and you will collect your money, and make a bank deposit in my personal account where I want to receive the rent payment monthly.<br><br>Please note that I will pay for the notary fees when signing the rental contract.<br><br>Thank you for your time and understanding,</pre><pre>Rosanna</pre><p>Here’s an another one I got recently with similar story. I didn’t bother to reply…</p><pre>Hello,</pre><pre>I just read my email about the apartment . I bought this apartment for my daughter during her studies in Germany. But now she&#39;s back home permanently, and I will rent the apartment.<br>First of all I would like to know a little bit about you, like how many people intending to live in apartment and for how long.<br>The apartment is exactly like you see in the pictures, fully furnished and renovated. Also, very important, utilities (hot / cold water, electricity, wireless broadband Internet access, digital TV, 1 car parking spaces, dishwasher, garbage , microwave, refrigerator and washing machine, etc.) are included in the price of 922 € / month. The security deposit is also 1 month ( 922 € ), and you will receive them back, when you decide to leave the apartment (you will have to give me an answer thirty days in advance). As for me, you can be assured that i will never ask you to leave the apartment. My daughter is building her life here, and i am too old to traveling in Germany, and i not can for disturb you.<br>You can use my furniture, or you can also use your own if you prefer. If you decide to use yours, you will have access to a very large and well ventilated cellar where you can store my furniture.<br>Now a little about me so we can get to know each other better. My name is Christophe Witt and I am a 58 year old man and i work to the CHAMBER OF COMMERCE of Lithuania, planning to retire in the next 2 years.<br>I have a lovely wife, Paula and a Lorena daughter who is 28 years old. I am very proud to say that soon I will be a grandfather. Another member of our family is a 5 year old labrador that we all love as well, I have no problem if you will keep pets in the apartment.<br>The only drawback is that my job does not allow me to leave Lithuania even for a single day. We just hired some new staff and am responsible for their training. But that does not affect everyone at all. <br>I can make some arrangements for renting the apartment from Lithuania . At my expense of course.</pre><pre>All the best from Lithuania<br>Christophe Witt</pre><p>Then I decided to reply old-fart Christophe and ask him an unrelated question to make him go out of the scope…</p><pre>Hey Christophe,</pre><pre>I have a dog too. We should get them together sometime. What do you think?</pre><pre>Best,<br>Onur</pre><p>And he replied my question with a different font and c/p ed the regular answer with another font.</p><pre>Hello Onur,</pre><pre>&lt;different font&gt;</pre><pre>Yes that will be fine about our dogs. let`s talk about the apartment rent,</pre><pre>&lt;/different font&gt;</pre><pre>The apartment is available from now for rent.<br>The visit and the rental will be made with an AirBnb reservation.<br>AirBnb is an online agency made to rent a flat. They are 100% safe. With AirBnb nobody no has lost money.<br>I will try to explain step by step how this will work:</pre><pre>I have left the keys and the contract (from 1 month to 10 years) with Airbnb.<br>1.) To start a new AirBnb official rental transaction, I need your information:<br>Full name, Address, City, Zip code, Country, Your email address, Moving date and for how long you would like to rent<br>2.) With the information you will provide me, I will start the official AirBnb rental transaction online.<br>The transportation of the keys of the floor, permanent property paper and rental contract will be made with the agent of AirBnb.<br>3.) You must deposit in the bank account of AirBnb the first month of rent ( 922 € ) + guarantee ( 922 €) in total 1.844 €.<br>4.) After the payment is made, AirBnb will send the agent with the keys and all the document to your address that you have provided and will accompany you to my flat to make the visit, sign the rental contract and move to the date you want.</pre><pre>I need information from your side so that I can arrange a meeting with one of the agents with Airbnb so you can see and move into the apartment :</pre><pre>Name :<br>Address :<br>Post Code :<br>City :<br>Country:<br>How fast you want to move:<br>How old are you:<br>Photo of you or passport, ID attached by email:<br>How many people will stay in the apartment:<br>Phone number I can contact you with:<br>Your personal e-mail address:</pre><pre>After receiving this information, I will agree with Airbnb future details.<br>You will receive news about all future steps as soon as possible.</pre><pre>In case you do not rent it, AirBnb will reimburse your money. I&#39;ll wait for the news!</pre><pre>Thank you for your time and I will wait for feedback.</pre><p>I received many more scam mails like these ones. Keywords are sending money through airbnb or western union. I appreciate that they are really trying… Some might think ”Good for you little scammer. You came a long way since <em>Nigerian Prince</em>”. But there’s a reason why Nigerian scammers say they’re from Nigeria.</p><p><em>A study that revealed Nigerian email scams are purposefully designed to look ridiculous so as to provide a better sorting mechanism for time-thrifty scam artists.</em></p><p>Dear scammers; I suggest you to read this article: <a href="https://www.microsoft.com/en-us/research/publication/why-do-nigerian-scammers-say-they-are-from-nigeria">https://www.microsoft.com/en-us/research/publication/why-do-nigerian-scammers-say-they-are-from-nigeria</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da9da93d9458" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lambdas]]></title>
            <link>https://nonuruzun.medium.com/lambdas-b91b1c3da1f6?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b91b1c3da1f6</guid>
            <category><![CDATA[cplusplus]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 11:31:45 GMT</pubDate>
            <atom:updated>2018-07-10T11:31:45.590Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11">What is a lambda expression in C++11?</a></p><p>The difference between a captured argument and a passing argument could be seen with an analogy. Consider the following function object:</p><pre>struct Capture {<br>  int &amp;i;<br>  int const j;<br>public:<br>  Capture(int &amp;_i, int &amp;_j) : i(_i), j(_j) {}<br>  int operator()(int const a, int const b) {<br>    i *= j;<br>    return a * b;<br>  }<br>};</pre><p>In function object class Capture there are two member variables i and j. There&#39;s also overloaded operator() which takes two input arguments. Now consider the following lambda:</p><pre>int i, j;<br>[&amp;i, j](int const a, int const b) {<br>  i *= j;<br>  return a * b;<br>};</pre><p>The member variables of class Capture are in analogy with the lambda capture (i.e., [&amp;i, j]), whereas input arguments of overloaded operator() a and b are in analogy with input arguments a and b of the lambda shown above.</p><p>That is, if you consider a lambda as a function object, its capture is the state of the function object (i.e., its member variables) whereas its input arguments would be the input arguments of the overloaded operator().</p><p><a href="https://stackoverflow.com/questions/31038437/difference-between-capture-and-passing-an-argument-in-lambda-functions">Difference between capture and passing an argument in lambda functions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b91b1c3da1f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MQTT and Mosquitto]]></title>
            <link>https://nonuruzun.medium.com/mqtt-and-mosquitto-7284d209d80b?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7284d209d80b</guid>
            <category><![CDATA[mosquitto]]></category>
            <category><![CDATA[mqtt]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 11:17:18 GMT</pubDate>
            <atom:updated>2018-07-10T11:17:18.034Z</atom:updated>
            <content:encoded><![CDATA[<p><em>MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol.</em></p><p>Eclipse Mosquitto is an open source message broker that implements the MQTT protocol.</p><h3>MQTT Mosquitto broker with SSL/TLS transport security</h3><p><strong>Mosquitto configuration:</strong><br>To configure the Mosquito broker we need first to copy the certificates and key files to a known directory. We will create a <strong>certs</strong> directory under <strong>/etc/mosquitto.</strong></p><pre><strong>ca.crt –</strong> The CA (Certificate Authority, who published the host certificate) public certificate.<br><strong>hostname.crt –</strong> The hostname, that will run the mosquitto broker, public certificate.<br><strong>hostname.key –</strong> The hostname private key.</pre><p>After this we can modify the mosquitto configuration file. One important thing to keep in mind is that lines must be following each other without blank lines after the <strong>listener</strong> directive.</p><pre><strong># Plain MQTT protocol</strong><br>listener 1883<br><br># End of plain MQTT configuration<br><br><strong># MQTT over TLS/SSL</strong><br>listener 8883<br>cafile /etc/mosquitto/certs/ca.crt<br>certfile /etc/mosquitto/certs/hostname.crt<br>keyfile /etc/mosquitto/certs/hostname.key<br><br># End of MQTT over TLS/SLL configuration<br><br><strong># Plain WebSockets configuration</strong><br>listener 9001<br>protocol websockets<br><br># End of plain Websockets configuration<br><br><strong># WebSockets over TLS/SSL</strong><br>listener 9883<br>protocol websockets<br>cafile /etc/mosquitto/certs/ca.crt<br>certfile /etc/mosquitto/certs/hostname.crt<br>keyfile /etc/mosquitto/certs/hostname.key</pre><p><strong>Authentication by using client certificates</strong><br>Using client certificates, signed by a certificate authority, assures the client identity. The certificate authority used must be the same used by the server certificates and is only supported over TLS/SSL.<br>For using client certificates for authentication, we need to change the listener configuration for TLS/SSL by adding the following directives:</p><pre># MQTT over TLS/SSL<br>listener 8883<br>cafile /etc/mosquitto/certs/ca.crt<br>certfile /etc/mosquitto/certs/hostname.crt<br>keyfile /etc/mosquitto/certs/hostname.key<br><strong>require_certificate true<br>use_identity_as_username true</strong></pre><p>The <strong>require_certificate</strong> directive with the value <strong>true</strong> means that clients must now provide a client certificate to connect.<br>The <strong>use_identity_as_username</strong> means that the user name of the connecting user is taken from the CN (Common Name) property of the certificate, otherwise we still need to provide an user and password.</p><p>And we should have three files, two of them the user1.crt, the user certificate, and the user1.key, the user1 private key.</p><pre># mosquitto_pub --cafile /etc/mosquitto/certs/ca.crt -h localhost -t &quot;test&quot; -m &quot;message&quot; -p 8883 -d  --cert user1.crt --key user1.key <br>Client mosqpub/30264-pcortex sending CONNECT<br>Client mosqpub/30264-pcortex received CONNACK<br>Client mosqpub/30264-pcortex sending PUBLISH (d0, q0, r0, m1, &#39;test&#39;, ... (7 bytes))<br>Client mosqpub/30264-pcortex sending DISCONNECT</pre><p>Source:</p><ul><li><a href="https://primalcortex.wordpress.com/2016/11/08/mqtt-mosquitto-broker-client-authentication-and-client-certificates/">MQTT Mosquitto broker - Client Authentication and Client Certificates</a></li><li><a href="https://primalcortex.wordpress.com/2016/03/31/mqtt-mosquitto-broker-with-ssltls-transport-security/">MQTT Mosquitto broker with SSL/TLS transport security</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7284d209d80b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Algorithms]]></title>
            <link>https://nonuruzun.medium.com/algorithms-ceafa828f175?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ceafa828f175</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 14:48:12 GMT</pubDate>
            <atom:updated>2019-07-08T11:22:18.845Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.geeksforgeeks.org/lmns-algorithms-gq/">LMNs- Algorithms - GeeksforGeeks</a></p><p><a href="https://www.geeksforgeeks.org/commonly-asked-data-structure-interview-questions-set-1/">https://www.geeksforgeeks.org/commonly-asked-data-structure-interview-questions-set-1/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*Z1ssvqTKv0AXAvGXaNKAPQ.png" /></figure><h3>Binary Search</h3><p>Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*NYh3Vm9UNkxibsrj.png" /></figure><pre>int binarySearch(int arr[], int l, int r, int x)<br>{<br>   if (r &gt;= l)<br>   {<br>        int mid = l + (r - l)/2;<br> <br>        // If the element is present at the middle <br>        // itself<br>        if (arr[mid] == x)  <br>            return mid;<br> <br>        // If element is smaller than mid, then <br>        // it can only be present in left subarray<br>        if (arr[mid] &gt; x) <br>            return binarySearch(arr, l, mid-1, x);<br> <br>        // Else the element can only be present<br>        // in right subarray<br>        return binarySearch(arr, mid+1, r, x);<br>   }<br> <br>   // We reach here when element is not <br>   // present in array<br>   return -1;<br>}</pre><h3>Breadth First Search (BFS) vs Deep First Search (DFS)</h3><p>There are two search algorithms exist for binary tree: <em>breadth-first</em> search (BFS) and <em>depth-first</em> search (DFS).</p><p>The best way to understand them is visually</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2flUmswX4qyLGJ4d.png" /></figure><p>BFS search nodes level by level, starting from the root node. Then checking its children. Then children for children and so on. Until all nodes are processed or node which satisfies search condition is found.</p><p>DFS behave differently. It checks all nodes from leftmost path from the root to the leaf, then jumps up and check right node and so on.</p><p>For classic binary trees BFS implemented using Queue data structure (LinkedList implements Queue)</p><pre><strong>public</strong> BinaryNode<strong>&lt;</strong>T<strong>&gt;</strong> <strong>bfs(</strong>Predicate<strong>&lt;</strong>T<strong>&gt;</strong> predicate<strong>)</strong> <strong>{</strong><br>    Queue<strong>&lt;</strong>BinaryNode<strong>&lt;</strong>T<strong>&gt;&gt;</strong> queue <strong>=</strong> <strong>new</strong> LinkedList<strong>&lt;&gt;();</strong><br>    queue<strong>.</strong>offer<strong>(this);</strong><br>    <strong>while</strong> <strong>(!</strong>queue<strong>.</strong>isEmpty<strong>())</strong> <strong>{</strong><br>        BinaryNode<strong>&lt;</strong>T<strong>&gt;</strong> node <strong>=</strong> queue<strong>.</strong>poll<strong>();</strong><br>        <strong>if</strong> <strong>(</strong>predicate<strong>.</strong>test<strong>(</strong>node<strong>.</strong>data<strong>))</strong> <strong>return</strong> node<strong>;</strong><br>        <strong>if</strong> <strong>(</strong>node<strong>.</strong>left <strong>!=</strong> <strong>null)</strong> queue<strong>.</strong>offer<strong>(</strong>node<strong>.</strong>left<strong>);</strong><br>        <strong>if</strong> <strong>(</strong>node<strong>.</strong>right <strong>!=</strong> <strong>null)</strong> queue<strong>.</strong>offer<strong>(</strong>node<strong>.</strong>right<strong>);</strong><br>    <strong>}</strong><br>    <strong>return</strong> <strong>null;</strong><br><strong>}</strong></pre><pre><strong>public</strong> BinaryNode<strong>&lt;</strong>T<strong>&gt;</strong> <strong>dfs(</strong>Predicate<strong>&lt;</strong>T<strong>&gt;</strong> predicate<strong>)</strong> <strong>{</strong><br>    Stack<strong>&lt;</strong>BinaryNode<strong>&lt;</strong>T<strong>&gt;&gt;</strong> stack <strong>=</strong> <strong>new</strong> Stack<strong>&lt;&gt;();</strong><br>    stack<strong>.</strong>push<strong>(this);</strong><br>    <strong>while</strong> <strong>(!</strong>stack<strong>.</strong>isEmpty<strong>())</strong> <strong>{</strong><br>        BinaryNode<strong>&lt;</strong>T<strong>&gt;</strong> node <strong>=</strong> stack<strong>.</strong>pop<strong>();</strong><br>        <strong>if</strong> <strong>(</strong>predicate<strong>.</strong>test<strong>(</strong>node<strong>.</strong>data<strong>))</strong> <strong>return</strong> node<strong>;</strong><br>        <strong>if</strong> <strong>(</strong>node<strong>.</strong>right <strong>!=</strong> <strong>null)</strong> stack<strong>.</strong>push<strong>(</strong>node<strong>.</strong>right<strong>);</strong><br>        <strong>if</strong> <strong>(</strong>node<strong>.</strong>left <strong>!=</strong> <strong>null)</strong> stack<strong>.</strong>push<strong>(</strong>node<strong>.</strong>left<strong>);</strong><br>    <strong>}</strong><br>    <strong>return</strong> <strong>null;</strong><br><strong>}</strong></pre><p>Source: <a href="http://mishadoff.com/blog/dfs-on-binary-tree-array/">http://mishadoff.com/blog/dfs-on-binary-tree-array/</a></p><h3>Dijkstra’s shortest path algorithm</h3><p><a href="https://brilliant.org/wiki/dijkstras-short-path-finder/">Dijkstra&#39;s Shortest Path Algorithm | Brilliant Math &amp; Science Wiki</a></p><p><strong>A* Algorithm:</strong> It is an extension of <a href="https://en.wikipedia.org/wiki/Edsger_Dijkstra">Edsger Dijkstra’s</a> <a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm">1959 algorithm</a>. A* achieves better performance by using <a href="https://en.wikipedia.org/wiki/Heuristic_(computer_science)">heuristics</a> to guide its search.</p><p><strong>What’s the difference between a Graph and a Tree?</strong></p><p>A tree is a special type of graph, i.e., a minimal graph, where there is only one path between two vertices.</p><p><strong>Bubble Sort</strong></p><p>Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.</p><pre>// An optimized version of Bubble Sort<br>void bubbleSort(int arr[], int n)<br>{<br>   int i, j;<br>   bool swapped;<br>   for (i = 0; i &lt; n-1; i++)<br>   {<br>     swapped = false;<br>     for (j = 0; j &lt; n-i-1; j++)<br>     {<br>        if (arr[j] &gt; arr[j+1])<br>        {<br>           swap(&amp;arr[j], &amp;arr[j+1]);<br>           swapped = true;<br>        }<br>     }<br> <br>     // IF no two elements were swapped by inner loop, then break<br>     if (swapped == false)<br>        break;<br>   }<br>}</pre><p><strong>Insertion Sort</strong></p><pre>/* Function to sort an array using insertion sort*/<br>void insertionSort(int arr[], int n)<br>{<br>   int i, key, j;<br>   for (i = 1; i &lt; n; i++)<br>   {<br>       key = arr[i];<br>       j = i-1;<br> <br>       /* Move elements of arr[0..i-1], that are<br>          greater than key, to one position ahead<br>          of their current position */<br>       while (j &gt;= 0 &amp;&amp; arr[j] &gt; key)<br>       {<br>           arr[j+1] = arr[j];<br>           j = j-1;<br>       }<br>       arr[j+1] = key;<br>   }<br>}</pre><h3>K’th Smallest/Largest Element in Unsorted Array</h3><p>Quick Select: This is an optimization. If QuickSort is used as a sorting algorithm in first step. In QuickSort, we pick a pivot element, then move the pivot element to its correct position and partition the array around it. The idea is, not to do complete quicksort, but stop at the point where pivot itself is k’th smallest element. Also, not to recur for both left and right sides of pivot, but recur for one of them according to the position of pivot. The worst case time complexity of this method is O(n2), but it works in O(n) on average.</p><p><a href="https://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array-set-2-expected-linear-time/">K&#39;th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time) - GeeksforGeeks</a></p><h3>Given a sorted array and a number x, find the pair in array whose sum is closest to x</h3><pre>1) Initialize a variable diff as infinite (Diff is used to store the <br>   difference between pair and x).  We need to find the minimum diff.<br>2) Initialize two index variables l and r in the given sorted array.<br>       (a) Initialize first to the leftmost index:  l = 0<br>       (b) Initialize second  the rightmost index:  r = n-1<br>3) Loop while l &lt; r.<br>       (a) If  abs(arr[l] + arr[r] - x) &lt; diff  then <br>           update diff and result <br>       (b) Else if(arr[l] + arr[r] &lt;  x )  then l++<br>       (c) Else r--</pre><p>Code:</p><pre>// Prints the pair with sum closest to x<br>void printClosest(int arr[], int n, int x)<br>{<br>    int res_l, res_r;  // To store indexes of result pair<br> <br>    // Initialize left and right indexes and difference between<br>    // pair sum and x<br>    int l = 0, r = n-1, diff = INT_MAX;<br> <br>    // While there are elements between l and r<br>    while (r &gt; l)<br>    {<br>       // Check if this pair is closer than the closest pair so far<br>       if (abs(arr[l] + arr[r] - x) &lt; diff)<br>       {<br>           res_l = l;<br>           res_r = r;<br>           diff = abs(arr[l] + arr[r] - x);<br>       }<br> <br>       // If this pair has more sum, move to smaller values.<br>       if (arr[l] + arr[r] &gt; x)<br>           r--;<br>       else // Move to larger values<br>           l++;<br>    }<br> <br>    cout &lt;&lt;&quot; The closest pair is &quot; &lt;&lt; arr[res_l] &lt;&lt; &quot; and &quot; &lt;&lt; arr[res_r];<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ceafa828f175" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtual inheritance to solve diamond problem]]></title>
            <link>https://nonuruzun.medium.com/virtual-inheritance-to-solve-diamond-problem-efe433b3e1df?source=rss-a6ca17ff373e------2</link>
            <guid isPermaLink="false">https://medium.com/p/efe433b3e1df</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Onur Uzun]]></dc:creator>
            <pubDate>Tue, 24 Apr 2018 12:05:39 GMT</pubDate>
            <atom:updated>2019-06-07T11:59:05.376Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>You want:</strong> (Achievable with virtual inheritance)</p><pre>  A  <br> / \  <br>B   C  <br> \ /  <br>  D</pre><p><strong>And not:</strong> (What happens without virtual inheritance)</p><pre>A   A  <br>|   |<br>B   C  <br> \ /  <br>  D</pre><p>Virtual inheritance means that there will be only 1 instance of the base A class not 2.</p><p>Your type D would have 2 vtable pointers (you can see them in the first diagram), one for B and one for C who virtually inherit A. D&#39;s object size is increased because it stores 2 pointers now; however there is only one A now.</p><p>So B::A and C::A are the same and so there can be no ambiguous calls from D. If you don&#39;t use virtual inheritance you have the second diagram above. And any call to a member of A then becomes ambiguous and you need to specify which path you want to take.</p><p><strong>Problematic:</strong></p><pre><strong>struct</strong> Animal {<br>  <strong>virtual</strong> ~Animal() { }<br>  <strong>virtual</strong> void eat();<br>};<br><br><strong>struct</strong> Mammal : Animal {<br>  <strong>virtual</strong> void breathe();<br>};<br><br><strong>struct</strong> WingedAnimal : Animal {<br>  <strong>virtual</strong> void flap();<br>};<br><br><em>// A bat is a winged mammal</em><br><strong>struct</strong> Bat : Mammal, WingedAnimal {<br>};<br><br>Bat bat;</pre><p><strong>Solution:</strong></p><pre><strong>struct</strong> Animal {<br>  <strong>virtual</strong> ~Animal() { }<br>  <strong>virtual</strong> void eat();<br>};<br><br><em>// Two classes virtually inheriting Animal:</em><br><strong>struct</strong> Mammal : <strong>virtual</strong> Animal {<br>  <strong>virtual</strong> void breathe();<br>};<br><br><strong>struct</strong> WingedAnimal : <strong>virtual</strong> Animal {<br>  <strong>virtual</strong> void flap();<br>};<br><br><em>// A bat is still a winged mammal</em><br><strong>struct</strong> Bat : Mammal, WingedAnimal {<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efe433b3e1df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>