Tree Sort is a sorting algorithm that works by first building a binary search tree from the elements to be sorted and then traversing the tree in-order to obtain the sorted sequence. It's an efficient algorithm that takes advantage of the binary search tree's properties to achieve a time complexity of O(n log n) in the average and best cases. However, in the worst case, it can have a time complexity of O(n^2) if the input is already sorted or nearly sorted, making it less suitable for some scenarios.
Algorithm Steps:
Start with the unsorted input array.
Create an empty binary search tree (BST).
For each element in the input array, insert it into the BST.
.If the BST is empty, the first element becomes the root.
.For other elements, follow the BST's insertion rules to place them in the appropriate position based on their values.
Perform an in-order traversal of the BST to obtain the elements in sorted order.
.in-order traversal involves visiting the left subtree, visiting the current node, and then visiting the right subtree.
The in-order traversal of a binary search tree visits the nodes in ascending order, which is why the Tree Sort algorithm produces a sorted sequence.
Tree Sort has some advantages, such as being an adaptive algorithm that can perform efficiently on partially sorted or nearly sorted arrays. However, it requires additional memory space to store the binary search tree, and in certain cases, it may not be the most efficient choice.
@Kumar-laxmi can you assigned me this algo, so i can make pr
Tree Sort is a sorting algorithm that works by first building a binary search tree from the elements to be sorted and then traversing the tree in-order to obtain the sorted sequence. It's an efficient algorithm that takes advantage of the binary search tree's properties to achieve a time complexity of O(n log n) in the average and best cases. However, in the worst case, it can have a time complexity of O(n^2) if the input is already sorted or nearly sorted, making it less suitable for some scenarios.
Algorithm Steps:
The in-order traversal of a binary search tree visits the nodes in ascending order, which is why the Tree Sort algorithm produces a sorted sequence.
Tree Sort has some advantages, such as being an adaptive algorithm that can perform efficiently on partially sorted or nearly sorted arrays. However, it requires additional memory space to store the binary search tree, and in certain cases, it may not be the most efficient choice.
@Kumar-laxmi can you assigned me this algo, so i can make pr