Tag: Algorithms

  • 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…

  • 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…

  • 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…

  • Algorithms 101: `>>` vs `>>>`

    In Python, understanding the difference between the >> operator and the non-existent >>> operator is crucial for correct bitwise operations and shifts. This section will explain how these operators work, clarify the distinction, and illustrate their use cases. 在 Python 中,理解 >> 操作符和不存在的 >>> 操作符之间的区别对于正确执行位操作和移位至关重要。本节将解释这些操作符的工作原理,澄清它们的区别,并举例说明它们的使用场景。 1. What is the >>…

  • Algorithms 101: |` vs `||` and `&` vs `&&`

    | vs || and & vs && Understanding the difference between bitwise operators (|, &) and logical operators (||, &&) is essential for writing efficient and bug-free code in Python. This section will break down how these operators work, their use cases, and when to use each type. 理解位操作符 (|,…