[Haskell-cafe] Branches of a binary tree

Stefan O'Rear stefanor at cox.net
Fri Jul 6 11:56:08 EDT 2007


On Fri, Jul 06, 2007 at 11:47:58AM -0400, Kyle L Bittinger wrote:
> I am writing some code to find peaks in molecular spectra. I represent a 
> spectrum as a list of numbers (intensities) and build a binary search tree 
> of the positions in the list (x-values) sorted by intensity.

In general, the best way to implement binary search trees in Haskell is:

-- <http://haskell.org/ghc/dist/current/docs/libraries/base/Data-Set.html>
import qualified Data.Set as S

If you can avoid depending on the details of balancing... :(

> Peaks in the spectrum appear as branches of the tree. My task is to return 
> branches of a binary tree that contain no other branches larger than some 
> size.
>
> I wrote this function to test whether a tree can be classified as a peak. I 
> suspect it's very inefficient, and it doesn't seem idiomatic to me either. 
> I'm looking for suggestions to improve it:

Stefan


More information about the Haskell-Cafe mailing list