Reorganizing a category hierarchy

An online retailer stores its product categories in a rooted tree, with Catalogue as the root. A leaf is a category with no children. A category's depth is the number of parent–child connections on the path from Catalogue to that category.


A catalogue hierarchy branches from Catalogue into Electronics and Home, with further category branches beneath each.


Apply these two changes in order:

  1. Move Audio and all its descendants from Electronics to Kitchen, making Audio an immediate child of Kitchen.
  2. Delete Cameras. Retain every other category, including any category that now has no children.

For the resulting tree, give the number of descendants of Home, excluding Home itself; the total number of leaf categories, including any newly created leaves; and the depth of Speakers. Enter each as an exact integer. Descendants include children and every category farther down their branches.


Finally, consider a proposed additional move of Home and its entire subtree beneath Headphones. Enter true if this proposed move would preserve a valid rooted tree, or false otherwise. Evaluate this proposal without applying it to your other answers.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Data Structures Questions: