Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing a binary search tree in a (key,value)-pair where key: name of student and value: mark  RSS feed

 
kamal lamgade
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!
The one below is the exercise I'm trying :
"Create a file BinarySearchTree.java which implements a simple binary search tree. Each node in the tree should store two pieces of information: a String variable called name, and a int variable called mark.The nodes in the tree are sorted by name in alphabetical (dictionary) order. " This is how i am trying . Is it a right way?

Some ideas would be really appreciable. Cheers
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this wikipedia entry.
 
Piet Souris
Rancher
Posts: 1979
67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi kamal,

You wrote:This is how i am trying . Is it a right way?

At first glance: the code looks okay to me.
But there's only one way to find out: test it!

While doing so, you will notice some problems (at least, given the code
you presented)

1) there is no contructor for your BST class. So, how would you create an instance?
2) how would you set your root node?
3) how do you intend to add another node to the BST? You would need at least
some nodes to do a decent test.

That's what I would solve first.

Then, in your current search I see that you only allow for one student having
only one grade. That might be okay, but is that as it should be?

Finally: although a binarySearchTree is mentioned, the following remark:
The nodes in the tree are sorted by name in alphabetical (dictionary) order.

That sentence looks like you are supposed to use an array or a list,
and perform a binary search on that array or list. You are creating a Tree structure.
What are your thoughts on this?

Greetz,
Piet
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!