GEC 114 Algorithms (Fall 2024) PDF
Document Details
Uploaded by PainlessSnowflakeObsidian
IIUI
2024
Sameer Akram Mirza
Tags
Related
- GE8151- PROBLEM SOLVING AND PYTHON PROGRAMMING - Question Bank PDF
- CPRO1 Introduction to Computer Programming PDF
- Fundamentals of Programming - Algorithms and Flowcharts PDF
- Introduction to Computer Algorithms PDF
- Unit 02: Computational Thinking and Algorithms PDF
- Computer Programming Skills Lecture Notes PDF
Summary
This document is a lecture presentation on algorithms and pseudocode. It covers different types of algorithms, such as sequence, selection, and iteration logic, and explains how to express algorithms using various notations. The document also discusses rules for writing pseudocode, such as the importance of indentation.
Full Transcript
GEC 114 – Applications of Information and Communication Technology Sameer Akram GEC 114 – Applications of Information & Communication Technology Lecture 11 – Alg...
GEC 114 – Applications of Information and Communication Technology Sameer Akram GEC 114 – Applications of Information & Communication Technology Lecture 11 – Algorithms (Pseudocode) Sameer Akram Mirza FALL 2024 Finding the largest integer among five integers 2 Defining actions in Find Largest algorithm 3 Properties of Algorithm There are three properties of algorithm that must have to consider in solving a certain problem in programming: Finiteness Absence of Ambiguity Sequence Definition Input and Output Definition Effectiveness Scope of Definition Properties of Algorithm (Contd.) Finiteness The execution of a programmed algorithm must be complete after a finite number of operations have been performed. Otherwise, we cannot claim that the execution produces a solution. Absence of Ambiguity The representation of every step of an algorithm should have a unique interpretation which also understand by the human. It is convenient to deal with algorithms presented in notational with sparse detail: Example: Pseudo code Flowcharts Properties of Algorithm (Contd.) Sequence of Definition The sequence in which the steps of the algorithm are to carried out should be clearly specified. In algorithmic specifications, the instructions are performed from top to bottom, unless the instruction themselves otherwise specified. Input and Output Definition Inputs – are the data items that is presented in the algorithm. Outputs – are the data items presented to the outside world as the result of the execution of a program based on the algorithm. An algorithm ought to produce at least one output (otherwise, what use is it?...) Properties of Algorithm (Contd.) Effectiveness it consists of basic instructions that are realizable. This means that the instructions can be performed by using the given inputs in a finite amount of time. The instructions of an algorithm may order the computer only to perform tasks that is capable of carrying out. Scope Definition An algorithm applies to the following: Specific problem or class of problem The range of inputs has to be predefined The range determines the generality of the algorithm. How to express an ALGORITHM? Algorithms can be expressed in many kinds of notation, including: Natural language Pseudo Code Flowcharts Programming Language What is Pseudocode…? “Pseudo” means artificial / imitation and “code” refers to the instructions written in a programming language. Pseudocode is another programming analysis tool that is used for planning a program. Pseudocode is also called Program Design Language (PDL). What is Pseudocode…? (Contd.) Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language, but is intended for human reading rather than machine reading. (Wikipedia) Pseudocode Statements and Flowchart Symbols Flowchart Pictorial representation of the logical steps it takes to solve a problem Pseudocode Language-like representation of the logical steps it takes to solve a problem Statements in pseudocode look similar to statements in a high-level language 11 Logical Structure of Pseudocode Pseudocode is made up of the following logic structures that have been proved to be sufficient for writing any computer program: Sequence Logic Selection Logic Iteration Logic Sequence Logic It is used to perform instructions in a sequence, that is one after another. Thus, for sequence logic, pseudocode instructions are written in an order in which they are to be performed. The logic flow of pseudocode is from top to bottom. Sequence Logic (Contd.) Selection Logic It is used for making decisions and for selecting the proper path out of two or more alternative paths in program logic. It is also known as decision logic. Selection logic is depicted as either an IF...THEN or an IF...THEN...ELSE structure. Iteration Logic It is used to produce loops when one or more instructions may be executed several times depending on some of the conditions. It uses structures called the DO_WHILE, FOR and the REPEAT_UNTIL. Rules for Pseudocode 1. Write only one statement per line. Each statement in your pseudocode should express just one action for the computer. If the task list is properly drawn, then in most cases each task will correspond to one line of pseudocode. 2. Capitalized initial keyword. In the example above, READ and WRITE are in caps. There are just a few keywords we will use: READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE, REPEAT, UNTIL Rules for Pseudocode (Contd.) 3. Indent to show hierarchy. We will use a particular indentation pattern in each of the design structures: SEQUENCE: keep statements that are “stacked” in sequence all starting in the same column. SELECTION: indent the statements that fall inside the selection structure, but not the keywords that form the selection LOOPING: indent the statements that fall inside the loop, but not the keywords that form the loop Rules for Pseudocode (Contd.) Examples: Rules for Pseudocode (Contd.) 4. End multi-line structures. All the initial keyword must always in line with the last or end of the structure. 5. Keep statement language independent. Resist the urge to write in whatever language you are most comfortable with. There may be special features available in the language you plan to eventually write the program in; if you are SURE it will be written in that language, then you can use the features. If not, then avoid using the special features. Rules for Pseudocode (Contd.) In summary: Write only one statement per line. Capitalized initial keyword. Indent to show hierarchy. End multi-line structures. Keep statement language independent. Standard for good pseudocode… These are follows: Number each instruction. This is to enforce the notion, “well-ordered collection of... operations.” Each instruction should be unambiguous. It means the computing agent, in this case the reader, should be capable of carrying out the instructions. And also, each instruction should be effectively computable (do-able). Completeness Nothing should be left out. Advantage of Pseudocode… Following are some of the advantages of using pseudocode: Converting a pseudocode to a programming language is much more easier than converting a flowchart. As compared to flowchart, it is easier to modify a pseudocode of a program logic when program modifications are necessary. Limitations of Pseudocode… It also suffers from some of the limitations. These limitations are as follows: In the cases of pseudocode, a graphic representation of program logic is not available. There are no standard rules to follow for using a pseudocode. Different programmers use their own style of writing pseudocode and hence, communication problem occurs due to lack of standardization. That’s end of the presentation! 25