Q BgQuestion:

Rookie
Karma Points: 0
Respect (44%):
posted by  badshah on 5/18/2008 5:32:57 AM  |  status: Live  

Solve it plz.. Subject "DATA STRUCTURE". FOr "LISFE SAVER" Poonts

Course Textbook Chapter Problem
N/A Subject "DATA STRUCTURE". N/A N/A
Question Details:

 

Queston:-

? Making students able to understand basic concepts relating to Binary Search Tree

(BST).

 

? Making students able to implement Binary Search Tree practically using c++.

Assignment:

 

? Add the integer part of your roll no in this tree and show the contents of this tree after insertion by traversing it (using preorder, inorder and post order traversal)

 

? Delete some digits from added digits of your id and show the contents of tree

again using pre, in and post order traversals.

Important Note:

? Note that as your id will have some duplicate digits for example more than one

zeros, they will be added only once when you will insert them again the message

will appear that attempt to insert duplicate value.

 

AAnswers:

Answer Question
Expert
Karma Points: 909
posted by smart_IT on 5/18/2008 9:25:22 AM  |  status: Live
Asker's Rating: Lifesaver   
badshah's comment:
"Thanks Dear ..solve other question i will award you more marks.bye"
Response Details:
For Implementation of BST:

 

<!--[if !supportLists]-->Ø      <!--[endif]-->float avg(BinaryNode * rootNode)

      int BinarySearchTree::avg(BinaryNode * rootNode)

     {

        int avg=0,i=0;

        Stack<BinaryNode* > stack;

       BinaryNode* p;

       p = root;

       do

      {

        while( p != NULL )

        {

            stack.push( p );

            p = p->left;

        }

        // at this point, left tree is empty

             if( !stack.isEmpty() )

             {

            p = stack.pop();

            avg=avg+p->number;

           p = p->right;

             }

             i++;

    } while ( !stack.isEmpty() || p != NULL );

    return avg/i;

}

 

<!--[if !supportLists]-->Ø      <!--[endif]-->int depth(BinaryNode * rootNode)

      int BinarySearchTree::depth(BinaryNode *rootNode) {

    

      int leftHeight, rightHeight;

 

      if (rootNode == NULL) {

         return -1;

      }

      leftHeight = height(rootNode->left);

      rightHeight = height(rootNode->right);

      if (leftHeight > rightHeight) {

          return leftHeight+1;

      } else {

          return rightHeight+1;

    }

}

 

//  The depth/height of binary tree

<!--[if !supportLists]-->Ø      <!--[endif]-->bool completeTree(BinaryNode * rootNode) 

//Code to determine if a binary tree is strictly or complete binary tree.

            bool BinarySearchTree::completeTree(BinaryNode * rootNode)

           {    

    

                Stack<BinaryNode* > stack;

                BinaryNode* p;

                p = root;

                bool balance;

                do

               {

                  while( p != NULL )

                  {

                     stack.push( p );

                     if(p->left!=NULL && p->right!=NULL || p->left==NULL && p->right==NULL)

                     balance = true;

                     else return false;

                        p = p->left;

        }

    

     if( !stack.isEmpty() )

             {

            p = stack.pop();

            p = p->right;

             }

            } while ( !stack.isEmpty() || p != NULL );

}

If you post one question/problem, I will provide 1 input/answer. If you put "x" questions/problems, I will provide"x" inputs/answers.  In both cases, appropriate ratings are appreciated for every input. Thanks.
Answer Question
Ask New Question

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different than tutoring »