Sorting in python

Sorting in python

In this article, we are going to discuss two sorting algorithms and their differences.

What’s sorting?

Sorting is nothing but arranging the items in a particular sequence. In other words, sorting is the ordering of elements based on our preference. Preference can be ascending or descending depending on our requirements.

In this article, we are going to discuss two sorting algorithms and their differences.

  1. Insertion sort
  2. Merge sort

Insertion sort

Consider a list of elements

x = [73, 79, 56,  4, 48, 35]

Implementation strategy for ascending order

Step 1:

key_element = x[key]

x[:key] is the list that contains all the elements before the key element
x[:key] is sorted

Step 2:

if some of the elements in x[:key] is greater than x[key]

do pairwise swaps until all the elements in the x[:key+1] is sorted

Step 3:

if all the elements in that x[:key+1] is sorted then move the key to the next index until there's no index left

programming python

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Guide to Python Programming Language

Guide to Python Programming Language

Python Programming: A Beginner’s Guide

Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?

Python Hello World Program - Create & Run Your First Python Program in PyCharm

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.

Python Programming Tutorials For Beginners

Python Programming Tutorials For Beginners

How to Remove all Duplicate Files on your Drive via Python

Today you're going to learn how to use Python programming in a way that can ultimately save a lot of space on your drive by removing all the duplicates. We gonna use Python OS remove( ) method to remove the duplicates on our drive. Well, that's simple you just call remove ( ) with a parameter of the name of the file you wanna remove done.