please help me: build a binary search tree by Lisp

Please support our Legacy and Other Languages advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 2
Reputation: xzhang is an unknown quantity at this point 
Solved Threads: 0
xzhang xzhang is offline Offline
Newbie Poster

please help me: build a binary search tree by Lisp

 
0
  #1
Apr 21st, 2007
Write lisp for two functions that manipulate binary search trees. The tree will now be a nested list structure. Inserting 4, 2, 5, 1, 6, 3 should create the list: (4 (2 (1 () ()) (3 () ())) (5 () (6 () ())))


1.Write a lisp (scheme) function (isIn? item binTree) that returns #t if the item is in the binary search tree ‘binTree’, otherwise it returns #f.

2.Write a lisp (scheme) function (with helpers?) that builds a binary tree equivalent to the CLIPS binary tree for any input list. The main function will be called by (binTree () list)
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 36
Reputation: azimuth0 is an unknown quantity at this point 
Solved Threads: 5
azimuth0 azimuth0 is offline Offline
Light Poster

Re: please help me: build a binary search tree by Lisp

 
0
  #2
May 9th, 2007
I'm sorry, but what is it that you need help with?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: please help me: build a binary search tree by Lisp

 
0
  #3
May 28th, 2007
This looks like a homework assignment. Nobody but a college professor would use LISP.

We don't do your homework for you. But I can get you thinking.

LISP is a prefix language, so it is obvious that the binary tree structure you have is also prefix. A quick look confirms it.

So each node of the tree includes three list items, in this order:

- the node's element (a numeric atom)

- the left child branch of the tree (which is either a tree node or an empty list)

- the right child branch of the tree (which is either a tree node or an empty list)

Since it is a binary tree, all of the elements in the left child must be less than the element in the current node. Likewise, all of the elements in the right child must be greater than the element in the current node.

So your function should be able to tell which way to go by looking at the current node. 4 possibilites exist:

1. The current node is empty. You didn't find the search item.

2. The current node element equals the search value. You found it.

3. The current node element is larger than the search value. Recursively go left.

4. The current node element is smaller than the search value. Recursively go right.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 36
Reputation: azimuth0 is an unknown quantity at this point 
Solved Threads: 5
azimuth0 azimuth0 is offline Offline
Light Poster

Re: please help me: build a binary search tree by Lisp

 
0
  #4
May 28th, 2007
You are incorrect. Both Common Lisp and Scheme are perfectly good industry languages with wide platform support and usage. For many, including myself, a lisp language is their preferred language.

I've seen lisp written by college professors, and it's awful. They only use lists, when an array, hash, or class would have been better.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: please help me: build a binary search tree by Lisp

 
2
  #5
May 29th, 2007
Originally Posted by MidiMagic View Post
LISP is a prefix language, so it is obvious that the binary tree structure you have is also prefix.
What do you mean, in that it is "prefix"?
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 5112 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Legacy and Other Languages
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC