12 - Binary search

Binary search
/Division and remainders
1 / 20
volgende
Slide 1: Tekstslide
ComputingUpper Secondary (Key Stage 4)GCSE

In deze les zitten 20 slides, met interactieve quizzen en tekstslides.

time-iconLesduur is: 50 min

Onderdelen in deze les

Binary search
/Division and remainders

Slide 1 - Tekstslide

Division and Remainders
/ Division
// Floor Division
% Modulus

Slide 2 - Tekstslide

Predict

Slide 3 - Tekstslide

What do you think the code
will do when run?

Slide 4 - Open vraag

Slide 5 - Tekstslide

Investigate & Modify
Using /, // and %, calculate the following questions using python

Slide 6 - Tekstslide

What is 703 divided by 34 with no remainder?
A
23
B
22
C
20
D
34

Slide 7 - Quizvraag

What is the remainder of 703 divided by 34?
A
23
B
22
C
20
D
34

Slide 8 - Quizvraag

What is 90231 divided by 94?
A
959
B
959.904255319
C
90
D
85

Slide 9 - Quizvraag

Linear Search
Attempt to code a linear search in Python




Slide 10 - Tekstslide

Advanced Linear search

Slide 11 - Tekstslide

Predict

Slide 12 - Tekstslide

What do you think the code
will do when run?

Slide 13 - Open vraag

Slide 14 - Tekstslide

Investigate and Modify
Experiment with altering the target and array's hard-coded values to investigate their effects

  • Replace the array, to cover a range of 1-10 using two "pointers"
  • Replace target's hard coded value with a user input.

Slide 15 - Tekstslide

Make
Click here for a blank createwithcode
Create a program to guess a user's number 1-100 with binary search.
You will only tell the program if their number is higher, lower or correct.

Slide 16 - Tekstslide

Number Guesser Code

Slide 17 - Tekstslide

What is the main advantage of using binary search over linear search?
A
Binary search is eaiser to implement
B
Binary search usually runs faster
C
Binary search works on unsorted data
D
Binary search is more suitable for small datasets

Slide 18 - Quizvraag

What is the result of 17 % 5?
A
2
B
3
C
4
D
5

Slide 19 - Quizvraag

In binary search, what is the first step after calculating the midpoint?
A
Check if the midpoint is equal to the target
B
Update the low pointer to the midpoint
C
Update the high pointer to the midpoint.
D
Divide the searrch space into two halves.

Slide 20 - Quizvraag