Skip to content
murmot

Results for “sort array java example python code site:geeksforgeeks.org 2”

  • geeksforgeeks.org

    Merge Sort - GeeksforGeeks

    Merge sort is a popular sorting algorithm known for its efficiency and stability. It follows the Divide and Conquer approach. It works by recursively dividing the input array into two halves, recursively sorting the two halves and finally merging them back together to obtain the sorted array.

  • geeksforgeeks.org

    Sort Array - GeeksforGeeks

    Oct 25, 2026 · Implement Sort - O (n log n) Time and O (n) Space The idea is to implement a sorting algorithm yourself. In the following code we have implemented Merge Sort which takes O (n Log n) time and O (n) Space. Other sorting methods can also be used to sort the array, depending on the requirements and the type of operations involved. Some commonly used sorting methods are: Insertion Sort - O (n ^ 2 ...

  • geeksforgeeks.org

    How to sort an array in a single loop? - GeeksforGeeks

    # Python3 code to sort an array of integers # with the help of single loop #. Function for Sorting the array # using a single loop def sortArrays(arr): # Finding the length of array 'arr' length = len(arr) #.This code is contributed by Rajput-Ji. Java.

  • geeksforgeeks.org

    Sorting in Java - GeeksforGeeks

    Apr 16, 2026 · Example 2: A sample Java program to sort an array in descending order using Arrays.sort ().

  • geeksforgeeks.org

    Sorting Array with Two Swaps - GeeksforGeeks

    May 4, 2026 ... Sorting Array with Two Swaps · For each swap, place element at its correct position · After swaps, check if array is sorted · Return true if sorted ...

  • geeksforgeeks.org

    Java Program to Sort Names in an Alphabetical Order

    Jul 23, 2025 · For, sorting names in an Alphabetical order there are multiple ways to sort the array, like using inbuilt Arrays.sort () method or using normal sorting algorithms like the bubble sort, merge sort.

  • geeksforgeeks.org

    Add elements in start to sort the array | Variation of... - GeeksforGeeks

    Stalin sort (also 'dictator sort' and 'trump sort') is a nonsensical 'sorting' algorithm in which each element that is not in the correct order is simply eliminated from the list.Function to sort the array def variationStalinsort(arr): j = 0 while True: moved = 0. for i in range(len(arr) - 1 - j)

  • geeksforgeeks.org

    Java Program to Sort the Elements of an Array in Ascending ...

    Aug 18, 2026 · Sorting an array in ascending order means arranging its elements from the smallest value to the largest value. In Java, an array can be sorted using the built-in Arrays.sort () method or by implementing a sorting algorithm such as Bubble Sort.

  • geeksforgeeks.org

    Pancake sorting - GeeksforGeeks

    # Python3 program to # sort array using # pancake sort #.Time Complexity: O(n2), Total O(n) flip operations are performed in above code Auxiliary Space: O(1). Recursive Approach.

  • geeksforgeeks.org

    sort() in Python - GeeksforGeeks

    Jan 3, 2018 · The sort () method in Python is used to arrange the elements of a list in a specific order. It works only on lists, modifies the original list in place, and does not return a new list. Example: This example shows the most basic use of sort () to arrange numbers in ascending order.