Question

I also don't quite understand the meaning of N.size, is N.size (the sum of nodes) (a node and its sub trees) has? please also explain that, thank you.modify the standard definition of a binary search tree to add a field N.size at each Suppose that we node, which records the

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A binary search tree is a binary tree (i.e. a finite set of data items which is either empty or consists of a single item called the root and two disjoint binary trees called the left sub-tree and right sub-tree)which is either empty or satisfies the following rules:

1) The value of left sub-tree is less than the value of root.

2) Value of right sub-tree is more than or equal to the values of root.

3) All the sub-trees of left and right sub-trees observe the two rules.

N.size is as same as given in second line of the image. Thus,here N.size record the size of sub-tree under N(including N)

A)Procedure / Algorithm of adding X element with both cases

  1. Struct record * insert(struct *tree, long digit, long N)repeat steps 2 to 14
  2. If (tree==NULL)step 3 to 6
  3. Tree =(struct record*)malloc(sizeof(struct record));
  4. Tree->left=tree->right=NULL
  5. Tree->num=digit;
  6. N++;
  7. Else step 7
  8. If(digit<tree->num)tree->left=insert(tree->left, digit,N)
  9. N=Nl++;
  10. Else step 9
  11. If(digit>tree->num)tree->right=insert(tree->right, digit,N)
  12. N=Nr++;
  13. Else step 11
  14. If(digit==tree->num)tree->right=insert(tree->right, digit, N)
  15. N=Nr++;
  16. //for duplicate nodes
  17. Exit (0);
  18. Return (tree);
  19. end

B) Procedure / Algorithm of deleting X element with both cases

  1. Struct record * delnum (int digit, struct record *r, long N)
  2. {
  3. struct record *
  4. If (r->!=NULL)del num(digit, r->right ,N)
  5. Else
  6. q->num=r->num;
  7. q=r;
  8. r= r->left;
  9. }
  10. Struct record * deletnode (int digit, struct record *tree, long N)
  11. {
  12. Struct recird *r,*q;
  13. If(tree==NULL)
  14. {
  15. Exit(0);
  16. }
  17. If(digit<tree->num)
  18. deletenode(digit,tree->left, N)
  19. N=Nl--;
  20. else
  21. If(digit>tree->num)
  22. deletenode(digit,tree->right, N)
  23. N=Nr--;
  24. q=NULL;
  25. else
  26. if(q->right==NULL)tree=q->left;
  27. else
  28. if(q->left==NULL)tree=tree=q->right;
  29. else
  30. delnum(digit, q->left,N)
  31. free(q);
  32. end

C) Procedure / Algorithm for finding kth element

for search

  1. void search(struct record *tree, long digit,int N)steps 2 to 9
  2. if(tree==NULL)step 3
  3. puts(“no number”);
  4. else if(digit==tree->num)step 5
  5. printf(“%d”,digit);
  6. else if(digit<tree->num)step 7
  7. search(tree->left, digit,N);
  8. else search(tree->left, digit,N);
  9. end

D) For finding number less than X

For this, same procedure will be applied like as in C.procedure,but only left of tree function will be called for search.

Add a comment
Know the answer?
Add Answer to:
I also don't quite understand the meaning of N.size, is N.size (the sum of nodes) (a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • just explain it in english would be enough. modify the standard definition of a binary search...

    just explain it in english would be enough. modify the standard definition of a binary search tree to add a field N.size at each Suppose that we node, which records the size of the subtree under N'Tincluding N itself). A. Explain how to modify the procedure for adding both the case where X is not yet in the tree and is added, and the case where X is already in the tree, and the tree remains unchanged. element X to...

  • 1. [10 pts.] AVL Trees: Example Operations (a) [5 pts.] Draw the AVL tree that results...

    1. [10 pts.] AVL Trees: Example Operations (a) [5 pts.] Draw the AVL tree that results from inserting key 45 into the following AVL tree. (b) [5 pts.] Draw the AVL tree that results from deleting key 70 from the following AVL tree. NOTE: When deleting a key from an AVL tree, please follow the textbook approach of finding the node with the key using the function for standard binary search trees. If the key is in the tree and...

  • Overview The purpose of this assignment is to practice functional programming in the Racket Programming Language...

    Overview The purpose of this assignment is to practice functional programming in the Racket Programming Language and to also reinforce the notion of the list as a universal data structure, by implementing various operations on binary search trees. Specification A binary search tree is a binary tree which satisfies the following invariant property: for any node X, every node in X's left subtree has a value smaller than that of X, and every node in X's right subtree has a...

  • Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elem...

    Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elements. In this problem, you will show how to transform Ti into T2 (i.e. Ti is altered to now have the same structure as T2) through a series of rotation operations. (a) Define a binary tree to be a right-going chain if no node in the tree has a left child (in other words, the tree is a linked list formed through...

  • The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition...

    The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition and post-condition. Please use these question to solve problem 8,the last photo. 2-3 Trees: Definition Suppose that E is an ordered type, that is, a nonempty set of values that have a total order. A 2-3-tree, for type E, is a finite rooted tree T (like a binary search tree or a red-black tree) that satisfies the following 2-3 Tree Properties: (a) Every leaf...

  • Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that...

    Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func)     (cond ((null? input-list) '())           ((func (car input-list))            (cons (car input-list) (filter (cdr input-list) func)))           (else            (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...

  • Attention!!!!!!! I need python method!!!!!!!!! the part which need to edit is below: i nee...

    attention!!!!!!! I need python method!!!!!!!!! the part which need to edit is below: i need python one!!!!!!!!! the part below is interface for the range search tree which don’t need to modify it. Week 3: Working with a BST TODO: Implement a Binary Search Tree (Class Name: RangesizeTree) Choose one language fromJava or Python. Iin both languages,there is an empty main function in the Range Size Tree file. The main function is not tested, however, it is provided for you...

  • I need help with this code, I'm stuck on it, please remember step 4, I'm very...

    I need help with this code, I'm stuck on it, please remember step 4, I'm very much stuck on that part. It says something about putting how many times it appears Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...

  • (1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an...

    (1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an integer between 1 and n. (2) Suppose Algorithm-1 does f(n) = n**2 + 4n steps in the worst case, and Algorithm-2 does g(n) = 29n + 3 steps in the worst case, for inputs of size n. For what input sizes is Algorithm-1 faster than Algorithm-2 (in the worst case)? (3) Prove or disprove: SUM{i**2} [where i changes from i=1 to i=n] ϵ tetha(n**2)....

  • SECTION B (4 QUESTIONS, 90 MARKS) Question 4. [32 marks in total] For this question, assume the definition of Java clas...

    SECTION B (4 QUESTIONS, 90 MARKS) Question 4. [32 marks in total] For this question, assume the definition of Java class Heap given in the Appendix. The heaps referred to in this question are all maxHeaps. a. (5 marks) Insert into an empty (binary) heap the values 35, 4, 72, 36, 49, 50. Draw all intermediate steps b. (3 marks) Carry out one deletion operation on the final heap in (a.) above. c. (2 marks) Give the worst-case time complexity...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT