Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms and Pseudocode CS Principles Lesson Developed for CS4 Alabama Project Jim Morse.

Similar presentations


Presentation on theme: "Algorithms and Pseudocode CS Principles Lesson Developed for CS4 Alabama Project Jim Morse."— Presentation transcript:

1 Algorithms and Pseudocode CS Principles Lesson Developed for CS4 Alabama Project Jim Morse

2 Algorithms Review

3 Logic The science that investigates the principle of correct or reliable inference. Infer – Concluding from evidence – To indicate from facts a solution or guess – To speculate from premises – To suggest using presumed information

4 Algorithm An effective method expressed as a list of well- defined instructions for completing a task. Examples: Instructions to assemble an object Cooking Receipts Business processes Military Protocols

5 Basic Steps in Any Algorithm Create a List of the items you need to complete the task. Gather the items Do something with these items Display Finished product

6 Basic Functions in a Computer Gather the items (INPUT) Do something with these items (PROCESS) Display Finished product (OUTPUT)

7 Pseudocode

8 Computer Programming The design, scheduling, or planning of a computer program. An algorithm designed for a computer to complete a given task.

9 Pseudocode An algorithm of a task, written in a form that can easily be converted into a computer program at a later date. For us, written in English Must be accurate, specific and feasible

10 Why Pseudocode? To detect any logic error prior to writing a computer program. Simple to covert into any programming language.

11 Steps of Pseudocode Define the problem Define the information that needs to be gathered to solve the problem Write the pseudocode for inputting the information Write the pseudocode for processing the information Write the pseudocode for reporting the results or solution.

12 Clarify the Problem What is really being asked of you? Disregard useless information. – Many times programming questions are presented with information that is intended to confuse you and is not needed to solve the problem. Is there a formula or equation I will need to solve the problem? What is it?

13 Input What data/information is needed for the computer to solve the problem. How are you going to store the data while you are waiting to use it?

14 Processing What needs to be done to the inputted data to solve the problem?

15 Output Displaying, print, writing, sending information to a screen, console, printer, file or over a network.

16 Input

17 Storage of Input For a computer to use data, it must be inputted from a source and stored in the memory (RAM) of the computer. We store this data… – Constants – Variables – Arrays/lists These memory locations have a unique name or identifier.

18 Basic Data Types Character – one keystroke ( ‘a’, ‘ ’, ’!’, etc…) String – multiple keystrokes (“Apple”,“!sdksdf&8”, “The pig in the poke”, etc…) Integer – whole numbers (12,56,-6,239, etc…) Decimals – Numbers with decimal places (1.1, 6.3, -234.0, 1.0, etc…) Boolean – Logic (TRUE or FALSE)

19 Constants Constants hold one value and should never be changed. Assignment of constants follow this format: ConstantName = value Example: Str_Name = “Jim” Dec_Pay = 132.43

20 Variables Similar to constants but the values variables can change as the program runs. Assignment of variable follow this format: VariableName = value Example: Dec_Pay = 132.43 Bo_PowerOn = TRUE

21 Arrays/Lists A group of data that has some connection. Assignment of arrays/lists follow this format: ArrayName = [value1, value2, value3] Example: Str_Fruits = [“apple”, “banana”, “peach”] Int_Numbers = [1, 2, 3, 77] Arrays usually hold only on type of data, Lists can hold multiple types of data.

22 Arrays/Lists Variables and constants can be added to arrays/lists. MyFavorite = “Apple” YourFavorite = “Peach” OurFruits = ( Myfavorite, YourFavorite)

23 Processing

24 The manipulation of data in a structured event. Two ways to look at processing… 1.Computational 2.Structural

25 Computational Processing Mathematical – Add- Multiply – Subtract- Divide – Exponential- Modulus Logical – Equal- Not Equal – Greater Than- Less Than – Greater Than or Equal To- Less Than or Equal To – Contains- Does Not Contain – AND- OR

26 Structural 3 basic forms that can be used in pseudocodes 1.Sequence 2.Decisions 3.Loops

27 Structures Sequence - one step at a time until completion Begin Create variable Str_Name GET Str_Name value from user DISPLAY Str_Name value END

28 Structures - Decisions IF – complete process only if a logical comparison is true. IF…ELSE – completes one process if a logical comparison is true and completes another if the process is false IF…ELSEIF…ELSE – more than two results of a comparison.

29 IF… Decision ….. IF (Condition is TRUE) do something End

30 IF…ELSE Decision ….. IF (Condition is TRUE) do something ELSE do something else END

31 IF…ELSEIF….ELSE Decision ….. IF (condition is TRUE) do something ELSEIF (this other condition is true) do something else ELSE do a third option END

32 Loops We use a WHILE loop for most situations While (condition is TRUE) do this Loop End

33 Creating Pseudocode

34 Basic Rules of Pseudocode One step of algorithm per line. Indent to show steps within a structure Always use a key word to describe similar steps

35 Example of Consistent Wording GET = receive information from the user WRITE = save information to a file DISPLAY = make information viewable to the user

36 Debugging/Troubleshooting Debugging – The process of locating and fixing errors in your pseudocode, whether these errors are logical, mathematical or procedural. Hints: Trace Runs– Step through the pseudocode step by step writing down all possible inputs, processing all equations and comparisons by hand. Peer Review – Have a peer step through your pseudocode for validation of your processes.

37 End Teachers, please use these slides as guidelines. Add images, videos, design templates as you see fit taking in consideration your audience.


Download ppt "Algorithms and Pseudocode CS Principles Lesson Developed for CS4 Alabama Project Jim Morse."

Similar presentations


Ads by Google