VOOZH about

URL: https://www.geeksforgeeks.org/dsa/longest-word-ternary-search-tree/

⇱ Longest word in ternary search tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Longest word in ternary search tree

Last Updated : 17 Mar, 2023

Given a set of words represented in a ternary search tree, find the length of largest word among them.

Examples: 

Input : {"Prakriti", "Raghav", 
 "Rashi", "Sunidhi"}
Output : Length of largest word in 
 ternary search tree is: 8

Input : {"Boats", "Boat", "But", "Best"}
Output : Length of largest word in 
 ternary search tree is: 5

Prerequisite : Ternary Search Tree
The idea is to recursively search the max of left subtree, right subtree and equal tree. 
If the current character is same as the root's character increment with 1. 

Implementation:


Output
Length of largest word in ternary search tree is: 8
Comment
Article Tags: