Welcome back to Software Development! Return graded assignments Review classroom procedures: Start of class procedure Reminders: Missing assignments Friday quiz – open book
Basic Flowchart Symbols Start or end of algorithm: Action/process step: Input or output operation: Decision: Leave the house At school - done Start the car Ask for directions Is the stoplight red? Yes No
Largest Number Algorithm Take the 1st number – at the start, it is the largest we’ve seen Do Get the next number from the list Compare the current largest to the next number If the next number is larger Then take it as the largest Until there are no more numbers left The number you are left with is the largest
Get 1st # as largest Get nxt # Compare nxt to largest Nxt # larger? Yes Nxt is new largest No Flowchart for my algo Emphasize Loop is obvious Decisions are obvious Loop termination condition…end of list General…works for any list of numbers Only specific is starting in the list (1st item in list) More #’s ? Yes No Done!
Task: find the largest number in a list of integers
Task: find the largest number in a list of integers Possible Algorithm:
Task: find the largest number in a list of integers Possible Algorithm: Get the list
Task: find the largest number in a list of integers Possible Algorithm: Get the list Get the biggest number from the list
Task: find the largest number in a list of integers Possible Algorithm: Get the list Get the biggest number from the list Done
Task: find the largest number in a list of integers Possible Algorithm: Get the list Get the biggest number from the list Done
Task: find the largest number in a list of integers Possible Algorithm: Get the list Get the biggest number from the list Done All you are doing is restating the problem…
Task: find the largest number in a list of integers
Task: find the largest number in a list of integers Algorithm:
Task: find the largest number in a list of integers Algorithm: Get the list
Task: find the largest number in a list of integers Algorithm: Get the list Sort the list from smallest to largest
Task: find the largest number in a list of integers Algorithm: Get the list Sort the list from smallest to largest Take the largest number
Task: find the largest number in a list of integers Algorithm: Get the list Sort the list from smallest to largest Take the largest number Done
Task: find the largest number in a list of integers Algorithm: Get the list Sort the list from smallest to largest Take the largest number Done
Task: find the largest number in a list of integers Algorithm: Get the list Sort the list from smallest to largest Take the largest number Done
Task: find the largest number in a list of integers Algorithm: Get the list Sort the list from smallest to largest Take the largest number Done You’ve actually created a harder problem that includes this one!
Algorithm Guidelines…
Algorithm Guidelines… One action per step or flowchart box:
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box?
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box.
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction…
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction… And, or, but, unless, ...
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction… And, or, but, unless, ... Likely more than one action in the step.
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction… And, or, but, unless, ... Likely more than one action in the step. Look for buried questions or decisions
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction… And, or, but, unless, ... Likely more than one action in the step. Look for buried questions or decisions Looping words: continue, do, repeat (the flow arrows covers these)
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction… And, or, but, unless, ... Likely more than one action in the step. Look for buried questions or decisions Looping words: continue, do, repeat (the flow arrows covers these) Decision words: is, if, ?
Algorithm Guidelines… One action per step or flowchart box: Too many words in the step / box? Keep it short and sweet … 5-6 words per step / box. Conjunction Junction… And, or, but, unless, ... Likely more than one action in the step. Look for buried questions or decisions Looping words: continue, do, repeat (the flow arrows covers these) Decision words: is, if, ? “Keep the larger number” is a decision (if x > y) and an action (keep x)…2 steps
Broken down enough?
Broken down enough? Swap “this” and “that” number in the list
Broken down enough? Swap “this” and “that” number in the list Is this one step?
Broken down enough? Swap “this” and “that” number in the list Is this one step? Actually no…
Broken down enough? Swap “this” and “that” number in the list Is this one step? Actually no… 1) Get a temporary copy of “this” number
Broken down enough? Swap “this” and “that” number in the list Is this one step? Actually no… 1) Get a temporary copy of “this” number 2) Move “that” number to “this” number’s slot
Broken down enough? Swap “this” and “that” number in the list Is this one step? Actually no… 1) Get a temporary copy of “this” number 2) Move “that” number to “this” number’s slot 3) Move “this” number to “that” number’s old slot
Broken down enough? Swap “this” and “that” number in the list Is this one step? Actually no… 1) Get a temporary copy of “this” number 2) Move “that” number to “this” number’s slot 3) Move “this” number to “that” number’s old slot If you understand this, you can put “swap A with B” as a flowchart step
Broken down enough? Swap “this” and “that” number in the list Is this one step? Actually no… 1) Get a temporary copy of “this” number 2) Move “that” number to “this” number’s slot 3) Move “this” number to “that” number’s old slot If you understand this, you can put “swap A with B” as a flowchart step When you code it, you will need to actually code the above steps
Practice Guided practice Rewrite “largest number” algo Focus on general solution Loop termination condition Flowchart your algo Team effort Turn in at end of class…graded. FINISH ALGO BEFORE STARTING FLOWCHART! About 30 mins
Practice Review and rewrite your “select the largest number” algorithm for clarity and conciseness.
Practice Review and rewrite your “select the largest number” algorithm for clarity and conciseness. Flowchart your “select the largest number” algorithm.
Practice Review and rewrite your “select the largest number” algorithm for clarity and conciseness. Flowchart your “select the largest number” algorithm. You have 30 minutes…
Hmm, an idea… Demonstrate power of a general algo Simple change solves a different problem What change needed to find smallest number? 10 minutes, group work
Hmm, an idea… What would you have to do to your “largest number” algorithm to make it a “smallest number” algorithm?
Hmm, an idea… What would you have to do to your “largest number” algorithm to make it a “smallest number” algorithm? Just change your comparison decision!
A Harder Task Extend and reinforce power of general solution. Use either algos to develop algo to sort a list of numbers Tool box reminder: Algos are tools to be used Keep a “tool box” of your valuable tools Use the right tool for the job Rest of class (30 minute goal) Close with “clear/unclear windows”
A Harder Task See if you can find a way to use your “largest number” or “smallest number” algorithm to sort a (any) list of numbers.
A Harder Task See if you can find a way to use your “largest number” or “smallest number” algorithm to sort a (any) list of numbers. Work with your partner
A Harder Task See if you can find a way to use your “largest number” or “smallest number” algorithm to sort a (any) list of numbers. Work with your partner Names on your work paper
A Harder Task See if you can find a way to use your “largest number” or “smallest number” algorithm to sort a (any) list of numbers. Work with your partner Names on your work paper Turn in at end of class
A Harder Task See if you can find a way to use your “largest number” or “smallest number” algorithm to sort a (any) list of numbers. Work with your partner Names on your work paper Turn in at end of class You have about 30 minutes…
Clear and Unclear Windows Tomorrow: Continue sorting algo Loops exploration