Skip to content
murmot

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

  • geeksforgeeks.org

    TimSort - GeeksforGeeks

    Driver Code Ends. Python.Applications of Tim Sort: Used as the default sorting algorithm in Python (sorted(), list.sort()) and Java (from Java 7 onwards for Arrays.sort() on objects). Particularly effective for real-world datasets where data is often partially sorted.

  • 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

    Pancake sorting - GeeksforGeeks

    Pancake sorting. Last Updated : 23 Jul, 2025. Given an unsorted array, the task is to sort the given array. You are allowed to do only following operation on array.This code is contributed by Devesh Agrawal*/. Python3.

  • 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

    Bubble Sort - GeeksforGeeks

    Sorts the array using multiple passes. After the first pass, the maximum goes to end (its correct position).# Optimized Python program for implementation of Bubble Sort def bubbleSort(arr): n = len(arr) #. Traverse through all array elements for i in range(n)

  • 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

    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.