You are on page 1of 3

Hashir Imtiaz(2022-CS-663)

Activity 05a Guess my Number.

1. Play a number guessing game with a partner. You think of an integer between 1 and 128. Your partner
will try to guess the number. You can tell them if they are too high, too low, or correct. Record your
guesses in the box below, then switch roles.
Guess: 48 115 90 70 40 50 65 55
Too Hi / Lo?
Too Lo Too Hi Too Hi Too Hi Too Lo Too Lo Too Hi Too Lo

Number is 60.

2. Change partners and play again.


This time keep track of the lowest and highest possibility the secret number could be.

Lowest 1 30 65 90 145 35 100


Possible #

Highest 128 75 200 160 180 80 150


Possible #

Guess 10 40 75 85 120 110 100

Too Hi / Too Lo Too Lo Too Lo Too Lo Too Hi Too Hi Too Hi


Low?

3. Look at the table above.


a. If the guess was too high, how did the value of the following change?
Lowest Possible: 145 Highest Possible: 200

b. If the guess was too low, how did the value of the following change? Lowest
Possible: 1 Highest Possible: 128

c. In both cases, how do you calculate the next guess?

Utilizing the lowest and highest possible numbers assists us in determining the correct number. These
values establish the numerical range within which the number is located. In the event that we select a
number that is either too high or too low, we should opt for a number that is not excessively high or
low. By employing this method, we can increase the likelihood of correctly guessing the number with
fewer attempts..

4. This algorithm is often called a Binary Search. The reason why the word “binary” is used is that the
number of possibilities is cut in half each time. Write out the complete algorithm for guessing a number
between Low and High using a binary search.

1. Choose a number from an array of numbers that you want to find.


2. Calculate the middle index by taking the sum of the first and last index of the array, then divide
the sum by 2.
3. Use the value at the middle index of the array as a reference for comparison.
4. Compare the reference value with all the numbers in the array.
5. If the number you are searching for is greater than the reference value, divide the array into two
parts and select the part that contains higher numbers. Set the middle value of this part as the
new reference value for comparison.
6. If the number you are searching for is smaller than the reference value, divide the array into two
parts and select the part that contains lower numbers. Set the middle value of this part as the
new reference value for comparison.

Activity 05b You Sort

A. In this activity, you and your partner will practice sorting a set of numbers from lowest to highest. You will
need 5-10 pieces of paper or card, with an integer written on each.

B. Place all the numbers face down and mix them up. Choose about 5 of the numbers, keep them face-down,
and place them in a row.

C. Decide on roles.
The “Helper” can look at the numbers and can say which one (of two) numbers is larger. The Helper cannot
move the numbers or give their partner any other information.

The “Sorter” cannot look at any numbers. However, they can point to two numbers (that are face down) and
ask the “Helper” which one is larger. The “Sorter” can also re-arrange the numbers.

D. Using about 5 numbers that are face-down in a row, work as a team to sort the numbers in order from
lowest to highest. Once the Sorter believes they are in order, turn over the numbers to see if your team
sorted them correctly. If you did not, try again. If you did, switch roles.

E. If you were successful with 5 numbers, try sorting 7, then try sorting 10 or more. Give each partner a turn
at each role.
PLAYERS:

Ali Irtaza (665) helper. Tayyab Zahid (659) helper.


AbdullahAteeq (661) sorter. Hashir Imtiaz (663) sorter.

Fahad Ayyaz (655) helper. Malik Shujaat (679) helper. Jawad


Ahmad (673) sorter. Shazaib (653) sorter.

Fahad (672) helper.


Hassnain (670) sorter.
F. There are actually many ways to solve this problem! Find another pair that sorted the numbers using a
different algorithm and compare your methods.
BUBBLE SORT SELECTION SORT
It involves comparing adjacent elements in a list and It involves repeatedly selecting the minimum element
swapping them if they are in the wrong order, creating a from an unsorted portion of a list and placing it at the
series of "bubbles" as smaller elements rise to the top. beginning of the sorted portion. This process is also
This process is repeated until the entire list is sorted. repeated until the entire list is sorted. Essentially,
selection sort involves selecting elements and placing
them in their correct order, rather than creating bubbles
as in bubble sort.

You might also like