TechArena Community Dictionary with a binary tree

#1
01-05-2009
 Member Join Date: Jan 2009 Posts: 150
Dictionary with a binary tree

I do not know too well the C programming language but I wanted to know if anyone can help me to set a dictionary with a binary tree.

I have a text file that contains all the words in the dictionary and I wanted to know if I can insert into a binary tree. I know that normally we should have a piece of code to start but then I have no idea how do I do.
#2
01-05-2009
 Member Join Date: May 2008 Posts: 685
Re: Dictionary with a binary tree

Read the file with the help of fopen + fgets + fclose, and insert the data into a binary tree which is nothing other than a special linked list. I hope that helps.
#3
01-05-2009
 Member Join Date: Jan 2009 Posts: 150
Re: Dictionary with a binary tree

But I do not know how to make the binary tree. Can you show me some way may be with the help of some sample code to make the binary tree?
#4
01-05-2009
 Member Join Date: May 2008 Posts: 685
Re: Dictionary with a binary tree

In computer science, a binary tree is a tree data structure in which each node has at most two children. Typically the child nodes are called left and right. A binary tree is a connected acyclic graph such that the degree of each vertex is no more than 3. It can be shown that in any binary tree, there are exactly two more nodes of degree one than there are of degree three, but there can be any number of nodes of degree two.With the root thus chosen, each vertex will have a uniquely defined parent, and up to two children.

Binary trees can be constructed from programming language primitives in several ways. Binary trees can also be stored as an implicit data structure in arrays, and if the tree is a complete binary tree, this method wastes no space.

Source: wikipedia

For the rest, I said: it's almost like a linked list.
#5
01-05-2009
 Member Join Date: Feb 2008 Posts: 194
Re: Dictionary with a binary tree

A binary tree is a tree-like structure that is rooted and in which each vertex has at most two children and each child of a vertex is designated as its left or right child

Because binary trees have log (base 2) n layers, the average search time for a binary tree is log (base 2) n. To fill an entire binary tree, sorted, takes roughly log (base 2) n * n. First, it is necessary to have a struct, or class, defined as a node. Simple example would be:

struct node
{
int key_value;
node *left;
node *right;
};

 Tags: