Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5646 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4716 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@skj7 | 671 |

@gurshehzadsingh | 418 |

@swastik8750 | 411 |

@nishunishuraj18 | 405 |

@vedantvalsangkar | 390 |

@deepakchowdary | 380 |

@akashverma4 | 369 |

@satyamannsm | 353 |

@2018uec1603 | 333 |

@rkrupeshkumar345 | 331 |

@surajmamgai | 330 |

Complete Leaderboard |

Given a encoded binary string and a Huffman MinHeap tree, your task is to complete the function decodeHuffmanData(), which decodes the binary encoded string and return the original string.

**Note:** Each node of the min heap contains 2 data members, a character and an integer to denote its frequency. The character '$' is the special character used for internal nodes whose min heap node only need a integer field.

**Example 1:**

Input :binaryString = 0000000000001100101010101011111111010101010 Min Heap Tree = $(20) / \ / \ $(8) \ / \ \ $(3) \ $(12) / \ \ / \ B(1) D(2) E(5) C(6) A(6)Output:AAAAAABCCCCCCDDEEEEEExplanation:The following chart can be made from the given min heap tree.character frequency codeA 6 00 B 1 110 C 6 01 D 2 111 E 5 10

**Example 2:**

Input :binaryString = 01110100011111000101101011101000111 Min Heap Tree = $(13) / \ / \ / \ $(5) \ / \ \ / \ \ $(3) \ $(8) / \ \ / \ $(2) \ \ $(4) \ / \ \ \ / \ \ f(1) o(1) r(1) g(2) k(2) s(2) e(4)Output:geeksforgeeksExplanation:The following chart can be made from the given min heap tree.character frequency codef 1 0000 o 1 0001 r 1 001 g 2 01 k 2 100 s 2 101 e 4 11

**Your Task: **

You dont need to read input or print anything. Complete the function **decodeHuffmanData()** which takes the root of the Huffman min heap tree and the encoded Binary String as input parameters and returns the decoded string.

**Expected Time Complexity:** O(N log N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 ≤ N ≤ 10^3

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Huffman Decoding

...