Thread: Data structures --binary search tree

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    25

    Data structures --binary search tree

    I have been given a program to create and display binary search tree.i have a doubt regarding display. i want to know should the display function shows the bst like we draw in paper or i have to traverse the in all the 3 possible ways(in,pre,post order and then print the elements in linear fashion.
    for ex:- if user input is 20
    bst:----> 20
    after that i/p is 17,6,8
    bst----> 20
    17
    6 18
    8
    or simply i traverse the tree in all the 3 orders.
    i think its better if i display it in first manner,because it is more clear and understandable.i am new to trees and graphs.i want to implement this program in c without any graphics so please help me how to display using printf statements and format specifiers like \n or \t.
    it will be very helpfull if you give me the algorithm/pseudo code or sourcecode for display function or any weblink in which it is given.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    We don't hand out code here, it's against our homework policy.

    Most likely, you won't be expected to try and draw it "like you do on paper". You generally want to print them in the order visited. An in-order traversal would print the nodes in sorted order. A pre-order prints the current node before visiting either child, and a post order after visiting either child. It's convention to visit the left child before the right child.

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    25
    thank u.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    You're welcome

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  2. A Binary Search Tree of... Binary Search Trees...
    By SlyMaelstrom in forum C++ Programming
    Replies: 5
    Last Post: 12-10-2005, 02:12 PM
  3. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  4. problem in storing data in a binary search tree
    By alavardi in forum C Programming
    Replies: 5
    Last Post: 02-13-2005, 03:20 PM
  5. Building a Binary Search Tree off sorted data
    By BlackCitan in forum C Programming
    Replies: 0
    Last Post: 12-01-2003, 09:52 PM