$ show krahets/hello-algo
This repository is a comprehensive, open-source textbook for data structures and algorithms, known as 'Hello Algo'. It provides implementations of over 200 classic algorithms across 12 programming languages (Python, Java, C++, Go, Rust, etc.) and multiple human languages (Chinese, English, Japanese, Russian). The code is organized into chapters covering complexity analysis, arrays, linked lists, stacks, queues, hashing, trees, heaps, graphs, sorting, searching, divide-and-conquer, backtracking, dynamic programming, and greedy algorithms. Each algorithm is presented as a self-contained, runnable example with driver code and inline comments explaining the logic. The repository is not a production application but a pedagogical reference, making it valuable for students, educators, and self-learners. While the code is well-structured and consistent across languages, its high duplication across languages and translations means it is not designed for production reuse. However, the utility modules for tree/linked list construction and printing are cleanly isolated and can be extracted for other projects.
The LLM identified 4 files worth highlighting for reuse:
Provides `list_to_tree` and `tree_to_list` functions to convert between Python lists and binary tree structures, along with a `TreeNode` class. This utility is self-contained, reusable in any Python project needing binary tree deserialization from array representations, and is used across all tree-related chapters.
Implements `ListNode` structure with constructor and helper functions like `GetListNode` to retrieve a node by index and `arrToLinkedList` to build a linked list from a slice. This utility is reusable for any Go project requiring linked list construction and manipulation, decoupled from algorithmic logic.
Contains overloaded print functions for vectors, matrices, trees, heaps, and hash tables. It is a clean, header-only utility that can be dropped into any C++ project for debugging output, with no dependencies beyond standard libraries.
Implements binary search to find the insertion point of a target in a sorted array. This function is reused by `binary_search_edge.js` for finding left/rightmost occurrences. It demonstrates a clean, generic binary search variant that can be extracted for any JavaScript project needing sorted array insertion logic.