Skip to content

Searching: linear and binary · ⁨查找:线性查找与二分查找⁩

English

Finding a value

  • A common job is to search: is a value in an array, and where?
  • The usual answer is the index where we found it, or -1 if it is not there.
  • We learn two ways: linear search (works on any array) and binary search (needs a sorted array, but is much faster).
中文

查找一个值

  • 一个常见的工作是查找(search):某个值在不在数组里,以及在哪里?
  • 通常的答案是我们找到它的那个下标(index),或者如果不在就返回 -1。
  • 我们学习两种方法:线性查找(linear search,适用于任何数组)和二分查找(binary search,需要已排序的数组,但快得多)。

Handout

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩