120 likes | 266 Vues
Explore the fundamentals of algorithms and control structures in Java programming with Dale Roberts at IUPUI. This program covers the essence of algorithms as systematic procedures to solve computing problems, the importance of control flow with sequential, selection, and repetition structures, and the significance of structured programming. Students will learn to represent algorithms using pseudocode and flowcharts, enhancing their programming skills through practical applications. Gain insights on building efficient programs without unnecessary complexities.
E N D
Department of Computer and Information Science,School of Science, IUPUI Program Control using Java- Theory Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu
Algorithms • Algorithms is the are part of the problem solving process • ‘A’ in STAIR. • All computing problems can be solved by executing a series of actions in a specific order, called an algorithm • Algorithm: procedure in terms of • Actions to be executed • The order in which these actions are to be executed • Program control • Specify order in which statements are to executed
Definition of Algorithm • Definition of an Algorithm • consists of unambiguous & computable operations • produce a result • halt in a finite amount of time. • Some scientists add a restriction that the algorithm must halt in a reasonable amount of time. Why would there be resistance to this idea?
Control Structures • Sequential execution • Statements executed one after the other in the order written • Transfer of control • When the next statement executed is not the next one in sequence • Overuse of goto statements led to many problems • Bohm and Jacopini • All programs written in terms of 3 control structures • Sequence structures: Built into C. Programs executed sequentially by default • Selection structures: Java has three types: if, if/else, and switch • Repetition structures: Java has three types: while, do/while and for
Pseudocode • Pseudocode • An informal language similar to English • Helps programmers develop algorithms • Does not run on computers • Should contain input, output and calculation actions • Should not contain variable declarations For each student i in the Class Calculate the student’s average score If the average score >= 90A% Then Assign Student[i] grade to ‘A’ End if End For
Control Structures • Sequential execution • Statements are normally executed one after the other in the order in which they are written • Transfer of control • Specifying the next statement to execute that is not necessarily the next one in order • Can be performed by the goto statement • Structured programming eliminated goto statements
4.4 Control Structures (Cont.) • Bohm and Jacopini’s research • Demonstrated that goto statements were unnecessary • Demonstrated that all programs could be written with three control structures • The sequence structure, • The selection structure and • The repetition structure
4.4 Control Structures (Cont.) • UML activity diagram (www.uml.org) • Models the workflow (or activity) of a part of a software system • Action-state symbols (rectangles with their sides replaced with outward-curving arcs) • represent action expressions specifying actions to perform • Diamonds • Decision symbols (explained in Section 4.5) • Merge symbols (explained in Section 4.7)
Control Structures • Flowchart • Graphical representation of an algorithm • Drawn using certain special-purpose symbols connected by arrows called flowlines • Rectangle symbol (action symbol): • Indicates any type of action • Oval symbol: • Indicates the beginning or end of a program or a section of code • Single-entry/single-exit control structures • Connect exit point of one control structure to entry point of the next (control-structure stacking) • Makes programs easy to build
4.4 Control Structures (Cont.) • Small circles • Solid circle represents the activity’s initial state • Solid circle surrounded by a hollow circle represents the activity’s final state • Transition arrows • Indicate the order in which actions are performed • Notes (rectangles with the upper-right corners folded over) • Explain the purposes of symbols (like comments in Java) • Are connected to the symbols they describe by dotted lines
Acknowledgements • Deitel, Java How to Program