Author: admin

  • Algorithms 101: InOrder Traversal

    中序遍历 InOrder traversal is a tree traversal method where the nodes are visited in ascending order. It is one of the depth-first search (DFS) methods used to explore all the nodes in a tree. In InOrder traversal, the process is to recursively visit the left subtree first, then visit the…

  • Algorithms 101: PreOrder Traversal

    先序遍历 PreOrder traversal is a tree traversal method where the root node is visited before its children. It is one of the depth-first search (DFS) methods used to explore all the nodes in a tree. In PreOrder traversal, the process is to visit the root node first, then recursively visit…

  • LeetCode: 20 Valid Parentheses

    Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Example: Input:…

  • Algorithms 101: Why Should You Use a Dummy Node

    为什么要使用哑节点? English: Using a dummy node is a common technique in linked list problems. It involves creating an extra node that is placed before the head of the linked list. Chinese: 使用哑节点是链表问题中常见的技巧。它涉及在链表头节点之前创建一个额外的节点。 English: This dummy node doesn’t hold any useful data for the problem but serves as a useful placeholder…

  • LeetCode: 19 Remove Nth Node From End of linked list

    Given the head of a linked list, remove the nth node from the end of the list and return its head. Example: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Explanation: The second node from the end is 4, so we remove it and link 3 to 5. Example:…

  • Algorithms 101: Stable vs Unstable Sorting in Python

    When sorting algorithms are discussed, one important characteristic to consider is whether they are stable or unstable. This distinction can have significant implications, especially when dealing with data that contains equal elements where the relative order matters. 1. What is a Stable Sort? [English] A stable sort is a sorting…

  • Algorithms 101: Is Selection Sort Stable

    选择排序是稳定的吗? Understanding Stability in Sorting Algorithms 理解排序算法中的稳定性 In the context of sorting algorithms, stability refers to whether the algorithm preserves the relative order of records with equal keys (i.e., if two elements are equal, they should appear in the same order in the sorted output as they do in the…

  • Algorithms 101: Insertion Sort

    插入排序 (Insertion Sort) 插入排序是一种简单且高效的排序算法,适用于小规模数据集。其核心思想是在已排序部分中,从右到左找到合适的位置插入新来的元素,使已排序部分依然有序。这个过程重复进行,直到整个数组排序完成。 Insertion Sort is a simple and efficient sorting algorithm, especially for small datasets. The key idea is to insert each new element into its correct position within the already sorted portion by sliding it from right to left until it finds its place. This process is…

  • Algorithms 101: Selection Sort

    选择排序 (Selection Sort) 选择排序是一种简单直观的排序算法。它的基本思想是在未排序部分中选择最小(或最大)的元素,并将其放在已排序部分的末尾。这个过程持续进行,直到整个数组都被排序。下面将详细介绍选择排序的工作原理、代码实现以及时间复杂度。 Selection Sort is a simple and intuitive sorting algorithm. The basic idea is to repeatedly find the minimum (or maximum) element from the unsorted portion and move it to the end of the sorted portion. This process continues until the entire array is sorted. Below, we’ll…

  • Algorithms 101: Bubble Sort

    冒泡排序 (Bubble Sort) 冒泡排序是一种简单的排序算法,它通过反复比较相邻元素并交换它们的位置,将较大的元素“滚”到数组的末尾。这个过程重复进行,直到整个数组排序完成。每一轮比较后,最大的元素会“冒泡”到当前未排序部分的最后一个位置。 Bubble Sort is a simple sorting algorithm that repeatedly compares adjacent elements and swaps them if they are in the wrong order. This causes the larger elements to "bubble" to the end of the array. The process is repeated until the entire array is sorted. After…