<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: André Maré</title>
    <description>The latest articles on DEV Community by André Maré (@andremare).</description>
    <link>https://dev.to/andremare</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F39919%2F7b2e35d7-bb6e-4f58-bb09-9af6fe89a0a7.jpg</url>
      <title>DEV Community: André Maré</title>
      <link>https://dev.to/andremare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andremare"/>
    <language>en</language>
    <item>
      <title>The 8 Types of Waste in Lean Methodology</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Wed, 24 Jul 2024 19:05:50 +0000</pubDate>
      <link>https://dev.to/andremare/the-8-types-of-waste-in-lean-methodology-j93</link>
      <guid>https://dev.to/andremare/the-8-types-of-waste-in-lean-methodology-j93</guid>
      <description>&lt;h4&gt;
  
  
  The Underlying Causes of Waste in Software Engineering
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gdnlcPly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2A3uYFG-oIEiNHa2Ud" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gdnlcPly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2A3uYFG-oIEiNHa2Ud" width="800" height="600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Gary Chan on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Staying competitive and delivering high-quality software on time requires exceptional efficiency in today’s fast-paced software engineering world. However, many organisations encounter various forms of waste that diminish productivity and escalate costs.&lt;/p&gt;

&lt;p&gt;The Lean methodology, with its systematic approach, offers valuable insights into identifying and eliminating these inefficiencies. By following Lean principles, software engineering teams can confidently tackle waste and improve their processes.&lt;/p&gt;

&lt;p&gt;In this blog, we will explore the eight types of waste defined by Lean principles and examine their root causes within software engineering.&lt;/p&gt;

&lt;p&gt;Understanding these sources of waste will enable teams to implement strategies to streamline their workflows, optimise their resources, and ultimately deliver better software more efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are the Types of Work?
&lt;/h3&gt;

&lt;p&gt;According to Lean methodology, work activities can be categorised into three main types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Value-Added Work&lt;/strong&gt; : Activities that directly contribute to creating value for the customer. These activities transform the product or service in a way the customer is willing to pay for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-Value-Added (Essential) Work&lt;/strong&gt;: Activities that don’t directly add value from the customer’s perspective but are currently required for business operations, regulatory compliance, or other essential reasons.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-Value-Added (Non-Essential) Work&lt;/strong&gt;: Activities that consume resources without adding value to the product or service from the customer’s perspective. These are considered pure waste and should be eliminated.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---XaXsWfB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2Ap4OqXsuOnV2CrBTyD9EY3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---XaXsWfB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2Ap4OqXsuOnV2CrBTyD9EY3g.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The definition of waste (or “muda” in Japanese) in Lean methodology is any activity or process that does not add value from the customer’s perspective.&lt;/p&gt;

&lt;p&gt;This concept extends beyond just physical waste to include inefficiencies in processes, unnecessary steps, and underutilised resources.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The purpose is to identify and eliminate waste, ensuring that products flow efficiently through the business.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What are the different types of Waste?
&lt;/h3&gt;

&lt;p&gt;Lean practitioners identify eight types of waste: defects, overproduction, waiting, non-utilised skills, transportation, inventory, motion, and excess processing.&lt;/p&gt;

&lt;p&gt;By systematically identifying and eliminating these forms of waste, organisations can streamline their operations, improve efficiency, and ultimately deliver greater value to their customers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defects&lt;/strong&gt; : &lt;em&gt;Flaws requiring rework and leading to customer dissatisfaction.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Defects are flaws or errors in products or services that fail to meet quality standards or customer expectations. They result in rework, increased costs, and customer dissatisfaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overproduction&lt;/strong&gt; : &lt;em&gt;Producing more than necessary, causing excess inventory.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Overproduction occurs when more products or services are produced than are needed or before they are required. This leads to excess inventory, increased storage costs, and potential waste of resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Waiting&lt;/strong&gt; : &lt;em&gt;Idle time causing delays and reduced efficiency.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Waiting refers to idle time when no value-adding activities occur, often due to delays, bottlenecks, or inefficient processes. This waste can slow down overall production and reduce efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-Utilised Talent&lt;/strong&gt; : &lt;em&gt;Underutilising employee skills and creativity.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Non-utilised talent is the failure to fully leverage the skills, knowledge, and creativity of employees. This results in missed opportunities for improvement, innovation, and overall organisational growth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transportation&lt;/strong&gt; : &lt;em&gt;Unnecessary movement of materials and information.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Transportation waste involves unnecessary movement of materials, products, or information that does not add value to the process. Excessive transportation can lead to increased costs and longer lead times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inventory&lt;/strong&gt; : &lt;em&gt;Excess stock tying up capital and space.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Inventory waste refers to excess stock of raw materials, work-in-progress, or finished goods that do not contribute to value creation. High levels of inventory can tie up capital and increase storage costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motion&lt;/strong&gt; : &lt;em&gt;Unnecessary movements reducing efficiency.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Motion waste involves unnecessary physical movements by workers that do not contribute to value creation. This can result from poor workplace layout or ergonomics, leading to inefficiencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extra Processing&lt;/strong&gt; : &lt;em&gt;Unnecessary work beyond customer requirements.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Extra processing occurs when work is performed beyond what the customer requires or is willing to pay for. This often results from unclear specifications, leading to wasted resources and time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_vaPhoiw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AGmg7N3ororlf7dFCRZ4-Uw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_vaPhoiw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AGmg7N3ororlf7dFCRZ4-Uw.png" width="800" height="424"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Lean Methodology: 8 Types of Waste&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Waste in Software Engineering
&lt;/h3&gt;

&lt;p&gt;The concept of waste in lean manufacturing can be effectively translated to software engineering, as both domains aim to optimise processes and eliminate inefficiencies. The eight wastes of manufacturing have direct parallels in software engineering:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Defects → Defects&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Overproduction → Extra Features&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Waiting → Waiting&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-utilised Talent → Non-utilised Talent&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transportation → Task Switching&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inventory → Partially Done Work&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Motion → Motion&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extra Processing → Extra Processes&lt;/strong&gt; (&lt;em&gt;Software Engineering&lt;/em&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Continue Reading
&lt;/h3&gt;

&lt;p&gt;Continue reading the rest of the article on my Medium Blog. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.beyondengineering.io/the-8-types-of-waste-in-lean-methodology-ef5b591db808" rel="noopener noreferrer"&gt;The 8 Types of Waste in Lean Methodology&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow me (👥&lt;/em&gt; &lt;a href="https://medium.com/u/a8aeb582b67d" rel="noopener noreferrer"&gt;&lt;em&gt;André Maré&lt;/em&gt;&lt;/a&gt;&lt;em&gt;) or my personal blog (&lt;/em&gt;&lt;a href="http://www.beyondengineering.io" rel="noopener noreferrer"&gt;&lt;em&gt;Beyond Engineering&lt;/em&gt;&lt;/a&gt;&lt;em&gt;) for more posts like this.&lt;/em&gt;&lt;/p&gt;




</description>
      <category>leanmethodology</category>
      <category>softwareengineering</category>
      <category>waste</category>
      <category>leadership</category>
    </item>
    <item>
      <title>Install Apache Kafka on macOS using Homebrew</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Sun, 01 Jan 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/andremare/install-apache-kafka-on-macos-using-homebrew-5gno</link>
      <guid>https://dev.to/andremare/install-apache-kafka-on-macos-using-homebrew-5gno</guid>
      <description>&lt;ul&gt;
&lt;li&gt;What is Kafka?&lt;/li&gt;
&lt;li&gt;Brew Installation Commands&lt;/li&gt;
&lt;li&gt;Directory Structure&lt;/li&gt;
&lt;li&gt;Brew Run Commands&lt;/li&gt;
&lt;li&gt;Alternative Commands&lt;/li&gt;
&lt;li&gt;Testing Installation&lt;/li&gt;
&lt;li&gt;Summary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apache Kafka is a popular open-source stream-processing software platform developed by the Apache Software Foundation. Installing and configuring Kafka can sometimes be daunting, but the process is significantly simplified thanks to Homebrew (or brew), a package manager for macOS.&lt;/p&gt;

&lt;p&gt;This blog will guide you through installing Kafka on macOS using Homebrew.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Kafka?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Apache Kafka acts as a decoupling layer between source and target systems, allowing source systems to produce data into Kafka, and target systems to consume data from Kafka, making the architecture more scalable and manageable.” &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Brew Installation Commands
&lt;/h2&gt;

&lt;p&gt;Before installing Kafka using Homebrew, you must ensure that Homebrew is installed on your Mac. Once Homebrew is installed, you can use the &lt;code&gt;brew install&lt;/code&gt; command to install both Kafka and Zookeeper, as Kafka has a dependency on Zookeeper which will be resolved by Homebrew automatically.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Install Homebrew&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Command: Install Kafka&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install kafka

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will install both Kafka and Zookeeper, as Zookeeper is a dependency for Kafka.&lt;/p&gt;

&lt;h2&gt;
  
  
  Directory Structure
&lt;/h2&gt;

&lt;p&gt;After the installation is complete, the Kafka and Zookeeper binaries, configurations, and logs will be located in different directories based on your Mac’s chip.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Macs with Intel Processor:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Binaries and scripts will be in &lt;code&gt;/usr/local/bin&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Kafka configurations will be in &lt;code&gt;/usr/local/etc/kafka&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Zookeeper configuration will be in &lt;code&gt;/usr/local/etc/zookeeper&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;log.dirs&lt;/code&gt; config (Kafka data) will be set to &lt;code&gt;/usr/local/var/lib/kafka-logs&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Macs with Apple Silicon Processor:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Binaries and scripts will be in &lt;code&gt;opt/homebrew/bin&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Kafka configurations will be in &lt;code&gt;opt/homebrew/etc/kafka&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Zookeeper configuration will be in &lt;code&gt;opt/homebrew/etc/zookeeper&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;log.dirs&lt;/code&gt; config (Kafka data) will be set to &lt;code&gt;opt/homebrew/var/lib/kafka-logs&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can modify the Kafka and Zookeeper configuration files to customize your setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Brew Run Commands
&lt;/h2&gt;

&lt;p&gt;Once you have installed Kafka and Zookeeper, you can start them using the brew services command. This command will start Kafka and Zookeeper as background services, so they will continue running even if you close your terminal.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Start Zookeeper and Kafka&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services start zookeeper
$ brew services start kafka

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Command: Stop Zookeeper and Kafka&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services stop kafka
$ brew services stop zookeeper

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Command: Restart Zookeeper and Kafka&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services restart kafka
$ brew services restart zookeeper

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Alternative Commands
&lt;/h2&gt;

&lt;p&gt;While Homebrew provides a convenient way to manage services, you can also start Zookeeper and Kafka manually using the provided scripts. This involves running the &lt;code&gt;zookeeper-server-start.sh&lt;/code&gt; and &lt;code&gt;kafka-server-start.sh&lt;/code&gt; scripts with the appropriate configuration files.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Start Zookeeper&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ /usr/local/bin/zookeeper-server-start /usr/local/etc/zookeeper/zoo.cfg

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Command: Start Kafka&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ /usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Closing the terminal window or using the &lt;code&gt;Ctrl-C&lt;/code&gt; command will stop the Kafka and Zookeeper services. It is important to stop the services properly to avoid any data corruption or loss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Installation
&lt;/h2&gt;

&lt;p&gt;Testing the Kafka installation involves starting the environment, creating a topic, producing events, and consuming events. After successfully performing these tasks, it is important to clean up the environment by deleting the created topic and stopping the Kafka and Zookeeper services to ensure that the system is left in a clean state.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Start Zookeeper and Kafka&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services start zookeeper
$ brew services start kafka

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating a topic in Kafka can be done using the &lt;code&gt;kafka-topics -- create&lt;/code&gt; command. After creating the topic, it is important to validate its creation by describing the topic using the command &lt;code&gt;kafka-topics --describe&lt;/code&gt;, which will display the details of the created topic.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Create a Topic&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kafka-topics --create --topic quickstart-events --bootstrap-server localhost:9092
$ kafka-topics --describe --topic quickstart-events --bootstrap-server localhost:9092

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Producing new events in Kafka can be done using the &lt;code&gt;kafka-console-producer&lt;/code&gt; command. This will send a &lt;code&gt;Hello World&lt;/code&gt; event to the Kafka topic you created.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Produce Events&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
&amp;gt; Hello World 1.
&amp;gt; Hello World 2.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can stop the producer client with &lt;code&gt;Ctrl-C&lt;/code&gt; at any time.&lt;/p&gt;

&lt;p&gt;Consuming the events in Kafka can be done using the &lt;code&gt;kafka-console-consumer&lt;/code&gt; command. This will retrieve the &lt;code&gt;Hello World&lt;/code&gt; event from the Kafka topic you created.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Consume Events&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kafka-console-consumer --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
&amp;gt; Hello World 1.
&amp;gt; Hello World 2.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can stop the consumer client with &lt;code&gt;Ctrl-C&lt;/code&gt; at any time.&lt;/p&gt;

&lt;p&gt;Cleaning up the environment after testing the Kafka installation involves several steps. First, you need to delete the topic you created using the &lt;code&gt;kafka-topics&lt;/code&gt; command, then you need to shut down Kafka and Zookeeper using the &lt;code&gt;brew services stop&lt;/code&gt; commands, and finally, you need to delete any data of your local Kafka environment, including any events you have created along the way, by removing the Kafka logs and Zookeeper data directories that were specified in the configuration files.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Command: Environment Cleanup&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kafka-topics --delete --topic quickstart-events --bootstrap-server localhost:9092
$ brew services stop kafka
$ brew services stop zookeeper
$ rm -rf /tmp/kafka-logs /tmp/zookeeper /tmp/kraft-combined-logs

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Installing Kafka on macOS is straightforward using Homebrew. With just a few commands, you can have Kafka and Zookeeper up and running on your machine.&lt;/p&gt;

&lt;p&gt;Happy streaming!&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>homebrew</category>
      <category>macos</category>
    </item>
    <item>
      <title>Essential cURL Commands for Developers</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Sat, 27 Jul 2019 22:00:00 +0000</pubDate>
      <link>https://dev.to/andremare/essential-curl-commands-for-developers-38g3</link>
      <guid>https://dev.to/andremare/essential-curl-commands-for-developers-38g3</guid>
      <description>&lt;p&gt;This post provides a quick reference to the cURL commands that I use as a Java developer. This is not a complete set of cURL commands with detailed explanations on what each command does. If you want to read detailed documentation on the different options and arguments of the cURL command, please refer to the &lt;em&gt;man&lt;/em&gt; pages of the cURL command.&lt;/p&gt;

&lt;p&gt;Furthermore, there are a number of REST Clients and IDEs like Eclipse and IntelliJ that allows you to invoke HTTP requests to a server, however more than often I find myself having to make these calls from the command line as part of a debug process. It is also faster to open a terminal and use these commands to invoke commands than to setup the configuration for different types of requests in your IDE or other UI applications.&lt;/p&gt;

&lt;p&gt;Use this reference to learn the cURL command and add it as a critical tool as part of your skillset.&lt;/p&gt;

&lt;h4&gt;
  
  
  Help and Information Commands
&lt;/h4&gt;

&lt;p&gt;To find help or learn more about the different options and arguements used as part of the curl command, you can type any of the following in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Display quick help information about the curl command
$ curl --help

# Quick search for specific curl options or arguments
$ curl --help | grep {search_value}

# Display the manual page for the curl command
$ man curl

# Displays information about curl and the libcurl version it uses.
$ curl --version
$ curl -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  General
&lt;/h4&gt;

&lt;p&gt;This section contains the basic curl commands on which you can add more options and arguments listed in the other sections.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Retrieve content of URL and display it on screen
$ curl {URL}

# Write output to a file instead of stdout.
$ curl {URL} &amp;gt; {filename}
$ curl -o {filename} {URL}

# Write output to a local file named like the remote file we get
$ curl -O {URL}

# Enables verbose detail to be displayed
$ curl -v {URL}

# Enables a full trace dump on all incoming and outgoing data.
$ curl --trace {filename} {URL}

# Silent Mode: Don’t show progress meter or error messages.
$ curl -s {URL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  HTTP Headers
&lt;/h4&gt;

&lt;p&gt;HTTP headers are the name or value pairs that are displayed in the request and response messages of message headers for Hypertext Transfer Protocol (HTTP). These commands will help you set and read the HTTP Headers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Fetch the headers from the server (HEAD)
$ curl -I {URL}

# Include the HTTP-header in the output
$ curl -i {URL}

# Pass multiple headers as part of the request to the server.
$ curl -H "{HTTP General Header}" -H "{HTTP Request Header}" {URL}

# Include custom HTTP Header in the request to the server.
$ curl -H "{X-Key}:{Value}" {URL}

# Write the received protocol headers to the specified file.
$ curl -D {filename} {URL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  HTTP Cookies
&lt;/h4&gt;

&lt;p&gt;An HTTP cookie is a small piece of data sent from a website and stored on the user’s computer by the user’s web browser while the user is browsing. These commands will help you set and read the HTTP Cookies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Write all cookies to filename after completed command.
$ curl -c {filename} {URL}

# Read cookies from file and pass data to HTTP Server in Cookie header. 
$ curl -b {filename} {URL}

# Read cookies from data (key:value) and pass to HTTP Server in Cookie header.
$ curl -b "{key1:value1;key2:value2}" {URL}

# Discard all "session cookies". New session started.
$ curl -j {URL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Proxy
&lt;/h4&gt;

&lt;p&gt;A proxy server is a server that acts as an intermediary for requests from clients seeking resources from other servers. These commands will help set the proxy server URL and port number and also with authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use the specified proxy server and port number
$ curl -x {proxy_url}:{port} {URL}

# Specify the user name and password to use for proxy authentication.
$ curl -U {username}:{password} - x {proxy_url}:{port} {URL}

# Comma-separated list of hosts which do not use a proxy
$ curl --noproxy {url1} -x {proxy_url}:{port} {URL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  FTP Server
&lt;/h4&gt;

&lt;p&gt;The File Transfer Protocol (FTP) is a standard network protocol used for the transfer of computer files between a client and server on a computer network. These commands will help to transfer files to and from a FTP Server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Display a directory listing of an FTP site (Anonymous)
$ curl {FTP_URL}

# Retrieve a file from a FTP site. (Anonymous)
$ curl {FTP_URL}/{filename} 

# Upload a file to a FTP site. (Anonymous)
$ curl -T {filename} {FTP_URL}

# Upload Files to an FTP Server. (Secured)
$ curl -u {ftpuser}:{ftppass} -T {filename} {FTP_URL}

# Upload multiple files to an FTP Server
$ curl -u {ftpuser}:{ftppass} -T "{file1,file2}" {FTP_URL}

# Upload a file to a FTP site and append to an existing file
$ curl -T {filename} -a {FTP_URL}/{filename}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  HTTP Post/Put Data
&lt;/h4&gt;

&lt;p&gt;The HTTP POST and PUT request method requests that a web server accepts the data enclosed in the body of the request message, most likely for storing it. These commands will show you how to enclose data as part of a request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Send data in a POST/PUT request to the HTTP server
$ curl -d '{key1=value1&amp;amp;key2=value2}' -X {POST/PUT} {URL}

# Send data from a file in a POST/PUT request to the HTTP server
$ curl -d {@filename} -X {Post/PUT} {URL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  REST API
&lt;/h4&gt;

&lt;p&gt;A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. The following commands illustrate how to invoke REST APIs with different HTTP methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Invoke REST API (GET &amp;amp; JSON)
$ curl -i -H "Content-Type: application/json" -X GET {REST_API}

# Invoke REST API (POST &amp;amp; JSON)
$ curl -i -H "Content-Type: application/json" -X POST -d '{key:value}' {REST_API}

# Invoke REST API (PUT &amp;amp; JSON)
$ curl -i -H "Content-Type: application/json" -X PUT -d '{key:value}' {REST_API}

# Invoke REST API (POST)
$ curl -X DELETE {REST_API}/{ID}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Security
&lt;/h4&gt;

&lt;p&gt;There are numerous ways to authenticate your curl commands against the server. Here are some of the ways to perform authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Authenticate with username and password
$ curl -u {username}:{password} {URL}

# Authenticate with SSL certificate and password
$ curl --cert {cert_file.pem}:{password} {URL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Configuration File
&lt;/h4&gt;

&lt;p&gt;The curl configuration file is named .curlrc (Linux) or _curlrc (Windows) and can be found in the user’s home directory.&lt;/p&gt;

&lt;p&gt;An example of the file and the entries is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The default Proxy and port to use
proxy = 127.0.0.1:8080
# The proxy username and password
proxy-user = "user:pass"
# The timeout is set to 60 seconds
-m 60
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Summary
&lt;/h4&gt;

&lt;p&gt;The curl commands listed in this article is by no means a complete set of curl commands and only serve as a quick reference to be used by developers. To see the full documentation of the curl command, please read the &lt;em&gt;man&lt;/em&gt; pages of the curl command.&lt;/p&gt;

&lt;p&gt;Follow me on any of the different social media platforms and feel free to leave comments.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>bash</category>
      <category>curl</category>
      <category>commands</category>
    </item>
    <item>
      <title>Alexa Commands</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Tue, 11 Dec 2018 06:19:20 +0000</pubDate>
      <link>https://dev.to/andremare/alexa-commands-358g</link>
      <guid>https://dev.to/andremare/alexa-commands-358g</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PX8O-DSF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.code2bits.com/wp-content/uploads/banner-image/banner-alexa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PX8O-DSF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.code2bits.com/wp-content/uploads/banner-image/banner-alexa.jpg" width="800" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Alexa?
&lt;/h3&gt;

&lt;p&gt;Amazon Alexa is a virtual assistant developed by Amazon. Alexa was first used in the Amazon Echo and the Amazon Echo Dot smart speakers. Alexa can perform numerous tasks such as voice interaction, making to-do lists, music playback, setting alarms, playing audiobooks and streaming podcasts. She can also provide weather, traffic, sports, and other real-time information, such as news. Other capabilities of Alexa are the control of several smart devices using itself as a home automation system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alexa Commands
&lt;/h3&gt;

&lt;p&gt;Alexa has a large number of built-in commands which you can invoke without installing new skills. The following is a list of the commands sorted by categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic Controls&lt;/li&gt;
&lt;li&gt;Alarm &amp;amp; Timer&lt;/li&gt;
&lt;li&gt;Bluetooth&lt;/li&gt;
&lt;li&gt;Calendar&lt;/li&gt;
&lt;li&gt;Funny&lt;/li&gt;
&lt;li&gt;General Knowledge&lt;/li&gt;
&lt;li&gt;Holidays&lt;/li&gt;
&lt;li&gt;Language &amp;amp; Dictionary&lt;/li&gt;
&lt;li&gt;Math &amp;amp; Conversion&lt;/li&gt;
&lt;li&gt;Movie &amp;amp; TV Series&lt;/li&gt;
&lt;li&gt;Music &amp;amp; Books&lt;/li&gt;
&lt;li&gt;Quotes&lt;/li&gt;
&lt;li&gt;Random&lt;/li&gt;
&lt;li&gt;Sport&lt;/li&gt;
&lt;li&gt;Star Wars&lt;/li&gt;
&lt;li&gt;Weather&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Basic Control Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, help.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, open {skill name}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, enable {skill name}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, disable {skill name}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, stop.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, cancel.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, louder.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, softer.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, turn up the volume.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, turn down the volume.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, mute.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, unmute.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, volume {1-10}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, go to sleep.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Alarm &amp;amp; Timer Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, set an alarm for {time}”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, set a repeating alarm for {time} weekdays”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, when’s my next alarm?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, turn off”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, snooze”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, snooze for {x minutes}”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, cancel my alarm for {time}”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, cancel all alarms”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wake me up at {time}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wake me up everyday at {time}”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wake me up at {time} to {music}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wake me up to {song} by {artist} at {time}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wake me up to {news service} at {time}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, timer.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, set timer for {x minutes}.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, set a 10 minute {named} timer.” &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how long is left on the timer?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how long is left on the {named} timer?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what are my timers?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, stop the timer”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, cancel the {named} timer”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the time?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the date?”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bluetooth Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, bluetooth.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, pair.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, connect to my phone.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, connect to my speaker.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, disconnect from my phone.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, disconnect from my speaker.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, discover my devices.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Calendar Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s on my calendar?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s on my calendar [tomorrow]?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s on my schedule?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is my next event?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is my next appointment?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, create new event.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, add [name] to my calendar for [day] at [time].”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, add [event_name] with [person’s name].”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, invite [person’s name] to [event_name].”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, delete my [event_name] event.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, cancel my [date] event.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, move my [event_name] to [time/date].”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the time?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the date?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how many days until [date]?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how many days until Christmas?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how many days until [holiday_name]?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what time is it in Paris?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Alexa, when is the next lunar eclipse?”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Funny Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do you have a boyfriend?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, ha ha!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who’s better, you or Siri?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what do you think about Google Now?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what do you think about Cortana?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what do you think about Siri?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, why is six afraid of seven?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, all your base are belong to us.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, you talkin’ to me!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, roses are red.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, where is Chuck Norris?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, open Jurassic Bark.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who let the dogs out?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, knock, knock.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a football joke.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a vegetable joke.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Thanksgiving joke.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a joke about you.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  General Knowledge Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what does the Earth weigh?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who wrote the Harry Potter series?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the currency of South Africa?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do dogs dream?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how hot is the sun?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is Roblox?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, random fact.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Romeo, Romeo, wherefore art thou Romeo?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is Nelson Mandela?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is Barack Obama?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is Juius Ceaser?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give a fact about Africa.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who was the first man on the moon?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who was the first man on mount Everest?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, when was McDonald’s founded?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a dinosaur fact.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Holiday Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, merry Christmas”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, is there a Santa?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Christmas joke.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, sing me a Christmas song.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how many days until Christmas?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, sing me a Christmas carol.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how old is Santa Claus?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, where does Santa Claus live?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, is Santa Claus real?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me about Santa’a reindeer.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is you favourite reindeer?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, read “The night Before Christmas.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, when is Thanksgiving?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Thanksgiving haiku.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the history of Thanksgiving?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what are you thankful for?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy birthday!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy New Year!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy holidays!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy Valentine’s Day!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, sing happy birthday.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy Mother’s Day.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy Father’s Day.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, happy Easter.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Language &amp;amp; Dictionary Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how do you spell birthday?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, say hello in French.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the word of the day?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a spelling bee word.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the definition of beautiful.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how do you spell beautiful.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the antonym of beautiful.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the synonym of beautiful.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what rhyme with beautiful.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Math &amp;amp; Conversion Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 plus 5?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 minus 5?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 times 5?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 divided by 5?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 squared?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the square root of 25?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 cubed?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 to the number of 5?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5 factorial?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is 5% of 5?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, is 5 a prime number?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is fibonacci numbers?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, divide by zero?”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Movie &amp;amp; TV Series Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is your favourite movie?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what movies are playing?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who plays in Die Hard?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the IMDb rating for Die Hard?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what was Bruce Willis first movie?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is Bruce Willis latest movie?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how many Oscars has Bruce Willis won?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the top grossing movie this week?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give a quote from Die Hard.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, are we in the Matrix?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the first rule of fight club?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the second rule of fight club?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is your favorite holiday movie?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the Die Hard movie about?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is your favourite TV Series?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who plays in Game of Thrones?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who plays Jon Snow in Game of Thrones?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what time is the Emmy Awards?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who lives in a pineapple under the sea?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is the mother of dragons?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, is Jon Snow dead?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, when is the Macy’s Thanksgiving Day Parade on TV?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the most popular TV show?”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Music &amp;amp; Books Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, shuffle mode on.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, shuffle mode off.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, loop.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, pause.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, next.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, previous.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, restart.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play some music.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play Beyoncé.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play music by Beyoncé.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play music by Frank sinatra.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s playing?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play my Rock Ballades playlist.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wake me up to Beyoncé.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, play Katy Perry’s new holiday song from Amazon Music.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a famous first line.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, read me a mystery.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, read a sample of Becoming by Michelle Obama from Audible.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Ripley’s Believe It or Not story.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Quote Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a Stephen Hawking quote.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a Nelson Mandela quote.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a Barack Obama quote.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me a William Shakespeare quote.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Random Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, testing 1-2-3.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, why so serious?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, wakey, wakey.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, make me a sandwich.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how are babies made?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, welcome!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I’m home&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do a barrel roll!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, are you lying?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the meaning of life?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the answer to life, the universe, and everything?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I’m sick.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Marco!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Cheers!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, can you smell that?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, will pigs fly?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, am I hot?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do you dream?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is on 1st”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, beam me up!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, warp 10”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, give me some advise.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who’s your favorite superhero?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Mac or PC?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, heads or tails?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I want the truth!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, is the cake a lie?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how old are you?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s your birthday?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the loneliest number?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how many roads must a man walk down?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, how much is that doggie in the window?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, supercalifragilisticexpialodocious.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, see you later alligator.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is your quest?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do aliens exist?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is love?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what does the fox say?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do you believe in love at first sight?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, are you alive?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, have you ever seen the rain?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what color is the dress?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I like big butts.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do you feel lucky punk?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what do you want to be when you grow up?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, drum roll please.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sport Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is Babe Ruth’s lifetime batting average?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is the fastest man on earth?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the offside rule in soccer?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s your favorite sport?”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Star Wars Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the Jedi code?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the Sith code?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Star Wars fact.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Star Wars quote.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, do or do not.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is Luke Skywalker?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is Han Solo?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who is Darth Vader?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I am your father.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, tell me a Star Wars joke.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, that’s no moon.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, who shot first?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, it is a trap.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the Millennium Falcon?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, may the force be with you.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, use the force.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, move along.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I have a bad feeling about this”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Help me, Obi-Wan Kenobi.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, Never tell me the odds!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, I’m one with the Force. The Force is with me.”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Weather Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the weather like?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the weather in Johannesburg?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the weather in Pretoria, South Africa?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the weather going to be like Friday?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the weather this weekend?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the weather forecast this weekend?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what’s the extended weather forecast?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, will it snow today?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, will it rain tomorrow?”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Alexa, what is the temperature right now?”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Congratulations! You have now learned a large number of the built-in commands that is available on your Alexa device. The commands listed on this page is a small set of what is available. Try out these commands and also think of new questions to ask Alexa and then share them with the Alexa community. Follow me on any of the different social media platforms and feel free to leave comments.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/alexa-commands/" rel="noopener noreferrer"&gt;Alexa Commands&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com" rel="noopener noreferrer"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>alexa</category>
      <category>amazon</category>
      <category>commands</category>
    </item>
    <item>
      <title>How to Configure AWS CLI</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Wed, 28 Nov 2018 06:18:08 +0000</pubDate>
      <link>https://dev.to/andremare/how-to-configure-aws-cli-33fk</link>
      <guid>https://dev.to/andremare/how-to-configure-aws-cli-33fk</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswm7pjzdhwu3fbbd21o1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswm7pjzdhwu3fbbd21o1.png" alt="AWS" width="600" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post provides a set of commands on how to configure Amazon Web Services Command Line Interface (AWS CLI) on macOS or any other operating system. The AWS CLI is an open source tool that enables the user of the AWS platform to communicate and issue commands to AWS Services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements
&lt;/h3&gt;

&lt;p&gt;The following list defines the technologies, tools and credentials required to configure the AWS CLI tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS Account &amp;amp; Credentials.&lt;/li&gt;
&lt;li&gt;Installed AWS CLI tool. (&lt;a href="https://www.code2bits.com/how-to-install-awscli-on-macos-using-homebrew/" rel="noopener noreferrer"&gt;AWS CLI on macOS&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;iTerm or Terminal. (&lt;a href="https://www.code2bits.com/how-to-install-iterm2-on-macos-using-homebrew/" rel="noopener noreferrer"&gt;iTerm2 on macOS&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is AWS CLI?
&lt;/h3&gt;

&lt;p&gt;AWS CLI is an open source tool that enables AWS Platform users to communicate and issue commands to their services. The command line tool enables users to invoke the AWS Platform services via the different public APIs. The authentication and other security mechanisms are abstracted away from the user by configuring the AWS CLI with he user’s access key and secret. Furthermore, it provides higher level operations by combining the finer grained public APIs of the AWS Services into simple operations. These higher level operations will be more natural to use for a user. Users can now manage their AWS Services by creating shell scripts and automate simple and complex tasks alike.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quick Command
&lt;/h3&gt;

&lt;p&gt;This section provides the command on how to configure AWS CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;aws configure
AWS Access Key ID &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;OMLQ] : &lt;span class="k"&gt;********&lt;/span&gt;
AWS Secret Access Key &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;BQWW] : &lt;span class="k"&gt;***********&lt;/span&gt;
Default region name &lt;span class="o"&gt;[&lt;/span&gt;us-east-1]: eu-west-1
Default output format &lt;span class="o"&gt;[&lt;/span&gt;json]: json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Default Region&lt;/strong&gt; : For a list of available regions, see &lt;a href="https://docs.aws.amazon.com/general/latest/gr/rande.html" rel="noopener noreferrer"&gt;AWS Regions and Endpoints&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Default Output&lt;/strong&gt; : The default output format can be either &lt;em&gt;json&lt;/em&gt;, &lt;em&gt;text&lt;/em&gt;, or &lt;em&gt;table&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  AWS Configuration Files
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;~/.aws/credentials&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The AWS Credential file contains the credentials of multiple named profiles including the default profile. The credentials of each profile consist of the key/values for the aws_access_key_id and aws_secret_access_key properties. The AWS credentials file are located at ~/.aws/credentials on macOS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.aws/credentials
&lt;span class="o"&gt;[&lt;/span&gt;default]
&lt;span class="nv"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1234567890
&lt;span class="nv"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ

&lt;span class="o"&gt;[&lt;/span&gt;user2]
&lt;span class="nv"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0987654321
&lt;span class="nv"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ZYXWVUTSRQPONMLKJIHGFEDCBA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;~/.aws/config&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The CLI Configuration file contains the configuration of multiple named profiles including the default profile. The configuration of each profile consist of the key/values for the region and output properties. The AWS CLI configuration file are located at ~/.aws/config on macOS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.aws/config
&lt;span class="o"&gt;[&lt;/span&gt;default]
&lt;span class="nv"&gt;region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-west-2
&lt;span class="nv"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;json

&lt;span class="o"&gt;[&lt;/span&gt;profile user2]
&lt;span class="nv"&gt;region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east-1
&lt;span class="nv"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AWS Configure Commands
&lt;/h3&gt;

&lt;p&gt;The following are additional commands that can be used during the configuration of the AWS CLI tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. AWS Configure a Named Profile
&lt;/h3&gt;

&lt;p&gt;You can configure a named pro-file using the –profile argument as part of the AWS Configure command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;aws configure &lt;span class="nt"&gt;--profile&lt;/span&gt; administrator
AWS Access Key ID &lt;span class="o"&gt;[&lt;/span&gt;None] : 12334567890
AWS Secret Access Key &lt;span class="o"&gt;[&lt;/span&gt;None] : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Default region name &lt;span class="o"&gt;[&lt;/span&gt;None] : eu-west-1
Default output format &lt;span class="o"&gt;[&lt;/span&gt;None] : json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The named profile argument –profile can be appended to any of the AWS Configure commands to execute the command in context of that named profile.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Update a Specific Property
&lt;/h3&gt;

&lt;p&gt;You can run the AWS Configure command multiple times to update specific properties. To existing value is displayed in [brackets]. To update the existing value, type a new value and press enter. To keep an existing value, press enter without typing any value in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;aws configure
AWS Access Key ID &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;1234]: 
AWS Secret Access Key &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;1234]: 
Default region name &lt;span class="o"&gt;[&lt;/span&gt;eu-west-1] : 
Default output format &lt;span class="o"&gt;[&lt;/span&gt;json] : table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. List Config Data
&lt;/h3&gt;

&lt;p&gt;The following command can be used to list the AWS CLI Configuration data of the default profile. For each configuration item, it will show you the value, where the configuration value was retrieved, and the configuration variable name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;aws configure list
      Name                    Value             Type    Location
      &lt;span class="nt"&gt;----&lt;/span&gt;                    &lt;span class="nt"&gt;-----&lt;/span&gt;             &lt;span class="nt"&gt;----&lt;/span&gt;    &lt;span class="nt"&gt;--------&lt;/span&gt;
   profile                &amp;lt;not &lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;             None    None
access_key     &lt;span class="k"&gt;****************&lt;/span&gt;1234 shared-credentials-file    
secret_key     &lt;span class="k"&gt;****************&lt;/span&gt;1234 shared-credentials-file    
    region                eu-west-1      config-file    ~/.aws/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Congratulations! You have successfully configured AWS CLI and will now be able to issue commands to the AWS Platform. Follow me on any of the different social media platforms and feel free to leave comments.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/how-to-configure-aws-cli/" rel="noopener noreferrer"&gt;How to Configure AWS CLI&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com" rel="noopener noreferrer"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Counting Sort in Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Thu, 22 Nov 2018 05:53:17 +0000</pubDate>
      <link>https://dev.to/code2bits/counting-sort-in-java-1jkg</link>
      <guid>https://dev.to/code2bits/counting-sort-in-java-1jkg</guid>
      <description>&lt;p&gt;Counting Sort is an integer sorting algorithm. Counting Sort are unlike other sorting algorithms in that it makes certain assumptions about the data. It counts the number of objects with a distinct key value, and use arithmetic to determine the position of each key. This algorithm does not make use of comparisons to sort the values. In simplistic terms, the algorithm counts the number of occurrences of each value in order to sort it.&lt;/p&gt;

&lt;p&gt;The initial phase of the algorithm is to start counting the number of occurrences of the values within the array and increment the value associated with the counting key. The second phase is to write out the new sorted array making use of the number of occurrences of each of the counting keys.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Counting Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classification&lt;/td&gt;
&lt;td&gt;Internal, Not In-place Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n+k)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n+k)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n+k)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(k)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Counting Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CountingSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;findMaxValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;countingSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input paramenter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;countingSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;countArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;countOccurrences&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;reconstructArray&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;countArray&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;findMaxValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;highest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;highest&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;highest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;highest&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;countOccurrences&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;tempArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;maxValue&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="n"&gt;tempArray&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;]++;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;    
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tempArray&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;reconstructArray&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;countArray&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;countArray&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;countArray&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]--;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the Counting Sort class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/main/java/com/code2bits/algorithm/sort/CountingSort.java"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The details of the Counting Sort JUnit Test class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/test/java/com/code2bits/algorithm/sort/CountingSortTest.java"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Counting Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Counting Sort algorithm in Java. I have learned a lot about how others have solved the Counting Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/counting-sort-in-java/"&gt;Counting Sort in Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>countingsort</category>
      <category>java</category>
    </item>
    <item>
      <title>Quick Sort Algorithm in Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Wed, 21 Nov 2018 10:26:14 +0000</pubDate>
      <link>https://dev.to/code2bits/quick-sort-algorithm-in-java-2c7j</link>
      <guid>https://dev.to/code2bits/quick-sort-algorithm-in-java-2c7j</guid>
      <description>&lt;p&gt;Quick Sort, also known as partition-exchange sort, is an efficient divide and conquer sorting algorithm. The algorithm can be implemented making use of loops or recursions. The algorithm performs the sorting in-place. Quick Sort is a comparison sort, meaning that it can sort items of any type for which a “less-than” relation is defined.&lt;/p&gt;

&lt;p&gt;The algorithm divides the array into two smaller sub-arrays. To divide the algorithm into two array, an pivot or element within the array is chosen. The partition phase consist of reordering the array so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it. After the partition phase, the pivot is in its final position. The pivot logically splits the original array into two sub-arrays. The Quick Sort algorithm then recursively sort the sub-arrays by selecting a new pivot and move the values accordingly. Every element will be selected as the pivot and will be placed in the correct position.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Quick Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classification&lt;/td&gt;
&lt;td&gt;Internal, In-place, Unstable Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quick Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;QuickSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;quickSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input paramenter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;quickSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstPosition&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;            
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;partition&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;quickSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;quickSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;       
    &lt;span class="o"&gt;}&lt;/span&gt; 

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;partition&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;  
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;selectPivot&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;swap&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;pivotIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstPosition&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;lastPosition&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pivotIndex&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;swap&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;swap&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;pivotIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pivotIndex&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;   

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;swap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;selectPivot&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="o"&gt;)/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 

&lt;span class="o"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the Quick Sort class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/main/java/com/code2bits/algorithm/sort/QuickSort.java"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The details of the Quick Sort JUnit Test class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/test/java/com/code2bits/algorithm/sort/QuickSortTest.java"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Quick Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Quick Sort algorithm in Java. I have learned a lot about how others have solved the Quick Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/quick-sort-algorithm-in-java/"&gt;Quick Sort Algorithm in Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>java</category>
      <category>quicksort</category>
    </item>
    <item>
      <title>Merge Sort Algorithm in Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Wed, 21 Nov 2018 09:48:11 +0000</pubDate>
      <link>https://dev.to/code2bits/merge-sort-algorithm-in-java-5gfd</link>
      <guid>https://dev.to/code2bits/merge-sort-algorithm-in-java-5gfd</guid>
      <description>&lt;p&gt;Merge Sort is a divide and conquer algorithm as the algorithm splits the original array into smaller logical sections. The algorithm can be implemented making use of loops or recursions. The two distinct phases are a splitting phase and secondly a merging phase.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Splitting Phase&lt;/em&gt;: Divide the array into two unsorted arrays. Each of the split arrays are continuously split into smaller arrays until only multiple single element arrays exist. Single element arrays are sorted as they only have one element in them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Merging Phase&lt;/em&gt;: Each of the single element arrays are now merged back into a larger array. During the merge phase the two arrays are merged so that the elements are sorted within the new larger sorted array. This process is repeated until a single sorted array is left. This is not an in-place algorithm as temporary arrays are used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Merge Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classification&lt;/td&gt;
&lt;td&gt;Internal, Not In-place, Stable Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Merge Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MergeSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;mergeSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input paramenter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt;  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxIndex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxIndex&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minIndex&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;maxIndex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;mergeSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;mergeSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;mergeBack&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;       
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;mergeBack&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxIndex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;centre&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;tempMinIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;tempCentre&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;tempIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;tempArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;maxIndex&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;tempMinIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tempCentre&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;maxIndex&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tempMinIndex&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tempCentre&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;tempArray&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tempIndex&lt;/span&gt;&lt;span class="o"&gt;++]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tempMinIndex&lt;/span&gt;&lt;span class="o"&gt;++];&lt;/span&gt;    
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;tempArray&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tempIndex&lt;/span&gt;&lt;span class="o"&gt;++]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tempCentre&lt;/span&gt;&lt;span class="o"&gt;++];&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;arraycopy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tempMinIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;tempIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;centre&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;tempMinIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;arraycopy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tempArray&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minIndex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tempIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;   
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the MergeSort class can be viewed here.&lt;br&gt;&lt;br&gt;
The details of the MergeSort JUnit Test class can be viewed here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Merge Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Merge Sort algorithm in Java. I have learned a lot about how others have solved the Merge Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/merge-sort-algorithm-in-java/"&gt;Merge Sort Algorithm in Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>java</category>
      <category>mergesort</category>
    </item>
    <item>
      <title>Shell Sort Algorithm in Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Wed, 21 Nov 2018 06:07:24 +0000</pubDate>
      <link>https://dev.to/code2bits/shell-sort-algorithm-in-java-4hek</link>
      <guid>https://dev.to/code2bits/shell-sort-algorithm-in-java-4hek</guid>
      <description>&lt;p&gt;Shell Sort is an in-place comparison sort algorithm. Shell Sort is a generalization of insertion sort that allows the exchange of items that are far apart. The algorithm perform preliminary work by sorting pairs of elements far apart from each other. The algorithm progressively reduce the gap between elements to be compared as the goal is to reduce the amount of shifting of elements across the array. As the gap is reduced to 1, the algorithm becomes the same as the insertion sort algorithm.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Shell Sort Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classification&lt;/td&gt;
&lt;td&gt;Internal, In-place, Unstable Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n log(n))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n log&lt;sup&gt;2&lt;/sup&gt;n)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shell Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ShellSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;shellSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input paramenter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;shellSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;/=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;

                &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
                    &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;gap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
                &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the Shell Sort class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/main/java/com/code2bits/algorithm/sort/ShellSort.java"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The details of the Shell Sort JUnit Test class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/test/java/com/code2bits/algorithm/sort/ShellSortTest.java"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Shell Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Shell Sort algorithm in Java. I have learned a lot about how others have solved the Shell Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/shell-sort-algorithm-in-java/"&gt;Shell Sort Algorithm in Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>java</category>
      <category>shellsort</category>
    </item>
    <item>
      <title>Insertion Sort Algorithm in Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Tue, 20 Nov 2018 09:06:52 +0000</pubDate>
      <link>https://dev.to/code2bits/insertion-sort-algorithm-in-java-nd7</link>
      <guid>https://dev.to/code2bits/insertion-sort-algorithm-in-java-nd7</guid>
      <description>&lt;p&gt;Insertion sort is a sorting algorithm that builds the final sorted array (or list) one item at a time. The algorithm iterates over the list and removes the current element, finds the location within the sorted part of the list, and inserts it there. This process is repeated until the whole list is sorted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Insertion Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classification&lt;/td&gt;
&lt;td&gt;Internal, In-place, Stable Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Insertion Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InsertionSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;insertionSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input parameter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 


    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;insertionSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;--)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the InsertionSort class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/main/java/com/code2bits/algorithm/sort/InsertionSort.java"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The details of the InsertionSort JUnit Test class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/test/java/com/code2bits/algorithm/sort/InsertionSortTest.java"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Insertion Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Insertion Sort algorithm in Java. I have learned a lot about how others have solved the Insertion Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/insertion-sort-algorithm-in-java/"&gt;Insertion Sort Algorithm in Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>insertionsort</category>
      <category>java</category>
    </item>
    <item>
      <title>Insertion Sort in Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Tue, 20 Nov 2018 09:06:52 +0000</pubDate>
      <link>https://dev.to/code2bits/insertion-sort-in-java-50h7</link>
      <guid>https://dev.to/code2bits/insertion-sort-in-java-50h7</guid>
      <description>&lt;p&gt;Insertion sort is a sorting algorithm that builds the final sorted array (or list) one item at a time. The algorithm iterates over the list and removes the current element, finds the location within the sorted part of the list, and inserts it there. This process is repeated until the whole list is sorted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Insertion Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classification&lt;/td&gt;
&lt;td&gt;Internal, In-place, Stable Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Insertion Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InsertionSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;insertionSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input parameter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 


    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;insertionSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;--)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newElement&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the InsertionSort class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/main/java/com/code2bits/algorithm/sort/InsertionSort.java"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The details of the InsertionSort JUnit Test class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/test/java/com/code2bits/algorithm/sort/InsertionSortTest.java"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Insertion Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Insertion Sort algorithm in Java. I have learned a lot about how others have solved the Insertion Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/insertion-sort-in-java/"&gt;Insertion Sort in Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>insertionsort</category>
      <category>java</category>
    </item>
    <item>
      <title>Selection Sort Algorithm In Java</title>
      <dc:creator>André Maré</dc:creator>
      <pubDate>Tue, 20 Nov 2018 06:15:13 +0000</pubDate>
      <link>https://dev.to/code2bits/selection-sort-algorithm-in-java-331a</link>
      <guid>https://dev.to/code2bits/selection-sort-algorithm-in-java-331a</guid>
      <description>&lt;p&gt;Selection sort is a sorting algorithm, specifically an in-place comparison sort and is used for sorting an array of integers. The algorithm divides the input list into two parts, sorted and unsorted. The algorithm looks for the largest element in the unsorted section and swap it with the last position in the unsorted partition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm Classification
&lt;/h3&gt;

&lt;p&gt;The following table contains information about the analysis of the Selection Sort algorithm. It defines the worst, average and best cases in terms of time complexity and also the worst case in space complexity.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Classification&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Sorting Algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Structure&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Best&lt;/td&gt;
&lt;td&gt;Ω(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Average&lt;/td&gt;
&lt;td&gt;Θ(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity: Worst&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Please use the following &lt;a href="http://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png"&gt;link&lt;/a&gt; for an explanation on Big-O notation and what is good, fair and bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selection Sort In Java
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SelectionSort&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;selectionSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Input paramenter for array to sort is null."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;selectionSort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arrayLength&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;--)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;largest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;largest&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;largest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;swap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;largest&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unsortIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;swap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;   
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Code (GitHub)
&lt;/h4&gt;

&lt;p&gt;The details of the SelectionSort class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/main/java/com/code2bits/algorithm/sort/SelectionSort.java"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The details of the SelectionSort JUnit Test class can be viewed &lt;a href="https://github.com/Code2Bits/Algorithms-in-Java/blob/master/sort/src/test/java/com/code2bits/algorithm/sort/SelectionSortTest.java"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Selection Sort algorithm forms part of a larger group of sorting algorithms. Learning through experience is the reason I created this post about the implementation of the Selection Sort algorithm in Java. I have learned a lot about how others have solved the Selection Sort algorithm in other languages including different implementations in Java.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.code2bits.com/selection-sort-algorithm-in-java/"&gt;Selection Sort Algorithm In Java&lt;/a&gt; appeared first on &lt;a href="https://www.code2bits.com"&gt;Code2Bits&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sortalgorithms</category>
      <category>algorithms</category>
      <category>java</category>
      <category>selectionsort</category>
    </item>
  </channel>
</rss>
