Radix Sort in Kotlin

Radix sort is a non-comparative sorting algorithm that sorts integers by grouping them based on their individual digits, or more generally, on their individual “radix” (base). The algorithm sorts the input integers from least significant digit (LSD) to most significant digit (MSD), with each pass sorting the integers based on the current digit position. The … Read more

Heap Sort in Kotlin

Heap sort is a popular sorting algorithm that works by first creating a binary heap from the array to be sorted and then repeatedly removing the root element of the heap, which is the maximum element, and placing it at the end of the array. The remaining elements in the heap are then reorganized to … Read more

Merge Sort in Kotlin

Merge sort is a popular sorting algorithm that works by recursively dividing an array into smaller sub-arrays until each sub-array has only one element, and then merging the sub-arrays back together in sorted order. The merging process involves comparing the first element of each sub-array and adding the smaller of the two elements to a … Read more

Quick Sort in Kotlin

Quicksort is a popular sorting algorithm that works by dividing an array into two smaller sub-arrays based on a chosen pivot element, such that all elements to the left of the pivot are smaller and all elements to the right are larger. The two sub-arrays are then recursively sorted using the same process, until the … Read more

Bubble Sort in Kotlin

Bubble sort is a simple sorting algorithm that repeatedly iterates through the array, compares adjacent elements and swaps them if they are in the wrong order. During each pass through the array, the largest element will “bubble” to the end of the unsorted part of the array, so the algorithm gets its name from this … Read more

Selection Sort in Kotlin

Selection sort is another simple sorting algorithm that works by repeatedly finding the minimum (or maximum) element from the unsorted part of the array or list and placing it at the beginning of the sorted part. The algorithm divides the array or list into two parts: the sorted part and the unsorted part. The sorted … Read more

Insertion Sort in Kotlin

Insertion sort is a simple sorting algorithm that works by building the final sorted array or list one element at a time, by inserting each unsorted element into its proper position within the sorted array or list. The algorithm maintains a sub-array of sorted elements and inserts each new element into its proper position within … Read more

Median of a Sorted Matrix in Kotlin

To find the median of a row-wise sorted matrix, we can follow the below steps: This function takes a 2D array matrix of integers as input and returns the median value as an integer. The function first finds the minimum and maximum elements in the matrix by iterating through all the rows. Then, it uses … Read more