Lab 4 - about algorithm | CS160, Exercises of Computer Science

Start with algorithm in this lab

Typology: Exercises

2016/2017

Available from 01/14/2022

hoang-vu-nguyen
hoang-vu-nguyen 🇺🇸

4 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Vu Nguyen
CS160
Lab 4
1: An algorithm is an unambiguous specification of how to solve a class of
problems
Example: recipe for cooking a meal, solving a homework problems, driving to
school
2-a: Making peanut butter and jelly sandwich
step 1: prepare the materials: get peanut butter, jelly and sandwich, a small knife
Step 2: position the bread: get 2 pieces of bread
Step 3: apply peanut butter: Using the knife, scoop a large dollop of peanut butter
and spread it onto the top of each slice of bread.* Use as much peanut butter as
desired.
Step 4: apply jelly: Using the same technique as with the peanut butter, scoop
out the desired amount of jelly. Spread it on top of the peanut butter of one slice
of bread.
Step 5: Combine Both Slices of Bread : Take the slice of bread without jelly on it
and flip it on top of the jelly of the other slice
Step 6: Eat and Repeat: Eat the sandwich, and if I want more, I redo step 2
2-b: Driving to LCC:
Step 1: Get into the car: Get ready to go to LCC
Step 2: Take a left to Harlow street: after leaving the house, I take a left
Step 3: Take a right to Laura street: keep going on Harlow street until I see a sign
said Laura street, then I turn right
Step 4: Take a right to I-126: When I see I-126, I take a right and merge on free-
way.
Step 5: Take a left to I-5: Slightly make a left and merge on I-5, keep driving for 3
miles
Step 6: Take a right on 30th avenue: take a right turn on 30th avenue and keep
driving until I see the sign LCC.
Step 7: arrive LCC:

Partial preview of the text

Download Lab 4 - about algorithm | CS160 and more Exercises Computer Science in PDF only on Docsity!

Vu Nguyen CS Lab 4 1: An algorithm is an unambiguous specification of how to solve a class of problems Example: recipe for cooking a meal, solving a homework problems, driving to school 2-a: Making peanut butter and jelly sandwich  step 1: prepare the materials: get peanut butter, jelly and sandwich, a small knife  Step 2: position the bread: get 2 pieces of bread  Step 3: apply peanut butter: Using the knife, scoop a large dollop of peanut butter and spread it onto the top of each slice of bread. Use as much peanut butter as desired.  Step 4: apply jelly: Using the same technique as with the peanut butter, scoop out the desired amount of jelly. Spread it on top of the peanut butter of one slice of bread.  Step 5: Combine Both Slices of Bread : Take the slice of bread without jelly on it and flip it on top of the jelly of the other slice  Step 6: Eat and Repeat: Eat the sandwich, and if I want more, I redo step 2 2-b: Driving to LCC:  Step 1: Get into the car: Get ready to go to LCC  Step 2: Take a left to Harlow street: after leaving the house, I take a left  Step 3: Take a right to Laura street: keep going on Harlow street until I see a sign said Laura street, then I turn right  Step 4: Take a right to I-126: When I see I-126, I take a right and merge on free- way.  Step 5: Take a left to I-5: Slightly make a left and merge on I-5, keep driving for 3 miles  Step 6: Take a right on 30th avenue: take a right turn on 30th avenue and keep driving until I see the sign LCC.  Step 7: arrive LCC: