1. binary search

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1
New cards

What is linear search?

A search method that checks each item one by one from start to end.

2
New cards

What is binary search?

A fast search that repeatedly checks the middle of a sorted list.

3
New cards

What kind of list does binary search require?

A sorted list (numbers or items must be in order).

4
New cards

What are the starting values of low and high in binary search?

low = 0, high = len(list) - 1

5
New cards

How do you find the middle index in binary search?

mid = (low + high) // 2

6
New cards

When does binary search stop?

When the target is found, or when low > high.

7
New cards

What does binary search return if it finds the item?

The index of the item.

8
New cards

What does binary search return if it doesn't find the item?

None (or -1, depending on the code).

9
New cards

What is the time complexity of linear search?

O(n) — slower for large lists.

10
New cards

What is the time complexity of binary search?

O(log n) — much faster than linear for big lists.

11
New cards

What does log₂(n) tell you in binary search?

How many times you can cut the list in half before it's empty.

12
New cards

Binary vs. Linear Search: which is faster for large lists?

Binary search — but only if the list is sorted.

13
New cards

Why does binary search fail on unsorted lists?

Because the logic assumes sorted order to skip parts of the list.