sorting

Heap Sort in Java

Posted on Updated on

Heap Sort is a comparison-based sorting algorithm to create a sorted array. It is similar to selection sort where we first find the maximum element from array and place it at the end. We repeat this process for each element in the given array. Heap Sort is based on Binary Heap data structure. In this program we will be sorting the given array in ascending order. Read the rest of this entry »

Sort dictionary in Python

Posted on

Python dictionary stores data in key-value pairs. In some situations, programmers need to sort the dictionary object as per their requirement which may be based on key or value. To sort dictionary object, you can user sorted() method and pass either keys or values from the dictionary which sorts the elements in their natural order. For example, if the elements are all integers, then smaller numbers go earlier in the list. If the elements are all strings, they are arranged in alphabetic order. Below examples demonstrate different ways to sort the dictionary based on key or value. Read the rest of this entry »

Difference between sorted() and list.sort() method

Posted on Updated on

There are different ways to sort a list in Python. You can find examples to sort a list in our article sort list in Python. Most popular ways are using sorted() and list.sort() methods. Each method has some advantage over other. In this article, we will be discussing difference between sorted() and list.sort() method. Read the rest of this entry »

Sort list in Python

Posted on Updated on

Python has different methods to sort elements of a list. These methods arrange elements in their natural order either in ascending or descending order. For example, if the elements are all integers, then smaller numbers go earlier in the list. If the elements are all strings, they are arranged in alphabetic order. Below are examples to sort list using list.sort(), sorted() method in ascending and descending order. Read the rest of this entry »