Twisuki's Blog and Notes

website·Indexed 31 days ago

https://blog.twis.uk/

A personal blog and knowledge base featuring technical notes on C programming, Node.js, React, and data structures, alongside academic studies on mathematics (Markov chains, random variables) and Modern Control Theory.

Tokens
23.2K
Snippets
90
Records
139
Agent score
52%

What's inside Twisuki Blog

  1. Overview of Hybrid Sorting Algorithms

    Hybrid sorting algorithms combine multiple sorting techniques to optimize performance based on data size or state:

    • Introsort: Combines Quick Sort, Heap Sort, and Insertion Sort. It uses Insertion Sort for small data, Quick Sort for large data, and switches to Heap Sort if the recursion depth exceeds a limit.
    • Timsort: A hybrid of Merge Sort and Insertion Sort.
    • Blocksort: A hybrid of Merge Sort and Insertion Sort that utilizes block operations to handle large datasets by sorting small blocks first and then merging them.
  2. Understand Discrete and Continuous Random Variables

    A random variable $X$ assigns a unique real number to every sample point in a sample space $\Omega$.

    • Discrete Random Variables: Take on a finite or countable set of fixed values (e.g., the result of a dice roll $X \in {1, 2, 3, 4, 5, 6}$). Probabilities for specific values $P(X=x)$ can be calculated directly.
    • Continuous Random Variables: Take on any value within a continuous range (e.g., any real number in $[0, 1)$). The probability of the variable taking any exact single value $a$ is $0$ ($P(X=a) = 0$), meaning a probability of 0 does not imply the event is impossible.
  3. Understand C pointer basics and arithmetic

    A pointer is a special variable that stores a memory address. The type of the pointer determines the size of the memory block it points to. For example, an int * points to a 4-byte region. Incrementing a pointer (p++) moves it forward in memory by the size of its underlying type (e.g., 4 bytes for int, 1 byte for char).
    int a = 10;
    int *pa = &a; // pa now points to the memory address of a
    printf("%d", *pa); // Accesses the value at the address (outputs 10)
  4. Understand the vuepress-theme-hope project structure

    The project is organized into a src directory for content and a .vuepress directory for configuration.

    Content Directory (src/):

    • README.md: The entry point of the website (equivalent to index.html).
    • .md files: Each Markdown file corresponds to a page. Files in the root of src are accessible at the root URL (e.g., https://site.com/page.html).
    • Subfolders (e.g., demo/, posts/): Files within subfolders create nested URLs (e.g., src/demo/README.md maps to https://site.com/demo/).

    .vuepress Directory:

    • public/: Stores static assets. Files here can be referenced directly in Markdown (e.g., public/image/icon.png is referenced as image/icon.png).
    • styles/: Contains custom SCSS files (index.scss, config.scss) for styling overrides.
  5. Understand the mechanical operation of the Enigma machine

    The Enigma machine is a cipher device that uses a combination of a plugboard, rotors, and a reflector to encrypt text.

    Key Properties:

    • Reversibility: If the machine is set to the same initial rotor positions, the encryption and decryption processes are identical. Inputting the ciphertext produces the original plaintext.
    • Self-Exclusion (Non-reflexivity): A letter can never be encrypted as itself (e.g., pressing 'A' will never light up 'A').

    Signal Path:

    1. Plugboard: Initial swap of characters.
    2. Rotor Group: The signal passes through three rotors (R1 → R2 → R3), each performing a substitution based on its current rotation.
    3. Reflector: The signal hits a reflector, which swaps the character and sends it back through the rotors in reverse order (R3 → R2 → R1).
    4. Plugboard: A final swap before the corresponding lamp lights up.
    5. Rotation: After each key press, the rotors rotate, changing the substitution mapping for the next character.
  6. Understand the core principles of recursive algorithms

    Recursion in algorithms is not strictly a mathematical concept, but a method of solving problems. A problem can be solved using recursion if it meets two critical conditions:

    1. The problem can be decomposed into a smaller scale of the same problem.
    2. A problem of a finite (base) scale can be solved directly.
  7. Define n-th order Markov Models

    A process where the transition to the next state depends only on the previous $n$ states is called an $n$-th order Markov model. A first-order process (the simplest form) is one where the current state $P(n)$ is determined solely by the immediately preceding state $P(n-1)$.
  8. Manage interactive UI using the UI = f(state) principle

    React uses a declarative programming model where the UI is a function of the state: UI = f(state). Instead of manually manipulating the DOM, developers update the state, and React automatically re-renders the UI to reflect those changes.
    function Comp() {
      // Define state
      const [count, setCount] = useState(0)
      
      // Update state
      const handleClick = () => setCount(count + 1)
    
      return (
        <div>
          <span>count is {count}</span>
          <button onClick={handleClick}>Click me!</button>
        </div>
      )
    }
  9. Add summaries and tables of contents to pages

    In vuepress-theme-hope, you can control how content is displayed on the homepage and within the page:

    • Summaries: Place <!-- more --> in the body. Content above this tag is treated as the summary for the homepage list. If omitted, the first few lines are used automatically.
    • Page TOC: Use [[toc]] to generate a table of contents for the current page.
    • Folder TOC: Use <Catalog /> to generate a directory list (typically used in README.md files).
    # My Article
    This text will appear as the summary on the home page.
    
    <!-- more -->
    
    This text is the main body of the article.
    
    [[toc]]
  10. Enable LaTeX mathematical formulas in vuepress-theme-hope

    To support LaTeX formulas, install a math rendering library like katex and enable it in the theme configuration within .vuepress/config.ts.
    pnpm add -D katex
    import { defineUserConfig } from "vuepress"
    import { hopeTheme } from "vuepress-theme-hope"
    
    export default defineUserConfig({
      theme: hopeTheme({
        markdown: {
          math: {
            type: "katex", // or 'mathjax'
          },
        },
      }),
    })
    
  11. Solve linear time-invariant (LTI) state equations

    For a linear time-invariant system $\dot{x}(t) = Ax(t)$, the free solution (zero-input response) is: $x(t) = e^{A(t - t_0)}x(t_0)$

    If the initial time $t_0 = 0$, the solution simplifies to: $x(t) = e^{At}x_0$

    The matrix exponential $e^{At}$ is defined by the power series: $e^{At} = I + At + \frac{1}{2!}A^2t^2 + \cdots + \frac{1}{k!}A^kt^k + \cdots$

  12. Read and parse whitespace-separated data files in Python

    To import a dataset from a text file where values are separated by whitespace, open the file and iterate through each line, splitting the string and converting the resulting elements to floats.
    data = []
    with open("data.txt", 'r') as f:
        for l in f:
            # Split by whitespace and convert to float
            line = [float(_) for _ in l.split()]
            data.append(line)