<?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 Vamsi Tallapudi on Medium]]></title>
        <description><![CDATA[Stories by Vamsi Tallapudi on Medium]]></description>
        <link>https://medium.com/@vamsitallapudi?source=rss-54fbb60e30e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cQzYZFD4O1fAONdae1OS2Q.jpeg</url>
            <title>Stories by Vamsi Tallapudi on Medium</title>
            <link>https://medium.com/@vamsitallapudi?source=rss-54fbb60e30e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 22:18:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vamsitallapudi/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[RxJava create Operators — Operators for Creating Observables — RxJava Tutorial #4]]></title>
            <link>https://medium.com/@vamsitallapudi/rxjava-create-operators-operators-for-creating-observables-rxjava-tutorial-4-20c5935124c?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/20c5935124c</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Sun, 20 Jan 2019 19:05:21 GMT</pubDate>
            <atom:updated>2019-01-20T19:05:32.862Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*J4plVUjDs7GQasd4.jpg" /></figure><p>In this article we will discuss about various RxJava create operators in depth with examples. Here we will discuss how to create Observables using various operators like Create, From, Just, Differ, etc.</p><blockquote>This article is part of RxJava Intro series. You can checkout the entire series here:</blockquote><ul><li><a href="https://www.coderefer.com/rxandroid-tutorial-getting-started/">RxAndroid Introduction</a></li><li><a href="https://www.coderefer.com/rxandroid-example-tutorial/">RxAndroid Example — RxJava Tutorial #2</a></li><li><a href="https://www.coderefer.com/rxjava-operators/">RxJava Operators In General — RxJava Tutorial #3</a></li><li>RxJava Operators for Creating Observables — RxJava Tutorial #4 — You are Here</li><li>RxJava Operators for Transforming Observables — RxJava Tutorial #5 — Coming Up</li><li>RxJava Operators for Filtering Observables — RxJava Tutorial #6 — Coming Up</li><li>RxJava Operators for Combining Observables — RxJava Tutorial #7 — Coming Up</li></ul><p>Let us explore these RxJava create operators one by one.</p><h4>RxJava Create Operators</h4><p>Create</p><p>Create operator helps creating an Observable from scratch by calling observer methods programmatically. It creates only one Observable for all Observers.</p><p>rxjava create operator block diagram</p><p>We have already seen an example on how to create an Observable using Create Operator. Let us re-collect the same by creating one more Observable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e82ffeb878b022c9ee8ae09d92ab35b1/href">https://medium.com/media/e82ffeb878b022c9ee8ae09d92ab35b1/href</a></iframe><p>In the above example, you can identify that in Line 48, we created an Observable using Create Operator. If we dive into <a href="http://reactivex.io/RxJava/javadoc/io/reactivex/Observable.html#create-io.reactivex.ObservableOnSubscribe-">RxJava documentation link</a> for create() we observe that it does not take any values. Hence we declared the values as list and iterated through them using onNext() function in line 49–50.</p><p>Here is the output:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f81193b0db6eb69888c78fb9c9639e4e/href">https://medium.com/media/f81193b0db6eb69888c78fb9c9639e4e/href</a></iframe><p>Defer</p><p>Defer differs from create in a way that Defer does not create an <strong>Observable</strong> unless and until an <strong>Observer</strong> is subscribed to it. It waits until an Observer subscribes and generate a Fresh Observable with fresh data. So even though the Observer thinks it is subscribing to Same Observable, it gets a Fresh Observable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tm6Va4CVF0zEpVAz.png" /></figure><p>Advantages</p><p>As this Operator waits till last minute to create new Observable, this ensures that the Observable always contains fresh Data. So this Operator is mostly used when intended to fetch freshest Data</p><p>Example</p><p>Here, I’ve created an Observable using Defer Operator as shown in the below example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3947e5675512cf06c00a3d1f371e6d15/href">https://medium.com/media/3947e5675512cf06c00a3d1f371e6d15/href</a></iframe><p>In the above example, we created a TestClass by initializing a variable named str to “Hello”. I’ve taken two types of observable — one is with <strong>Just </strong>operator and other is with <strong>Defer </strong>operator.</p><p>In line 24, I’ve modified the str value to “World”. In lines 25, 30 we subscribed to both observables. Now If we see the logcat, the output is printed as follows:</p><figure><img alt="defer output" src="https://cdn-images-1.medium.com/max/1024/0*1inVv4w6ayQe-_yW.png" /></figure><p>We can clearly see that <strong>Defer </strong>operator is fetching the latest data by creating a fresh Observable.</p><p>From</p><p><strong>From</strong> operator is used to transform objects like lists, arrays, futures etc into Observables.</p><figure><img alt="rxjava create operators" src="https://cdn-images-1.medium.com/max/1024/0*pVnmPG0Vx4qYfK9I.png" /></figure><p>from operator illustration</p><p>There are different methods for transforming different objects like fromArray(), fromCallable(), fromFuture(), fromIterable(), fromPublisher(). More info is provided at the <a href="https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#from">RxJava Wiki Link.</a></p><p>Example</p><p>Here I will consider an example using fromIterable where I will be converting arraylist into Observables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc8c70cd3e6c84662df4f0b40e88e6b4/href">https://medium.com/media/fc8c70cd3e6c84662df4f0b40e88e6b4/href</a></iframe><p>In Line 22, I’ve transformed the numList to Observable.</p><p><strong>Output:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dea878cf449202225957218726c3c4ab/href">https://medium.com/media/dea878cf449202225957218726c3c4ab/href</a></iframe><p>Interval</p><p>This operator creates an Observable that emits a sequence of Integers with a given particular interval of time.</p><p>Interal operator illustration</p><p>Example</p><p>Below is the example where I used Interval Operator to create Observable and print Integer starting from 0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d88e5d4530e66c8babc6e04511fcbf/href">https://medium.com/media/99d88e5d4530e66c8babc6e04511fcbf/href</a></iframe><p>In line 20, I created a clock Observable using Interval Operator and given it an interval of 1 second. Now the output for this above will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf780f479066dadd809442ce5ac306a/href">https://medium.com/media/cbf780f479066dadd809442ce5ac306a/href</a></iframe><p>This will print until the activity is destroyed as we are disposing disposable. Be careful that if we don’t dispose the disposable, it will continue to printing the values even if we exit the activity.</p><p>Just</p><p>Just Operator converts an item into an Observable that emits that item. Here whatever we pass in as arguments, it is converted to an Observable and will be emitted. The max arguments that can be passed in <strong>Just</strong> Operator are 1 to 10 (so min of 1 argument and max of 10).</p><p>Example</p><p>Here is the first example of creation of Observable using <strong>Just</strong> Operator where I passed the numbers 1, 2, 3, 4 directly as arguments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb75c1238ae852fd4046aaf5b41a6ee3/href">https://medium.com/media/cb75c1238ae852fd4046aaf5b41a6ee3/href</a></iframe><p>The Output for the above is :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7aab9b73aef931bd8c3ea78c38eea9c7/href">https://medium.com/media/7aab9b73aef931bd8c3ea78c38eea9c7/href</a></iframe><p>We can also pass List as a parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a9842442b68d527f8ab01cd40407c01/href">https://medium.com/media/9a9842442b68d527f8ab01cd40407c01/href</a></iframe><p>The output will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48efa1367f2190a36cc7d34d6c5f48c0/href">https://medium.com/media/48efa1367f2190a36cc7d34d6c5f48c0/href</a></iframe><p>Range</p><p>Range Operator creates an Observable that emits a particular range of Integers. It takes 2 arguments — starting integer n and length m, so that it starts emitting integers from the starting integer n to n+m-1.</p><figure><img alt="rxjava operators range" src="https://cdn-images-1.medium.com/max/1024/0*JB4-gXM6g4-4c7Pk.png" /></figure><p>Example</p><p>Here is the example where we created an Observable using Range Operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4deb984dda12fd07e9a7d7becdf02d48/href">https://medium.com/media/4deb984dda12fd07e9a7d7becdf02d48/href</a></iframe><p>The output of the above example is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b063f98b1f7c2c2b3601b7fb4f52b317/href">https://medium.com/media/b063f98b1f7c2c2b3601b7fb4f52b317/href</a></iframe><p>Repeat</p><p>Repeat Operator is a simple operator which emits the same item multiple times</p><p>Example</p><p>Let us see its implementation with example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd01fda1ad6271d02d23adc78f2f00a0/href">https://medium.com/media/cd01fda1ad6271d02d23adc78f2f00a0/href</a></iframe><p>The output for the above is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a663ec38e5826e1fee5b5ec94b6701af/href">https://medium.com/media/a663ec38e5826e1fee5b5ec94b6701af/href</a></iframe><p>Timer</p><p>Timer operator creates an Observable that emits a particular item after a given delay.</p><p>Example</p><p>Here is the example of timer operator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8ae6d356713393f022c32a2e144a15f/href">https://medium.com/media/b8ae6d356713393f022c32a2e144a15f/href</a></iframe><p>The output for the above is :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abc38b4f69e122c7449f5191461d1ea4/href">https://medium.com/media/abc38b4f69e122c7449f5191461d1ea4/href</a></iframe><p>This completes our tutorial on RxJava create Operators which we use to create Observables. In the next tutorial, we will focus on RxJava’s Operators for Transforming Observables along with examples.</p><p>All the code for the above examples can be found in the following <a href="https://github.com/vamsitallapudi/RxAndroid-Examples">Github link</a>. Hope this article is useful to you. Make sure you subscribe for the mail to notify about the latest articles first. Let me know if any queries through comment section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20c5935124c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxJava create Operators — Operators for Creating Observables — RxJava Tutorial #4]]></title>
            <link>https://medium.com/@vamsitallapudi/rxjava-create-operators-operators-for-creating-observables-rxjava-tutorial-4-b842d8287bf1?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b842d8287bf1</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Sun, 20 Jan 2019 19:05:21 GMT</pubDate>
            <atom:updated>2019-01-20T19:05:40.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*ecqFlHUuTPFFe9z0.jpg" /></figure><p>In this article we will discuss about various RxJava create operators in depth with examples. Here we will discuss how to create Observables using various operators like Create, From, Just, Differ, etc.</p><blockquote>This article is part of RxJava Intro series. You can checkout the entire series here:</blockquote><ul><li><a href="https://www.coderefer.com/rxandroid-tutorial-getting-started/">RxAndroid Introduction</a></li><li><a href="https://www.coderefer.com/rxandroid-example-tutorial/">RxAndroid Example — RxJava Tutorial #2</a></li><li><a href="https://www.coderefer.com/rxjava-operators/">RxJava Operators In General — RxJava Tutorial #3</a></li><li>RxJava Operators for Creating Observables — RxJava Tutorial #4 — You are Here</li><li>RxJava Operators for Transforming Observables — RxJava Tutorial #5 — Coming Up</li><li>RxJava Operators for Filtering Observables — RxJava Tutorial #6 — Coming Up</li><li>RxJava Operators for Combining Observables — RxJava Tutorial #7 — Coming Up</li></ul><p>Let us explore these RxJava create operators one by one.</p><h4>RxJava Create Operators</h4><p>Create</p><p>Create operator helps creating an Observable from scratch by calling observer methods programmatically. It creates only one Observable for all Observers.</p><figure><img alt="rxjava create operator" src="https://cdn-images-1.medium.com/max/1024/0*12LE5kN03UYaumIz.png" /></figure><p>rxjava create operator block diagram</p><p>We have already seen an example on how to create an Observable using Create Operator. Let us re-collect the same by creating one more Observable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e82ffeb878b022c9ee8ae09d92ab35b1/href">https://medium.com/media/e82ffeb878b022c9ee8ae09d92ab35b1/href</a></iframe><p>In the above example, you can identify that in Line 48, we created an Observable using Create Operator. If we dive into <a href="http://reactivex.io/RxJava/javadoc/io/reactivex/Observable.html#create-io.reactivex.ObservableOnSubscribe-">RxJava documentation link</a> for create() we observe that it does not take any values. Hence we declared the values as list and iterated through them using onNext() function in line 49–50.</p><p>Here is the output:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f81193b0db6eb69888c78fb9c9639e4e/href">https://medium.com/media/f81193b0db6eb69888c78fb9c9639e4e/href</a></iframe><p>Defer</p><p>Defer differs from create in a way that Defer does not create an <strong>Observable</strong> unless and until an <strong>Observer</strong> is subscribed to it. It waits until an Observer subscribes and generate a Fresh Observable with fresh data. So even though the Observer thinks it is subscribing to Same Observable, it gets a Fresh Observable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MNRB77vGkLrrvyUI.png" /></figure><p>Advantages</p><p>As this Operator waits till last minute to create new Observable, this ensures that the Observable always contains fresh Data. So this Operator is mostly used when intended to fetch freshest Data</p><p>Example</p><p>Here, I’ve created an Observable using Defer Operator as shown in the below example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3947e5675512cf06c00a3d1f371e6d15/href">https://medium.com/media/3947e5675512cf06c00a3d1f371e6d15/href</a></iframe><p>In the above example, we created a TestClass by initializing a variable named str to “Hello”. I’ve taken two types of observable — one is with <strong>Just </strong>operator and other is with <strong>Defer </strong>operator.</p><p>In line 24, I’ve modified the str value to “World”. In lines 25, 30 we subscribed to both observables. Now If we see the logcat, the output is printed as follows:</p><figure><img alt="defer output" src="https://cdn-images-1.medium.com/max/1024/0*NSMgLf07GQ0qqZAz.png" /></figure><p>We can clearly see that <strong>Defer </strong>operator is fetching the latest data by creating a fresh Observable.</p><p>From</p><p><strong>From</strong> operator is used to transform objects like lists, arrays, futures etc into Observables.</p><figure><img alt="rxjava create operators" src="https://cdn-images-1.medium.com/max/1024/0*h6uUE2hehwi3UZq_.png" /></figure><p>from operator illustration</p><p>There are different methods for transforming different objects like fromArray(), fromCallable(), fromFuture(), fromIterable(), fromPublisher(). More info is provided at the <a href="https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#from">RxJava Wiki Link.</a></p><p>Example</p><p>Here I will consider an example using fromIterable where I will be converting arraylist into Observables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc8c70cd3e6c84662df4f0b40e88e6b4/href">https://medium.com/media/fc8c70cd3e6c84662df4f0b40e88e6b4/href</a></iframe><p>In Line 22, I’ve transformed the numList to Observable.</p><p><strong>Output:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dea878cf449202225957218726c3c4ab/href">https://medium.com/media/dea878cf449202225957218726c3c4ab/href</a></iframe><p>Interval</p><p>This operator creates an Observable that emits a sequence of Integers with a given particular interval of time.</p><figure><img alt="rxjava create operators" src="https://cdn-images-1.medium.com/max/1024/0*NGbBQ25go0q2yT4g.png" /></figure><p>Interal operator illustration</p><p>Example</p><p>Below is the example where I used Interval Operator to create Observable and print Integer starting from 0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d88e5d4530e66c8babc6e04511fcbf/href">https://medium.com/media/99d88e5d4530e66c8babc6e04511fcbf/href</a></iframe><p>In line 20, I created a clock Observable using Interval Operator and given it an interval of 1 second. Now the output for this above will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf780f479066dadd809442ce5ac306a/href">https://medium.com/media/cbf780f479066dadd809442ce5ac306a/href</a></iframe><p>This will print until the activity is destroyed as we are disposing disposable. Be careful that if we don’t dispose the disposable, it will continue to printing the values even if we exit the activity.</p><p>Just</p><p>Just Operator converts an item into an Observable that emits that item. Here whatever we pass in as arguments, it is converted to an Observable and will be emitted. The max arguments that can be passed in <strong>Just</strong> Operator are 1 to 10 (so min of 1 argument and max of 10).</p><p>Example</p><p>Here is the first example of creation of Observable using <strong>Just</strong> Operator where I passed the numbers 1, 2, 3, 4 directly as arguments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb75c1238ae852fd4046aaf5b41a6ee3/href">https://medium.com/media/cb75c1238ae852fd4046aaf5b41a6ee3/href</a></iframe><p>The Output for the above is :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7aab9b73aef931bd8c3ea78c38eea9c7/href">https://medium.com/media/7aab9b73aef931bd8c3ea78c38eea9c7/href</a></iframe><p>We can also pass List as a parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a9842442b68d527f8ab01cd40407c01/href">https://medium.com/media/9a9842442b68d527f8ab01cd40407c01/href</a></iframe><p>The output will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48efa1367f2190a36cc7d34d6c5f48c0/href">https://medium.com/media/48efa1367f2190a36cc7d34d6c5f48c0/href</a></iframe><p>Range</p><p>Range Operator creates an Observable that emits a particular range of Integers. It takes 2 arguments — starting integer n and length m, so that it starts emitting integers from the starting integer n to n+m-1.</p><figure><img alt="rxjava operators range" src="https://cdn-images-1.medium.com/max/1024/0*6fdeT8H6Du7Wrtca.png" /></figure><p>Example</p><p>Here is the example where we created an Observable using Range Operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4deb984dda12fd07e9a7d7becdf02d48/href">https://medium.com/media/4deb984dda12fd07e9a7d7becdf02d48/href</a></iframe><p>The output of the above example is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b063f98b1f7c2c2b3601b7fb4f52b317/href">https://medium.com/media/b063f98b1f7c2c2b3601b7fb4f52b317/href</a></iframe><p>Repeat</p><p>Repeat Operator is a simple operator which emits the same item multiple times</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6GP72dLFA5pbuPDs.png" /></figure><p>Example</p><p>Let us see its implementation with example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd01fda1ad6271d02d23adc78f2f00a0/href">https://medium.com/media/cd01fda1ad6271d02d23adc78f2f00a0/href</a></iframe><p>The output for the above is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a663ec38e5826e1fee5b5ec94b6701af/href">https://medium.com/media/a663ec38e5826e1fee5b5ec94b6701af/href</a></iframe><p>Timer</p><p>Timer operator creates an Observable that emits a particular item after a given delay.</p><figure><img alt="timer operator" src="https://cdn-images-1.medium.com/max/1024/0*JN3jkugqRridbfSq.png" /></figure><p>Example</p><p>Here is the example of timer operator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8ae6d356713393f022c32a2e144a15f/href">https://medium.com/media/b8ae6d356713393f022c32a2e144a15f/href</a></iframe><p>The output for the above is :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abc38b4f69e122c7449f5191461d1ea4/href">https://medium.com/media/abc38b4f69e122c7449f5191461d1ea4/href</a></iframe><p>This completes our tutorial on RxJava create Operators which we use to create Observables. In the next tutorial, we will focus on RxJava’s Operators for Transforming Observables along with examples.</p><p>All the code for the above examples can be found in the following <a href="https://github.com/vamsitallapudi/RxAndroid-Examples">Github link</a>. Hope this article is useful to you. Make sure you subscribe for the mail to notify about the latest articles first. Let me know if any queries through comment section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b842d8287bf1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxJava Operators In General — RxJava Tutorial #3]]></title>
            <link>https://medium.com/@vamsitallapudi/rxjava-operators-in-general-rxjava-tutorial-3-321de84de4f1?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/321de84de4f1</guid>
            <category><![CDATA[rxjava]]></category>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Tue, 15 Jan 2019 13:52:43 GMT</pubDate>
            <atom:updated>2019-01-15T13:52:59.023Z</atom:updated>
            <content:encoded><![CDATA[<h4>RxJava Operators in General</h4><p>In this article, we will continue discussing about RxJava Operators in general and what are the various types of RxJava Operators available. This article will be a brief introduction focusing on what are RxJava Operators and What are the types of <a href="http://reactivex.io/documentation/operators.html">Operators</a> available in RxJava that we can use. In the following upcoming articles, we will discuss about the each category of Operators along with examples. We will go through them one by one by breaking these tutorial into few parts. If you are new to this site, consider trying these prerequisite articles for which will help you gain more insight towards RxJava and their basic usage.</p><ul><li><a href="https://www.coderefer.com/rxandroid-tutorial-getting-started/">RxAndroid Introduction</a></li><li><a href="https://www.coderefer.com/rxandroid-example-tutorial/">RxAndroid Example</a></li></ul><h4>What are Operators in the World of RxJava?</h4><p>Operators perform certain tasks on Observables. There are few operators that can Create Observables, and there are other operators that can perform various actions on Observables.</p><h4>Types of Operators Available in RxJava</h4><p>1. Operators for Creating Observables</p><p>These Operators help creating new Observables. The Operators in this category are: Create, Just, Defer, Start, etc.</p><p>2. Operators for Transforming Observables</p><p>These Operators help transforming the items emitted by the Observables. The Operators in this Category are: Map, Flatmap, Buffer, etc.</p><p>3. Operators for Filtering Observables</p><p>These Operators help in filtering the selective items from Observable. The Most commonly used Operators in this category are: Filter, Distinct, Debounce, etc.</p><p>4. Operators for Combining Observables</p><p>These Operators help in combine multiple Observables to create a single Observable. The Most commonly used Operators in this category are: Zip, Join, Switch, etc.</p><p>5. Error Handling Operators</p><p>These Operators are used to help catching errors while working with Observables. Eg: Catch, Retry.</p><p>6. Observable Utility Operators</p><p>These operators are used for working with Observables. Eg. Subscribe, SubscribeOn, ObserveOn, etc.</p><p>7. Conditional and Boolean Operators</p><p>These operators are helpful to evaluate one or more Observables or items emitted by Observables. Eg: All, Contains, DefaultIfEmpty, etc.</p><p>8. Mathematical and Aggregate Operators</p><p>These are the basic Math Operators that will operate on entire sequence of items emitted by Observable. Eg: Max, Min, Average, Reduce, Sum, etc.</p><p>In the next articles, we will discuss each of these types in depth along with examples for each. The links will be updated to this article as required.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=321de84de4f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Search using Kotlin — Searching Algorithms #1]]></title>
            <link>https://medium.com/@vamsitallapudi/binary-search-using-kotlin-searching-algorithms-1-ad790c0bd11b?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad790c0bd11b</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 18:06:13 GMT</pubDate>
            <atom:updated>2018-11-26T18:06:17.530Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, let us discuss one more Algorithm — Binary Search which is the most frequently asked Algorithms during Interviews. Let us discuss about it in brief and how to implement its algorithm using Kotlin Programming Language.</p><p>According to <a href="https://en.wikipedia.org/wiki/Binary_search_algorithm">Wikipedia</a>, A Binary Search is a search algorithm that finds the position of a target value within a <a href="https://en.wikipedia.org/wiki/Sorted_array">sorted array</a>. The algorithm compares the target element with the middle element of the array. If the target element is greater than middle element, the algorithm will be reapplied to the right of the array. If the target element is less than middle element, then the algorithm is again applied to the left of the array. Note that this algorithm is to be applied only on the sorted array.</p><p>Related Links</p><ul><li><a href="https://www.coderefer.com/merge-sort-kotlin/">Merge Sort using Kotlin</a></li><li><a href="https://www.coderefer.com/quick-sort-kotlin/">Quick Sort using Kotlin</a></li><li><a href="https://www.coderefer.com/bubble-sort-kotlin/">Bubble Sort using Kotlin</a></li><li><a href="https://www.coderefer.com/android-interview-questions/">Android Interview Questions</a></li></ul><h4>Advantages</h4><p>Binary Search is significantly faster than that of Linear search. While Linear search takes O(n) time to search for an element in worst case, Binary search only takes O(log n) to search an element. For example, if there are more elements, it will significantly reduces the amount of time taken to find the element from the sorted array.</p><h4>Algorithm</h4><p>We will discuss here, the two ways of achieving Binary Search Implementation -</p><p>1. Binary Search through Iteration</p><p>Below gist shows us how to achieve the Algorithm through iteration. Here our goal is simple: Firstly to read the array and the element to be searched from the user input and print the position of element in the array. Here is the iterative implementation of the same. Code is commented wherever I find it necessary. Feel free to modify in gist / comment if anything more required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acdedf08c867c8eb060eade191bf9e13/href">https://medium.com/media/acdedf08c867c8eb060eade191bf9e13/href</a></iframe><p>2. Binary Search through Recursion</p><p>Now we’ll see how to achieve the same through Recursion. Below gist shows the same:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1b8aed91fc8567b8ee1bdbb3836a6bc/href">https://medium.com/media/d1b8aed91fc8567b8ee1bdbb3836a6bc/href</a></iframe><p>Feel free to suggest any modifications / feedback on the above implementation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad790c0bd11b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackLand Election — Coding Interview Questions #1]]></title>
            <link>https://medium.com/@vamsitallapudi/hackland-election-coding-interview-questions-1-1a295f094fbe?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a295f094fbe</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Wed, 07 Nov 2018 06:40:04 GMT</pubDate>
            <atom:updated>2018-11-07T14:21:13.261Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*VVD7kM0AE_Rc_BCq.png" /></figure><p>Few days ago, I attended an Android Interview for an MNC where I encountered an interesting coding question — Hackland Election. In this post, I would like to share it with you guys so that it might be helpful for your interview preparations.</p><p>Here is the question in the similar lines that was asked during the interview:</p><h4><em>“</em></h4><h4><em>Hackland Election</em></h4><p><em>There are n citizens voting in this year’s Hackland election. Each voter writes the name of their chosen candidate on a ballot and places it in a ballot box. The candidate with the highes number of votes win the election; if two or more candidates have the same number of votes, then the tied candidates’ names are ordered alphabetically and the last name wins.</em></p><p><em>Complete the election Winner function in your editor. It has 1 parameter:L an array of strings, votes, describing the votes in the ballot box. This function must review these votes and return a string representing the name of the winning candidate.</em></p><p><strong><em>Constraints</em></strong></p><ul><li><em>1&lt;= n &lt;= 10⁴</em></li></ul><p><strong><em>Input Format</em></strong><em> An array of Strings</em></p><p><strong><em>Output Format</em></strong><em> Name of the person who has the max votes. If there are multiple people with same number of votes(max) then print the last name of the list arranged in dictionary order.</em></p><p><strong><em>Input Example:</em></strong></p><p><em>5</em></p><p><em>Vamsi</em></p><p><em>Krishna</em></p><p><em>Vamsi</em></p><p><em>Krishna</em></p><p><em>Tallapudi</em></p><p><strong><em>Output:</em></strong></p><p><em>Vamsi</em></p><p><em>“</em></p><h4>Related Links</h4><ul><li><a href="https://www.coderefer.com/android-interview-questions/">Android Interview Questions</a></li><li><a href="https://www.coderefer.com/java-interview-questions/">Java Interview Questions</a></li></ul><h4>Coding Approach for Hackland Election Problem</h4><p>Here is the output using Kotlin Programming Language. Here I am using Collection Framework’s <a href="https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html">HashMap</a> with the approach of storing key value pairs with new key addition for every new word and incrementing the value for every repeated word:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c55b75175973d787dcf7c5e89d36b90/href">https://medium.com/media/4c55b75175973d787dcf7c5e89d36b90/href</a></iframe><p>Hope it will be helpful to you guys for your interview preparation. Feel free to suggest modifications if any. Contact us <a href="https://www.coderefer.com/contact-us/">here</a> if you want to share your interview questions with fellow developers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a295f094fbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Sort Kotlin Implementation — Sorting Algorithms #4]]></title>
            <link>https://medium.com/@vamsitallapudi/quick-sort-kotlin-implementation-sorting-algorithms-4-cb909930bd50?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb909930bd50</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Fri, 19 Oct 2018 15:39:23 GMT</pubDate>
            <atom:updated>2018-10-19T15:39:35.101Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*JfotVLa0D6hTEPfo.jpg" /></figure><p>Quick Sort is based on divide and conquer algorithmic technique, similar to Merge Sort. In this tutorial, we will be looking at <a href="https://en.wikipedia.org/wiki/Quicksort">Quick Sort</a> Kotlin Implementation.</p><h4>How Quick Sort Works?</h4><p>In Quick Sort, we will consider a random element of an array as pivot and partition the array into two — left part and right part. The main essence of Quick sort is as follows: If an element is considered to be sorted, then all the other elements which are left to it should be less than that element and all the right elements must be greater than it.</p><h4>Related Links</h4><ul><li><a href="https://www.coderefer.com/merge-sort-kotlin/">Merge Sort Kotlin</a></li><li><a href="https://www.coderefer.com/bubble-sort-kotlin/">Bubble Sort Kotlin</a></li><li><a href="https://www.coderefer.com/selection-sort-kotlin/">Selection Sort Kotlin</a></li></ul><p>To understand the above, let us take an example of [1, 2, 3, 4, 5]. Here, if we consider 3 as pivot, which is in sorted position, the elements left to it ([1, 2]) are less than 3 and the elements right to it (4, 5) are greater than 3. Hence we know that 3 is in sorted position.Now let us discuss on how Quick sort algorithm is written.</p><p>We will select a random element as pivot and partition the array such that elements less than pivot position will be on left and elements greater will be on right. Any greater element on left will be swapped with any less element on right. In this manner we will keep on partitioning the array into sub arrays and rearranging them.</p><blockquote>Sometimes Theory can be confusing than Practice — Vamsi Tallapudi :)</blockquote><p>Let us quickly dive into the algorithm for Quick Sort Kotlin Implementation</p><h4>Algorithm For Quick Sort Kotlin Implementation</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93a90a2056f29a031eff08a48e83222b/href">https://medium.com/media/93a90a2056f29a031eff08a48e83222b/href</a></iframe><p>As usual, Let us briefly discuss the points which are commented and are worth mentioning from the above Quick Sort Kotlin algorithm.</p><ol><li><strong>Read the Input and Split into array:</strong> Here we are trying to read the input whose values are separated by spaces (for eg., 5 4 3 2 1) and later split them into an array of integers.</li><li><strong>Sorting left half: </strong>Here we will be calling the <strong>quickSort() </strong>recursively on the left half so that it will be sorted.</li><li><strong>Sorting right half: </strong>Here we will be calling the <strong>quickSort() </strong>recursively on the right half so that it will be sorted.</li><li><strong>Pivot Point: </strong>Here we are calculating the pivot point. For simplicity and efficient time complexity, we are taking the average of low and high as pivot. In general, we can have any element of the array / sub array as pivot.</li><li><strong>Find the elements on left that should be on right: </strong>Here we are iterating through the left array till we find the element greater than pivot position.</li><li><strong>Find the elements on right that should be on left: </strong>Here we are iterating through the right array until we find the element less than the pivot position.</li><li><strong>Swap elements, and move left and right indices: </strong>At this point of code, if left &lt; right, then we have found left and right positions that needs to be swapped. Then we will increment left and decrement right positions respectively so that we will be ready for next iteration.</li></ol><h4>Performance</h4><p>Performance of Quick sort depends upon the factors like choice of pivot selection point etc. On an average case, Quick sort’s time complexity is O(nlogn) and in worst case it is O(n2).</p><p>In the upcoming articles we will be discussing about Searching Algorithms.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb909930bd50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge sort Kotlin Implementation — Sorting Algorithms #3]]></title>
            <link>https://medium.com/@vamsitallapudi/merge-sort-kotlin-implementation-sorting-algorithms-3-2d076f39b55c?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d076f39b55c</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 13:00:03 GMT</pubDate>
            <atom:updated>2018-10-17T13:00:20.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*qzft3atmh6HuSphe.jpg" /></figure><p>Merge Sort is sorting based on Divide and Conquer strategy and is one of the famous algorithms among Sorting. In this article, we will be discussing about <a href="https://en.wikipedia.org/wiki/Merge_sort">Merge Sort</a> Kotlin Implementation.</p><h4>How Merge sort Works?</h4><p>Merge sort algorithm technique basically involves two processes — one process splits the array into two halves and sorts them individually. The other process involves merging them again into a single array. This first process of splitting the array goes on and on and on till the array divides into small subfiles with single elements and later merged. Thus it does not need separate stack.</p><h4>Related Links</h4><ul><li><a href="https://www.coderefer.com/java-interview-questions/">Java Interview Questions</a></li><li><a href="https://www.coderefer.com/android-interview-questions/">Android Interview Questions</a></li></ul><p>Let us quickly dive into the Merge sort kotlin implementation. In addition to commenting the code wherever its necessary, I tried to explain in brief at the bottom of the implementation for those who seek more info.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/271057cf2e4f6aa0beae8ac93140b148/href">https://medium.com/media/271057cf2e4f6aa0beae8ac93140b148/href</a></iframe><h4>Code Explanation for Merge Sort Kotlin Algorithm</h4><ol><li><strong>Read the Input and Split into array:</strong> Here we are trying to read the input whose values are separated by spaces(for eg., 5 4 3 2 1) and later converting them into an array of integers. Next, <strong>mergeSort()</strong> function is called in 5th Line.</li><li><strong>Calculating the middle element:</strong> To split the array into two halves we are calculating and splitting array into two halves — 0 to middle, middle + 1 to array.length-1</li><li><strong>To sort left half:</strong> Recursively calling <strong>mergeSort()</strong> function on the left half to make it sorted</li><li><strong>To sort right half:</strong> Recursively calling <strong>mergeSort()</strong> function on the right half to make it sorted</li><li><strong>Merge them:</strong> Here we are calling <strong>merge()</strong> function which takes few parameters as shown to help them sort and merge. We added additional points in this function. Lets see them individually</li><li><strong>Copying both halves into helper array: </strong>Here we are copying both halves into helper array.</li><li><strong>Helper variables:</strong> helperLeft and helperRight keeps the track of where the start of left and right halves is.</li><li><strong>Condition to check helper left and helper right: </strong>checking if both the helper variables are within the limits</li><li><strong>Check if value at helperLeft index is less than that of value at helper right: </strong>If it’s true, then we’ll fill the current position of array with the element present at helperLeft index and increment the helperLeft to compare with other right elements in next iteration.</li><li><strong>Right element is smaller than left element: </strong>If the right value is true, we’ll perform a similar operation as that of the above.</li><li><strong>Copy the rest of left side of array into target: </strong>Here we will be copying any elements which are left in the left side of array after merging. We don’t copy the right half because they will be already be present at their respective spots. For example if we take the values as [1, 4, 5, || 3, 9, 10] before merging the elements left will be [9, 10] which will be present at last place both in helper array and our array. Hence no need to copy them.</li></ol><h4>Performance</h4><p>Here the Runtime for merge sort is O(n log n) for average and worst cases.</p><p>In the next article, we will be looking into other few major sorting techniques.</p><p>Want to improve this article / contribute new articles? Reach us at — <a href="https://www.coderefer.com/write-an-article/">https://www.coderefer.com/write-an-article/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d076f39b55c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bubble Sort Kotlin Implementation — Sorting Algorithms #2]]></title>
            <link>https://medium.com/@vamsitallapudi/bubble-sort-kotlin-implementation-sorting-algorithms-2-4d9622b78797?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d9622b78797</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 12:28:34 GMT</pubDate>
            <atom:updated>2018-10-17T12:28:55.305Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*uioCrIqx0sj3WwZG.jpg" /></figure><p>Bubble Sort is the simplest Algorithm of all the sorting techniques. It compares two adjacent elements and swaps them if they are in wrong order. In this article we will focus on <a href="https://en.wikipedia.org/wiki/Bubble_sort">Bubble Sort</a> Kotlin Implementation</p><h4>How Bubble Sort Works?</h4><p>Bubble sort works by iterating through the array of N elements, from the first element to the last, comparing each adjacent elements and swapping them if they are in wrong order. Once an iteration is completed, last element is in sorted position and we will start another iteration through N-1 elements. Enough of the theory, let’s dive into the Bubble Sort Kotlin Implementation Algorithm</p><h4>Bubble Sort Kotlin Algorithm</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78c8bffe9e223bc749aead1625101822/href">https://medium.com/media/78c8bffe9e223bc749aead1625101822/href</a></iframe><h4>Related Links</h4><ul><li><a href="https://www.coderefer.com/java-interview-questions/">Java Interview Questions</a></li><li><a href="https://www.coderefer.com/android-interview-questions/">Android Interview Questions</a></li></ul><h4>Things to Explain from Above Algorithm</h4><p>Let us briefly discuss the points which are commented and are worth mentioning from the above algorithm.</p><ol><li><strong>Read values and convert them to arraylist:</strong> As usual, we will read input from the console using <strong>readLine() </strong>method and convert it to arraylist in this line of code.</li><li><strong>To keep the track of unsorted array: </strong>Earlier we mentioned that for each iteration, the respective last element in the iteration gets sorted. So from next iteration onwards, we will iterate through 0 to (last element-1). This variable helps tracking that.</li><li><strong>Making this as false whenever the swap needs to be performed: </strong>Here isSorted is being made as false because we identified adjacent items that needs to be swapped. If any iteration is such that no adjacent items needs to be swapped, then that means the total array is sorted. Otherwise we will make isSorted = false so that it is ready for next iteration.</li><li><strong>Decreasing the count since one more element from right side is placed in sorted position: </strong>As mentioned in point 2, we are decreasing the count as the last element of the iteration is sorted and in next iteration we can ignore that last element.</li></ol><h4>Advantages</h4><ol><li>Simplest form of all sorting, easy to understand</li><li>No additional memory required.</li></ol><h4>Disadvantages</h4><ol><li>Bit Expensive. Average and Worst case complexity is O(n2).</li></ol><p>In the next articles, we will be discussing another interesting sorting algorithm techniques like Merge sort.</p><p>Want to improve this article / contribute new articles ? Reach us at — <a href="https://www.coderefer.com/write-an-article/">https://www.coderefer.com/write-an-article/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d9622b78797" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bubble Sort Kotlin Implementation — Sorting Algorithms #2]]></title>
            <link>https://medium.com/@vamsitallapudi/bubble-sort-kotlin-implementation-sorting-algorithms-2-4377942d2f30?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4377942d2f30</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 12:28:34 GMT</pubDate>
            <atom:updated>2018-10-17T12:28:45.891Z</atom:updated>
            <content:encoded><![CDATA[<p>Bubble Sort is the simplest Algorithm of all the sorting techniques. It compares two adjacent elements and swaps them if they are in wrong order. In this article we will focus on <a href="https://en.wikipedia.org/wiki/Bubble_sort">Bubble Sort</a> Kotlin Implementation</p><h4>How Bubble Sort Works?</h4><p>Bubble sort works by iterating through the array of N elements, from the first element to the last, comparing each adjacent elements and swapping them if they are in wrong order. Once an iteration is completed, last element is in sorted position and we will start another iteration through N-1 elements. Enough of the theory, let’s dive into the Bubble Sort Kotlin Implementation Algorithm</p><h4>Bubble Sort Kotlin Algorithm</h4><p><a href="https://gist.github.com/vamsitallapudi/dfe55849ea78612100a6f058942bb50e">https://gist.github.com/vamsitallapudi/dfe55849ea78612100a6f058942bb50e</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78c8bffe9e223bc749aead1625101822/href">https://medium.com/media/78c8bffe9e223bc749aead1625101822/href</a></iframe><ul><li><a href="https://www.coderefer.com/java-interview-questions/">Java Interview Questions</a></li><li><a href="https://www.coderefer.com/android-interview-questions/">Android Interview Questions</a></li></ul><h4>Things to Explain from Above Algorithm</h4><p>Let us briefly discuss the points which are commented and are worth mentioning from the above algorithm.</p><ol><li><strong>Read values and convert them to arraylist:</strong> As usual, we will read input from the console using <strong>readLine() </strong>method and convert it to arraylist in this line of code.</li><li><strong>To keep the track of unsorted array: </strong>Earlier we mentioned that for each iteration, the respective last element in the iteration gets sorted. So from next iteration onwards, we will iterate through 0 to (last element-1). This variable helps tracking that.</li><li><strong>Making this as false whenever the swap needs to be performed: </strong>Here isSorted is being made as false because we identified adjacent items that needs to be swapped. If any iteration is such that no adjacent items needs to be swapped, then that means the total array is sorted. Otherwise we will make isSorted = false so that it is ready for next iteration.</li><li><strong>Decreasing the count since one more element from right side is placed in sorted position: </strong>As mentioned in point 2, we are decreasing the count as the last element of the iteration is sorted and in next iteration we can ignore that last element.</li></ol><h4>Advantages</h4><ol><li>Simplest form of all sorting, easy to understand</li><li>No additional memory required.</li></ol><h4>Disadvantages</h4><ol><li>Bit Expensive. Average and Worst case complexity is O(n2).</li></ol><p>In the next articles, we will be discussing another interesting sorting algorithm techniques like Merge sort.</p><p>Want to improve this article / contribute new articles ? Reach us at — <a href="https://www.coderefer.com/write-an-article/">https://www.coderefer.com/write-an-article/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4377942d2f30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Selection Sort Kotlin with Example — Sorting Algorithms #1]]></title>
            <link>https://medium.com/@vamsitallapudi/selection-sort-kotlin-with-example-sorting-algorithms-1-e01008ccc979?source=rss-54fbb60e30e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e01008ccc979</guid>
            <dc:creator><![CDATA[Vamsi Tallapudi]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 06:58:19 GMT</pubDate>
            <atom:updated>2018-10-17T06:58:30.058Z</atom:updated>
            <content:encoded><![CDATA[<p>Selection Sort is one of the most important sorting algorithm frequently looked upon and is even asked in the Interviews. In this article we will look at <a href="https://en.wikipedia.org/wiki/Selection_sort">Selection Sort</a> Kotlin Implementation with example.</p><p>Before diving into the code, let us see what is a Selection sort and Whether its efficient to use or not.</p><h4>What is a Selection Sort</h4><p>Selection sort is one of the simplest form of sorting. Its goal is simple: to find the smallest element and bring it to front. Then find the second smallest and move it to second position from front and so on.This will continue until all the elements are in position.</p><p>Since the algorithm repeatedly selects the smallest element, it is called as selection sort.</p><h4>Related Links</h4><ul><li><a href="https://www.coderefer.com/java-interview-questions/">Java Interview Questions</a></li><li><a href="https://www.coderefer.com/android-interview-questions/">Android Interview Questions</a></li></ul><h4>Advantages</h4><ul><li>Easy,</li><li>No additional space required</li></ul><h4>Selection Sort Kotlin Algorithm Implementation:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40950b6aa4869da26d81cfd3253086dd/href">https://medium.com/media/40950b6aa4869da26d81cfd3253086dd/href</a></iframe><h4>Is it Efficient?</h4><p>As you can see, in the above example, it consists of two for loops — one in line 9 and other in line 11 in the above example. So we know that the its Average and worst case Complexity is O(n2). Hence its inefficient compared to other algorithms.</p><p>In the next article we will be looking into few other important sorting techniques like bubble sort, merge sort etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e01008ccc979" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>