Welcome to Day 3!

Give me 👍 if you watched CS50 Lec 0

Give me 👍 if you watched The Power of Vulnerability

Agenda

  • CS50 lecture 0 review
  • Recap Pseudocode
  • Algorithms Exercise
  • Problem solving techniques
  • Practice solving difficult problems

CS50 Lec 0

👍 if you liked it

Define Computer Science

Computer Science is the process of solving problems

Define problem

When we consider a problem to be solved, we have to all agree [...] how we're going to represent these inputs and outputs

Define representations of inputs and outputs

I/O Representations

  • binary
  • Chars (ASCII)
  • Text
  • Decimal
  • List
  • Object

How to represent algorithms?

Pseudocode!

Pseudocode Examples

Start with two pieces of bread.
while the first piece of bread is not covered with peanut butter on one side
	Spread peanut butter on one side of the first piece of bread
while the second piece of bread is not covered with jelly on one side
	Spread jelly on one side of the second piece of bread
Place the jelly side of the second piece of bread against the peanut butter side of the first piece of bread.
Place sandwich on plate, and cut in half.
MakePBJRoutine(input: peanut butter, jelly, bottom bread, top bread) 
Begin routine:
        Take bottom bread. 
        Spread peanut butter on bottom bread. 
        Spread jelly on bottom bread. 
        If want more jelly:
              Spread jelly on bottom bread. 
        Place top bread slice on bottom bread
        Return finished sandwich
End routine 
makePBJroutine(input: P, J, TB, BB; Out: PBJ) {
     BB <- P;
     BB <- J;
     If(BB.J < PreferredJellyAmountConstant){
         BB <- J;
     } 
    PBJ <- (BB <- TB);
    Return PBJ;
}

Is Pseudocode the only way to represent algorithms?

UML (Flowchart)

Birthday problem algorithms

Find the students whose birthday is today

 Aug 31                                                                                                                                                                                                     
 Nov 17    
 Nov 28    
 Feb 12    
 June 23    
 March 17    
 Nov 19    
 24 march    
 January 2    
 Aug 6    
 June 15    
 7th of June    
 15 January    
 Jan 2    
 24th of September!!    
 March 23    
 Oct 29    
 June 12    
 December 30    
 16th of November    
 22 of May    
 6th of february    
 Jan. the 10th    
 9th of October    
 July 17    
go down the list of birthdays
check if it is today
    memorize the student name
continue down the list

-------
first, sort  the birthdays
use a search algorithm to find the date more quickly

-------
Divide the birthdays by month
Search within each month

-------
Ahmed Jamal's solution 

Write the algorithm above with Pseudo Code in 30 minutes

Share your Pseudocode

#-10-inclass

go down the list of birthdays
check if it is today
    memorize the student name
otherwise
    continue down the list

-------                                                                                                                                                                                     

first, sort  the birthdays
use a search algorithm to find the date more quickly

-------                                                                                                                                                                                     

Divide the birthdays by month
Search within each month

-------

Divide the year into 365 days solution 
(Ahmed Jamal's solution on Slack #-05-random)

How did you solve this problem?

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

1. Understand and Analyse the Problem

List of months + days

List of integers representing the order at which the month + day combination appears

2. Go through the sample inputs and examples thoroughly

Pattern Recognition & Abstraction

List of months + days

List of integers representing the order at which the month + day combination appears

  • Aug 31
  • March 17
  • 24 march
  • 7th of June
  • 17 MAR
  • If today was Aug 31?
    • 1st
  • If today was Mar 17
    • 2nd
    • 5th

3. Break down the problem

Decomposition

List of

months + days

List of integers representing the order at which the month + day combination appears

  • Aug 31
  • March 17
  • 24 march
  • 7th of June
  • 17 MAR
  • If today was Aug 31?
    • 1st
  • If today was Mar 17
    • 2nd
    • 5th

List of

months + days

List of integers

  • Aug 31
  • March 17
  • 24 march
  • 7th of June
  • 17 MAR
  • 243
  • 77
  • 84
  • 159
  • 77

List of

months + days

List of integers

  • 243
  • 77
  • 84
  • 159
  • 77
  • If today was Aug 31?
    • 1st
  • If today was Mar 17
    • 2nd
    • 5th

4. Write Pseudocode

Algorithm Design

5. Start coding

Solution

Questions?

Another exercise

This one is more difficult

Design a solution to help large dev teams collaborate on code

1. Understand and Analyse the Problem

Code files

Code files

2. Go through the sample inputs and examples thoroughly

Pattern Recognition & Abstraction

  • Index.html
  • Index.css
  • Index.js
  • Changed index.html
    • Index.html
  • Changed index.html & index.css
    • Index.html
    • Index.css

Code files

Code files

What if 2 devs change the same file?

3. Break down the problem

Decomposition

4. Start solving/coding

Algorithm Design

Made with Slides.com