Binary Search Tree

This is a discussion on Binary Search Tree within the C Programming forums, part of the General Programming Boards category; Hi guys, how can I write a simple program which returns true if the given binary tree is binary search ...

  1. #1
    ibo
    ibo is offline
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Question Binary Search Tree

    Hi guys, how can I write a simple program which returns true if the given binary tree is binary search tree and false otherwise...

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    Recursion! Look at the current node. If there are no children, return true. If there are child nodes, then depending on if it is a left or right child, the value contained in that child should either be less-than or greater-than the current node's value. If not what you expected, then return false otherwise you then need to recurse through those children.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    ibo
    ibo is offline
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Thanks

    Thanks for your reply...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 10:07 AM
  2. BST (Binary search tree)
    By praethorian in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 08:11 AM
  3. searching and insertion in a binary search tree
    By galmca in forum C Programming
    Replies: 1
    Last Post: 03-26-2005, 04:15 PM
  4. binary search and search using binary tree
    By Micko in forum C++ Programming
    Replies: 9
    Last Post: 03-18-2004, 09:18 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21