Home arrow Practices arrow Page 7 - Sort This Sort That

Left(node) and Right(node) - Practices

One of the main activities in algorithms and programs, whose purpose is manipulating data, is sorting. So if you write these kinds of programs-what kind of method for sorting data is best? In this article I will present some algorithms for sorting and their advantages and weaknesses.

TABLE OF CONTENTS:
  1. Sort This Sort That
  2. Sorting
  3. Inserting Methods
  4. Decrementing Increment or Just Shell-Sort
  5. Selection Methods
  6. Sorting with Binary Tree
  7. Left(node) and Right(node)
By: Djordje Popovic
Rating: starstarstarstarstar / 21
February 25, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

First, something about the procedure that goes through this binary tree creating sorted array. We have a procedure get_value(node) that accepts as an argument the type of node and gets the node's data value and puts it in an array.  There are also two procedures named left(node) and right(node) that return the left or right child node of the parent node set as the argument (this means pointers to the left or right child-node). If this is clear, see the procedure for sorting.


BINARY_TREE_SORT(root)
if
(root!=nullthen
 BINARY_TREE_SORT
(left(root))
 get_value
(root)
 BINARY_TREE_SORT
(right(root))
end_if

As it is shown this procedure is recursive and accepts one argument of type node. When we start this procedure it recursively calls itself until it reaches the further-most left child-node that has no left child of it's own. Then with a get_value procedure, it stores that node's data value in the array and again calls binary_tree_sort procedure for that node’s further-most right child.  This recursion goes on until all elements (all recursion ends) are visited. This algorithm is efficient for all kinds of binary trees and also known as "inorder tree visit".

Conclusion

I have presented two types of sorting methods: inserting and selection methods. In the next article we will go further with inner-sorting methods and I will try to present to you some linear-complex methods for sorting such as counting-sort, bucket-sort and distribution sort. Until then enjoy your sorting!



 
 
>>> More Practices Articles          >>> More By Djordje Popovic
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PRACTICES ARTICLES

- Calculating Development Project Costs
- More Techniques for Finding Things
- Finding Things
- Finishing the System`s Outlines
- The System in So Many Words
- Basic Data Types and Calculations
- What`s the Address? Pointers
- Design with ArgoUML
- Pragmatic Guidelines: Diagrams That Work
- Five-Step UML: OOAD for Short Attention Span...
- Five-Step UML: OOAD for Short Attention Span...
- Introducing UML: Object-Oriented Analysis an...
- Class and Object Diagrams
- Class Relationships
- Classes

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: