Skip to content

Latest commit

 

History

History
139 lines (106 loc) · 15.5 KB

README_en.md

File metadata and controls

139 lines (106 loc) · 15.5 KB

Understanding Algorithms and Data Structures, Learning Different Programming Languages 中文

Learn data structures and algorithms based on different programming languages, including C, Java, Python, JavaScript, Go, TypeScript, etc., with ample comments and explanations.

Project Features:

  1. Covers a variety of algorithms such as numerical calculations, string search, tree traversal, sorting, dynamic programming, etc.
  2. Each algorithm is implemented in multiple languages to help understand the features of different programming languages.
  3. Examples are carefully designed for students or programmers to learn and analyze, improving programming skills.

Overview of Algorithms

What are common algorithms?

  • Text Search: Includes linear search, binary search, tree search, longest common subsequence, palindrome computation, etc., mainly for string searching.
  • Mathematical Computations: Includes base conversion, square roots, Fibonacci sequence, prime factorization, Pascal’s triangle, etc., mainly for numerical calculations.
  • Sorting Algorithms: Includes bubble, selection, insertion, shell, merge, quick, heap, counting, bucket, radix, etc., for ordering data.
  • Other Algorithms: Includes dynamic programming, greedy algorithms, divide and conquer, backtracking, graph algorithms (e.g., breadth-first search, depth-first search, Dijkstra’s algorithm, Kruskal’s algorithm, etc.), and machine learning and artificial intelligence algorithms such as classification, clustering, deep learning, reinforcement learning, etc.

Algorithm Overview

Common Algorithm Ideas

  • Greedy Algorithm: A method that expects to find the global optimum by selecting the local optimum at each step.
  • Divide and Conquer: Breaks a problem into smaller subproblems, solves them independently, and then combines the results.
  • Dynamic Programming: Solves complex problems by breaking them down into simpler overlapping subproblems.
  • Backtracking: Solves problems by incrementally building candidate solutions and abandoning those that fail to meet the criteria.
  • Graph Algorithms: Includes breadth-first search, depth-first search, Dijkstra’s algorithm, Kruskal’s algorithm, etc., for solving graph-related problems.
  • Branch and Bound: A method for solving combinatorial optimization problems by systematically exploring the branches of the search tree.

For detailed information, see: 10 Classic Algorithm Ideas

10 Classic Sorting Algorithms

Sorting Algorithm C JavaScript Python Java TypeScript Go Time Complexity (Average/Worst) Space Complexity Stability Suitable Scenarios
Bubble Sort C JS Python Java TS Go O(n²) / O(n²) O(1) Suitable for small-scale data sorting, educational purposes
Insertion Sort C JS Python Java TS Go O(n²) / O(n²) O(1) Suitable for small-scale data or nearly sorted elements
Selection Sort C JS Python Java TS Go O(n²) / O(n²) O(1) Suitable for small-scale data with fewer swaps
Heap Sort C JS Python Java TS Go O(n log n) / O(n log n) O(1) Suitable for priority queues, TOP K problems
Quick Sort C JS Python Java TS Go O(n log n) / O(n²) O(log n) Suitable for general sorting scenarios, efficient but unstable
Merge Sort C JS Python Java TS Go O(n log n) / O(n log n) O(n) Suitable for large-scale data sorting, external sorting
Counting Sort C JS Python Java TS Go O(n + k) / O(n + k) O(k) Suitable for sorting integers with limited range
Radix Sort C JS Python Java TS Go O(nk) / O(nk) O(n + k) Suitable for large-scale integer sorting, such as ID numbers, phone numbers
Bucket Sort C JS Python Java TS Go O(n + k) / O(n²) O(n + k) Suitable for uniformly distributed data range
Shell Sort C JS Python Java TS Go O(n log n) / O(n²) O(1) Suitable for medium-scale data sorting, semi-ordered data

String Search and Lookup

Algorithm C Language Go Language JS Version Python Version Java Version TypeScript Version Time Complexity (Average/Worst) Space Complexity Suitable Scenarios
Naive Search C Go JS Python Java TS O(mn) / O(mn) O(1) Suitable for small-scale text search
Binary Search C Go JS Python Java TS O(log n) / O(log n) O(1) Suitable for searching in sorted arrays
KMP Search C Go JS Python Java TS O(n + m) / O(n + m) O(m) Suitable for large-scale text search

Tree Search and Traversal

Algorithm C Language JS Version Python Version Java Version TypeScript Version Time Complexity (Average/Worst) Space Complexity Suitable Scenarios
Binary Tree Traversal C JS Python Java TS O(n) / O(n) O(n) Suitable for tree structure data traversal, such as XML parsing, file system traversal

Prime Factorization

Language Code Link Complexity Suitable Scenarios
C factor.c O(√n) For calculating prime factorization of large integers
C++ factor.cpp O(√n) Suitable for efficient mathematical calculations
JavaScript factor.js O(√n) For number theory calculations on the web
TypeScript PrimeFactor.ts O(√n) Suitable for front-end or Node.js calculations
Go factor.go O(√n) Suitable for backend service calculations
Python factor.py O(√n) Suitable for scientific computations and data analysis
Java Factor.java O(√n) Suitable for enterprise-level application calculations
Kotlin factor.kt O(√n) Suitable for Android and backend calculations
Dart factor.dart O(√n) Suitable for Flutter applications
Swift factor.swift O(√n) Suitable for iOS/macOS development
Objective-C factor.m O(√n) Suitable for older versions of iOS/macOS
Rust factor.rs O(√n) Suitable for high-performance computing

Removing Duplicate Items from Arrays and Lists

Language Code Link Time Complexity Suitable Scenarios
C unique.c O(n log n) Suitable for embedded development
Go unique.go O(n log n) Suitable for high-concurrency scenarios
JS unique.js O(n) Suitable for front-end data processing
Python unique.py O(n) Suitable for data cleaning and analysis
Java UniqueArray.java O(n log n) Suitable for enterprise-level applications
TypeScript UniqueArray.ts O(n) Suitable for front-end TypeScript projects
Dart unique.dart O(n) Suitable for Flutter applications
Rust unique.rs O(n) Suitable for high-performance computing

Recursion

Algorithm Code Link Time Complexity Space Complexity Suitable Scenarios
Simple Recursion C O(2^n) O(n) Suitable for divide-and-conquer algorithms, tree and graph traversal, backtracking problems

Mathematical Computation

Algorithm Code Link Time Complexity Space Complexity Suitable Scenarios
Mathematical Computation C O(n) O(1) Suitable for number theory, addition, multiplication, large integer computations, etc.

Date and Calendar

Algorithm Code Link Time Complexity Space Complexity Suitable Scenarios
Date and Calendar C O(1) O(1) Suitable for date calculations, holiday predictions, date conversions, etc.

Data Structures

Data structures refer to the ways data is organized and stored, aggregating data together for processing and organization. Different data structures have different efficiency for access, insertion, deletion, etc. By selecting the appropriate data structure, data can be processed efficiently. See also: Overview of Data Structures

Data Structure Description Structural Features Access Efficiency Insertion/Deletion Efficiency
Array A collection of elements of the same data type, supports random access by index Continuous memory storage, supports linear or non-linear O(1) O(n)
Linked List Data stored in a chain structure, connected by pointers, including singly linked list, doubly linked list, and circular linked list Linear structure, non-contiguous memory O(n) O(1) (head) / O(n) (middle)
Tree A tree-like data structure, nodes are organized in hierarchical relationships, common types include binary tree, binary search tree, balanced tree, etc. Non-linear structure, one root node, unlimited number of child nodes O(log n) O(log n)
Heap A special type of complete binary tree that satisfies the heap property (max-heap or min-heap), often used in priority queues Non-linear structure, supports efficient operations on extreme values O(1) (extract top) O(log n)
Stack A Last-In-First-Out (LIFO) collection of data Linear structure, sequential or chain storage, only operations at the top of the stack O(1) O(1)
Queue A First-In-First-Out (FIFO) collection of data Linear structure, sequential or chain storage, supports insertion at the rear and deletion at the front O(1) O(1)
Graph A data structure consisting of nodes (vertices) and edges, common storage methods include adjacency lists and adjacency matrices Non-linear structure, nodes can be connected many-to-many O(1) (adjacency matrix) / O(n) (adjacency list) O(1) (adjacency matrix) / O(n) (adjacency list)
Hash A data structure that maps keys to storage locations using hash functions, supporting fast lookups, insertions, and deletions Linear structure, key-value mapping O(1) (amortized) O(1) (amortized)
Struct Combines multiple types of data into a whole, often used to represent complex objects Custom structure, fields fixed, containing various data types O(1) O(1)

Related Links

Join Us in Co-Building

Link to this document

If you're interested in this project, please add me. I welcome you to build it together!

WeChat: springbuild

Email: [email protected] or [email protected]