The Artima Developer Community
Sponsored Link

Java Answers Forum
Binary Search Tree

1 reply on 1 page. Most recent reply: Nov 18, 2002 10:47 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Monique

Posts: 1
Nickname: loonietune
Registered: Nov, 2002

Binary Search Tree Posted: Nov 17, 2002 12:01 PM
Reply to this message Reply
Advertisement
I need to create an index for text stored in a file(the index gives the line numbers that a word appears on). There are two input files: a text file called "data.txt", for which you build the indiex and a "dismiss" file called "dismiss.txt" which contains a list of words which should not be shown in the index. The output will be placed in a file that your program creates, named "out.txt"

How would you do this using a binary search tree?


I'd appreciate any type of help

Below is what I've come up with so far

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.util.*;

public class Program3

{


public static void main(String args[])throws Exception

{

FileReader fr = new FileReader("data.txt");

BufferedReader br = new BufferedReader(fr);


FileReader rf = new FileReader("dismiss.txt");

BufferedReader rb = new BufferedReader (rf);

PrintWriter pw = new PrintWriter(new FileWriter("out.txt"));



String s;


while ((s = br.readLine()) != null)

{


pw.println(s);

}

while ((s = rb.readLine()) != null)

{

pw.println(s);

}


fr.close();

rf.close();

pw.close();

}

public class BST

{

public BST (String val)

{

info = val;

}

String info;

Node left, right;

}

public void insert(String s)

{







}

public void find( String s)

{





}

public class NumList

{

public NumList()

{









}



}

}


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Binary Search Tree Posted: Nov 18, 2002 10:47 PM
Reply to this message Reply
I wouldn't -- I'd use a Map.

What is a Binary Search Tree, anyway? Do you mean binary search, or binary tree? A binary search is a faster way (than linear) of searching a sorted list. A binary tree's keys could be searched this way, of course, but what is really going on in that case is probably a recursive search of the tree, unless all the keys are moved, in order, into a List.

Or are you simply talking about using a TreeMap? In this case, you can just use a Map; it is then quite easy to put any of its implementations behind it (TreeMap, HashMap, Hashtable). If you really need things sorted, then you'd use SortedMap and you'd be pretty much limitted to TreeMap.

I think the more important issue here is how you index words -- for instance, you'll want to make it case-insensitive and be sure to strip out all punctuation and ignore non-words, in addition to those words you are filtering.

Flat View: This topic has 1 reply on 1 page
Topic: How do i loop Previous Topic   Next Topic Topic: a for loop that needs explaing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use