Skip to content

Greedy huffman#1562

Open
ryanzone wants to merge 2 commits intoTheAlgorithms:masterfrom
ryanzone:greedy_huffman
Open

Greedy huffman#1562
ryanzone wants to merge 2 commits intoTheAlgorithms:masterfrom
ryanzone:greedy_huffman

Conversation

@ryanzone
Copy link

Description of Change

Added a complete implementation of Huffman Coding (Greedy Algorithm) in C. The program constructs a Huffman Tree using a min-heap data structure to efficiently select the two nodes with the smallest frequencies at each step, following the greedy strategy for optimal prefix code generation. The implementation builds the tree dynamically, generates binary prefix codes for each character through traversal, and ensures that the resulting codes satisfy the prefix property. The code includes well-defined structures, heap operations (create, insert, extract-min, and heapify), tree construction logic, and example usage in main() to demonstrate correctness. Proper inline documentation and comments are added to improve readability and maintainability. The overall time complexity of the implementation is O(n log n) due to heap operations during tree construction, and the space complexity is O(n) for storing heap nodes and the Huffman tree.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant