2

I'm studying AVL trees for a large homework I have, 2 of the functions that need to be implemented are the successor and predecessor

I've looked around on the internet and only found how to implement code to find the two, not why or when it can be used, not enough.

Duplicates are not allowed in the tree, the tree is a standard AVL tree implementation with rotate functions, insert and delete functions, the keys are int.

I recall once my tutor told me that you ''keep copying'' predecessors or successors successively until you reach a leaf node to help with node deletion is this true, or something similar like this?

I don't know which part of the file(s) to show for this question, it's a big one and It's not really a question about a specific code.

Rami Raghfan
  • 151
  • 12
  • 1
    We need more details about the problem, preferably including some code. – QuestionC Apr 19 '19 at 15:49
  • Nominally, if there are no duplicate entries in your tree, you could use `successor` and `predecessor` to find the value after or before a given other value. If the node structures are exposed (visible to users of the tree code), then you could find the node that comes before or after a given node. If you work by values and there are duplicates in the tree, you can't unambiguously find the node before or after a value with duplicates; you can't tell which of the duplicate values you were given. Sadly, you've not shown or described how the functions identify what they're looking for. ([MCVE]) – Jonathan Leffler Apr 19 '19 at 16:00
  • I believe it requires no code example, its a question of concept. **what do you use the functions that finds the aforementioned for?** – Rami Raghfan Apr 19 '19 at 16:24
  • 1
    You don't have a programming problem, you have a problem with how your homework is written. We would have to be in your class to answer the question. – QuestionC Apr 19 '19 at 16:49
  • I see you've updated the question a bit. I mentioned two ways the `successor` and `predecessor` could be used — using some sort of `avl_node *` to identify the current node, or using the value stored in the node. Are you storing integers, strings, student records, or what in the tree? You could use the functions to traverse all the nodes in a tree. It isn't 100% clear how you'd navigate from rightmost leaf node in the left subtree of the root to the leftmost node in the right subtree of the root. – Jonathan Leffler Apr 19 '19 at 17:11
  • You could use the `successor` and `predecessor` functions to traverse all the nodes in a tree somehow. It's unlikely they'd be used in the tree rotation code, but you could perhaps devise a way to use them for the task. Without more information, I (for one) cannot help you further. – Jonathan Leffler Apr 19 '19 at 17:12

0 Answers0