Given a string str containing only lowercase characters. The problem is to print the characters along with their frequency in the order of their occurrence using Binary Tree
Input: str = “aaaabbnnccccz”
Input: str = “geeksforgeeks”
- Start with the first character in the string.
- Perform a level order insertion of the character in the Binary Tree
- Pick the next character:
- If the character has been seen and we encounter it during level order insertion increase the count of the node.
- If the character has not been seen so far, go to step number 2.
- Repeat the process for all the characters of the string.
- Print the level order traversal of the tree which should output the desired output.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- Print characters and their frequencies in order of occurrence
- Print characters having odd frequencies in order of occurrence
- Print characters having even frequencies in order of occurrence
- Print characters having prime frequencies in order of occurrence
- Print the Vowels in the Order of their occurrence in the given Matrix
- Print a Binary Tree in Vertical Order | Set 3 (Using Level Order Traversal)
- Minimize Cost to sort a String in Increasing Order of Frequencies of Characters
- Generate a Number in Decreasing order of Frequencies of characters of a given String
- Print nodes of a Binary Search Tree in Top Level Order and Reversed Bottom Level Order alternately
- Binary string with given frequencies of sums of consecutive pairs of characters
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Sum and Product of Prime Frequencies of Characters in a String
- Flatten Binary Tree in order of Level Order Traversal
- Flatten binary tree in order of post-order traversal
- Print number in ascending order which contains 1, 2 and 3 in their digits.
- Print Binary Tree levels in sorted order | Set 2 (Using set)
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Find the occurrence of the given binary pattern in the binary representation of the array elements
- XOR of Prime Frequencies of Characters in a String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Rajput-Ji