170k views
2 votes
Consider the binary search tree constructed for the words oenology, phrenology, campanology, ornithology, ichthyology, limnology, alchemy, and astrology using alphabetical order. Find the number of comparisons needed to locate or to add each of the following words in the search tree, starting fresh each time:

a. palmistry
b. etymology
c. paleontology
d. glaciology

User Aregnier
by
4.6k points

2 Answers

0 votes

Final answer:

To find or add words 'palmistry', 'etymology', 'paleontology', and 'glaciology' to a binary search tree, one must compare them to nodes following alphabetical order, and the number of comparisons will vary based on the tree's structure at that moment.

Step-by-step explanation:

The question pertains to determining the number of comparisons needed to locate or add specific words in a binary search tree (BST) that is constructed by inserting words in alphabetical order. Assuming each comparison counts towards the total number of comparisons, and each of the given words is inserted starting from a fresh tree, we shall analyze each case:

Palmistry: To locate or add 'palmistry,' we would compare it to the root and proceed to the appropriate child nodes based on alphabetical order until the appropriate location is found or until it is determined the word is not in the tree.

Etymology: Similarly, adding 'etymology' would require comparisons starting from the root, moving along the tree based on the alphabetical ordering.

Paleontology: This would follow the same process as the previous words, locating the position in the binary search tree where 'paleontology' would be inserted.

Glaciology: Lastly, 'glaciology' would be compared against the nodes in the tree following the BST rules until its position is found or until it's added if not present.

The exact number of comparisons for each word would depend on the current structure of the BST at the time of each insertion/search.

User Calebe Oliveira
by
4.0k points
2 votes

Step-by-step explanation:

Binary Search Tree is also called ordered tree or sorted binary tree. In the tree each node contains smaller values in the left side of the subtree and larger values in the right side of the subtree.

User AbdulG
by
4.6k points