Wednesday, March 20, 2013

Tree traversal is used to print data in a binary tree. There are two main types of tree traversal. Depth-first and Breadth-first. Depth-first traversal can be further divided into three types: pre-order traversal, in-order traversal and post-order traversal. Lets get started.



Depth-first

Pre-order Traversal

  • Visit the root.
  • Traverse the left subtree in pre-order
  • Traverse the right subtree in pre-order

In-order Traversal

  • Traverse the left subtree in in-order
  • Visit the root.
  • Traverse the right subtree in in-order

Post-order Traversal

  • Visit the root.
  • Traverse the left subtree in post-order
  • Traverse the right subtree in post-order

Those the main ideas behind the three depth-first traversals. To give you a clearer understanding, here are the basic algorithms for each traversal.

Pre-order traversal algorithm



In-order traversal algorithm




Post-order traversal algorithm



Breadth-first

Level-order Traversal

  • Visit the nodes starting from the top until the bottom. Print them from left to right.



Now, let us look at some examples. 

1.


Pre-order sequence: A B D G E C F
In-order sequence: G D B E A C F
Post-order sequence: G D E B F C A
Level-order sequence: A B C D E F G



2.


Pre-order sequence: A B D E G C F H
In-order sequence: D B G E A C F H
Post-order sequence: D G E B H F C A
Level-order sequence: A B C D E F G H


3.

Pre-order sequence: A B D F H I E G C
In-order sequence: F H I D B G E A C
Post-order sequence: I H F D G E B C A
Level-order sequence: A B C D E F G H I




If you followed the algorithms correctly, you would get the same answers. You could practice using those algorithms until you get a hang of it. I will add more examples in the future so that you can practice more cases. I will also post another tutorial about traversals that will teach you how to output the different sequences in a fast and simple way. But for now, that's all.



    Hello! Welcome to Code Realm.

    This is a site where you can learn different programming languages such as HTML, CSS, PHP, Java, C and C++. I will also teach some algorithms and post random tips.

    I know there are already tons of websites that teaches those things but I will teach it in a way beginners will easily understand. Most of the programming tutorial sites I visit teaches the concepts but they do not usually give adequate examples for the people to understand the concepts. It is true that you can learn by reading the concepts but examples give people a better understanding on how it works. Therefore, I will give lots of examples that is practical and will make you easily comprehend the things I will teach.

    Be sure to check this site for the tutorials that I will post.

    Tuesday, March 19, 2013


    This Privacy Policy governs the manner in which coderealm.blogspot collects, uses, maintains and discloses information collected from users (each, a "User") of the http://coderealm.blogspot.com/ website ("Site"). This privacy policy applies to the Site and all products and services offered by coderealm.blogspot.

    Personal identification information

    We may collect personal identification information from Users in a variety of ways in connection with activities, services, features or resources we make available on our Site.. Users may visit our Site anonymously. We will collect personal identification information from Users only if they voluntarily submit such information to us. Users can always refuse to supply personally identification information, except that it may prevent them from engaging in certain Site related activities.

    Non-personal identification information

    We may collect non-personal identification information about Users whenever they interact with our Site. Non-personal identification information may include the browser name, the type of computer and technical information about Users means of connection to our Site, such as the operating system and the Internet service providers utilized and other similar information.

    Web browser cookies

    Our Site may use "cookies" to enhance User experience. User's web browser places cookies on their hard drive for record-keeping purposes and sometimes to track information about them. User may choose to set their web browser to refuse cookies, or to alert you when cookies are being sent. If they do so, note that some parts of the Site may not function properly.

    How we use collected information

    coderealm.blogspot may collect and use Users personal information for the following purposes:
    • - To personalize user experience
      We may use information in the aggregate to understand how our Users as a group use the services and resources provided on our Site.
    • - To send periodic emails
      We may use the email address to respond to their inquiries, questions, and/or other requests.
    How we protect your information

    We adopt appropriate data collection, storage and processing practices and security measures to protect against unauthorized access, alteration, disclosure or destruction of your personal information, username, password, transaction information and data stored on our Site.

    Sharing your personal information

    We do not sell, trade, or rent Users personal identification information to others. We may share generic aggregated demographic information not linked to any personal identification information regarding visitors and users with our business partners, trusted affiliates and advertisers for the purposes outlined above.We may use third party service providers to help us operate our business and the Site or administer activities on our behalf, such as sending out newsletters or surveys. We may share your information with these third parties for those limited purposes provided that you have given us your permission.

    Third party websites

    Users may find advertising or other content on our Site that link to the sites and services of our partners, suppliers, advertisers, sponsors, licensors and other third parties. We do not control the content or links that appear on these sites and are not responsible for the practices employed by websites linked to or from our Site. In addition, these sites or services, including their content and links, may be constantly changing. These sites and services may have their own privacy policies and customer service policies. Browsing and interaction on any other website, including websites which have a link to our Site, is subject to that website's own terms and policies.


    Changes to this privacy policy

    coderealm.blogspot has the discretion to update this privacy policy at any time. When we do, we will revise the updated date at the bottom of this page. We encourage Users to frequently check this page for any changes to stay informed about how we are helping to protect the personal information we collect. You acknowledge and agree that it is your responsibility to review this privacy policy periodically and become aware of modifications.

    Your acceptance of these terms

    By using this Site, you signify your acceptance of this policy. If you do not agree to this policy, please do not use our Site. Your continued use of the Site following the posting of changes to this policy will be deemed your acceptance of those changes.

    Contacting us

    If you have any questions about this Privacy Policy, the practices of this site, or your dealings with this site, please contact us at:
    coderealm.blogspot
    http://coderealm.blogspot.com/
    coderealm.blogspot@gmail.com

    This document was last updated on March 22, 2013

    Privacy policy created by Generate Privacy Policy