Sorting and Searching

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/7

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:38 PM on 3/27/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

8 Terms

1
New cards
<p>binary search</p>

binary search

Classic template:

  1. l = 0, r = n-1

  2. While l <= r:

    • mid = (l+r)//2

    • Compare target with nums[mid]

  3. Move left/right accordingly

    O(log n)

2
New cards
<p><strong>Search in Rotated Sorted Array</strong></p>

Search in Rotated Sorted Array

Modified binary search:

  1. One half is always sorted

  2. Check if target lies in sorted half

  3. Move to correct side

    Repeat until found

    O(log n)

3
New cards
<p><strong>Kth Smallest Element in a Sorted Matrix</strong></p>

Kth Smallest Element in a Sorted Matrix

Binary search on value range:

  1. low = smallest, high = largest

  2. Mid = candidate value

  3. Count elements ≤ mid (row-wise)

  4. If count < k → search right

  5. Else search left

    O(n log range)

4
New cards
<p><strong>Search a 2D Matrix</strong></p>

Search a 2D Matrix

Treat matrix as sorted array:

  1. Index = mid // cols, mid % cols

  2. Apply binary search

    Matrix is globally sorted

    O(log (m*n))

5
New cards
<p><strong>Kth Largest Element in an Array</strong></p>

Kth Largest Element in an Array

Quickselect:

  1. Choose pivot

  2. Partition into > pivot and < pivot

  3. Recurse on correct side

    Average O(n)

    (Heap alternative: size k min-heap → O(n log k))

6
New cards
<p><strong>Find Minimum in Rotated Sorted Array</strong></p>

Find Minimum in Rotated Sorted Array

Binary search:

  1. Compare nums[mid] with nums[r]

  2. If mid > r, min is right side

  3. Else min is left (including mid)

    Stop when l == r

    O(log n)

7
New cards
<p><strong>Median of Two Sorted Arrays (H)</strong></p>

Median of Two Sorted Arrays (H)

Binary search partition:

  1. Partition both arrays so left halves = right halves

  2. Ensure max(left) ≤ min(right)

  3. Median from boundary elements

    Binary search on smaller array

    O(log(min(m,n)))

8
New cards
<p><strong>H-Index</strong></p>

H-Index

Sort citations:

  1. Sort descending

  2. Find largest h such that citations[h] ≥ h+1

    Alternative:

  • Sort ascending and check citations[i] ≥ n-i

Explore top notes

Explore top flashcards

flashcards
Bio Chapter 1 Test
93
Updated 572d ago
0.0(0)
flashcards
A&P Chapter 12.
101
Updated 842d ago
0.0(0)
flashcards
Español Dos Study Guide
22
Updated 1058d ago
0.0(0)
flashcards
PSY 3113 Chapter 2
45
Updated 903d ago
0.0(0)
flashcards
Python 221 Terms
63
Updated 857d ago
0.0(0)
flashcards
Vocabulary & Spelling 2.3
20
Updated 484d ago
0.0(0)
flashcards
Bio Chapter 1 Test
93
Updated 572d ago
0.0(0)
flashcards
A&P Chapter 12.
101
Updated 842d ago
0.0(0)
flashcards
Español Dos Study Guide
22
Updated 1058d ago
0.0(0)
flashcards
PSY 3113 Chapter 2
45
Updated 903d ago
0.0(0)
flashcards
Python 221 Terms
63
Updated 857d ago
0.0(0)
flashcards
Vocabulary & Spelling 2.3
20
Updated 484d ago
0.0(0)