🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

W1 - ICT912 Programming.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

MIT : ICT912 Programming LECTURE 1 Computational Thinking and Programming Tools 1 Resources Prescribed Texts McMullen, K., Matthews, E., & Parsons, J. J. (2022). Programming with Python (1st ed.)., Cengage Learning Recom...

MIT : ICT912 Programming LECTURE 1 Computational Thinking and Programming Tools 1 Resources Prescribed Texts McMullen, K., Matthews, E., & Parsons, J. J. (2022). Programming with Python (1st ed.)., Cengage Learning Recommended Readings Lutz, M. (2013). Learning Python (5th ed.). O'Reilly Media, Inc * Slides taken from Cengage resources 2 Week 1: Lesson Learning Outcomes Ø Understand the basics of computer science including problem solving and algorithms Ø Identify and explain different programming paradigms, such as procedural, object- oriented, parallel, logic, functional and database programming Ø Develop problem-solving skills to break down complex problems and design efficient algorithms Ø Design and analyze algorithms for various types of problems, with a focus on algorithm efficiency Ø Distinguish between syntax and semantics in the context of programming languages 3 What is Computer Science? Ø A computer is a programmable machine that receives input, stores and manipulates data, and provides output in a useful format. (Wikipedia) Ø Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems. (Wikipedia) Ø A program is a sequence of instructions that can be executed by a computer to solve some problem or perform a specified task. Ø A programming language is an artificial language designed to automate the task of organizing and manipulating information, and to express problem solutions precisely 4 Programming Languages 5 Programming Paradigms 6 Programming Paradigms Ø Imperative paradigm: Ø giving explicit instructions to the computer Ø Procedural Programming Ø list of step-by-step instructions for the computer program to follow Ø Use case: finding the area of a figure, display some phrase like “Hello, world!” Ø E.g.: C, Pascal Ø Object Oriented Programming Ø program is written as a collection of classes; revolves around objects that encapsulate data and behavior Ø Use case: entity cat, and we want to describe it using a class, attributes and methods. Ø E.g.: C++, Java, Python Ø Parallel Programming Ø sharing or parallelizing instructions across multiple processors: "divide and conquer" Ø Use case: reduce instruction execution time Ø E.g.: C, C++ 7 Programming Paradigms Ø Declarative paradigm: Ø specifying the logic of computation without dictating the control flow Ø Logical Programming Ø based on the notion of formal logic and mathematical proofs Ø Use case: ‘X is true if Y and Z are true’. Research and testing complex theorems Ø E.g.: Prolog, Datalog Ø Functional Programming Ø emphasizes the use of functions to accomplish tasks Ø Use case: avoid flow controls like loops and instead favor recursive functions Ø E.g.: JavaScript, Scala, Lisp Ø Database Programming Ø based on working with data Ø Use case: allowing for file creation, data entry, updating, querying, and reporting functions Ø E.g.: SQL 8 Problem Solving Ø Problem Solving is the sequential process of analyzing information related to a given situation and generating appropriate response options. Ø Problem Solving Process: Ø Understanding the problem Ø Analyzing the problem Ø Developing a plan Ø Implementing the plan Ø Testing and Debugging Ø Evaluating the solution 9 Example Ø Calculate the average grade for all students in a class get all the grades … perhaps by typing them in via the 1. Input: keyboard or by reading them from a USB flash drive or hard disk. 2. Process: add them all up and compute the average grade. output the answer to either the monitor, to the printer, to the 3. Output: USB flash drive or hard disk … or a combination of any of these devices. 10 1. Understand the Problem Ø What input data/information is available ? Ø What does it represent ? Ø What format is it in ? Ø Is anything missing ? Ø Do I have everything that I need ? Ø What output information am I trying to produce ? Ø What do I want the result to look like … text, a picture, a graph … ? Ø What am I going to have to compute ? 11 2. Analysing the Problem Ø Look for familiar things Ø You should never try to “reinvent the wheel” Ø Divide and Conquer Ø Break up a large problem into smaller units that can be handled more easily Ø Do you understand this step in the problems solving process ? Ø It is all about figuring out how you will make use of the available data to compute an answer 12 3. Developing a plan Ø An algorithm is a precise sequence of instructions for solving a problem. Ø Representation: Ø Pseudo code Ø A pseudocode is a simple and concise sequence of English-like instructions to solve a problem. Ø Flow charts Ø a graphical representation of a computer program in relation to its sequence of functions 13 4. Implementing the plan 14 5. Testing and Debugging Ø Compiling is the process of converting a program into instructions that can be understood by the computer. Ø Running a program is the process of telling the computer to evaluate the compiled instructions. Ø (Software) Testing is an investigation conducted to detect errors and gaps between existing and required conditions Ø Bugs are problems/errors with a program that cause it to stop working or produce incorrect or undesirable results Ø The process of finding and fixing errors in your code is called debugging 15. 6. Evaluating the Solution Ø Re-consider the original problem to make sure the answer is the proper solution Ø May realize that you need additional steps/data to solve the problem fully Ø Or may need to adjust the results Ø May be necessary to re-do some steps or start again if data was missing 16 Abstraction Ø Abstraction plays an important role. Ø A mental model that removes complex details 17 Algorithm Ø Algorithm: Ø A series of steps for solving a problem or carrying out a task Ø Programming algorithm: Ø A set of steps that specify the underlying logic and structure for the statements in a computer program Ø Computer program Ø A set of instructions, written in a programming language that performs a specific task when executed by a digital device Ø “Good” algorithms: Ø Input: applies to a set of specified inputs Ø Output: produces one or more outputs Ø Finite: terminates after a finite number of steps Ø Precise: each step is clear and unambiguous 18 Ø Effective: successfully produces the correct output Representations Ø Two ways: Ø Flow charts Ø Symbols convey different types of actions Ø Pseudocodes Ø A cross between code and plain English Ø Note: Ø The performance of the algorithm is measured based on time complexity and space complexity. Ø Mostly, the complexity of any algorithm is dependent on the problem and on the algorithm itself. 19 Flowchart Symbol Name Function Start/End An oval represents a start or end point A line is a connector that shows relationships between Arrows the representative shapes Input/ Output A parallelogram represents input or output Process A rectangle represents a process Decision A diamond indicates a decision 20 Pseudocode Ø Pseudocode is text based – Plain English to express the logic and flow of the program Ø A way of describing an algorithm without using any specific programming language Ø No graphical or tabular syntax 21 Example Ø Draw a flowchart and write a pseudocode to calculate the area of a rectangle Ø Formula: Area = Length * Breadth Pseudocode Flow chart Step 1: Start Step 2: Input length and breadth Step 3: area = length * breadth Step 4: print area Step 5: stop 22 **Use Draw.io to draw flowcharts Algorithm Efficiency Ø That XYZ 23 Algorithm Efficiency Ø The runtime complexity (a.k.a. running time) of an algorithm is the amount of time that it takes to complete once it has begun. Ø Mainly calculated by counting the number of steps to finish the execution Ø The space complexity of an algorithm is the amount of memory or storage space required by the algorithm execute and store data. Ø Space complexity = Auxiliary space + Input size. Ø Auxiliary space: The extra space required by the algorithm, excluding the input size, is known as an auxiliary space. 24 Programming Languages Ø Starting point for programmers 25 Programming Terminology Ø Machine Language Ø High-level Language Ø The most basic circuitry-level language Ø Allows you to use a vocabulary of reasonable Ø A low-level programming language terms Ø Syntax Ø Program Statements Ø A specific set of rules for the language Ø Similar to English sentences Ø Commands to carry out program tasks Ø Syntax Errors Ø Logic Errors Ø Misuse of language rules Ø Also called semantic errors Ø A misspelled programming language word Ø The program may run but provide inaccurate output Ø Compiler Ø Interpreter Ø Preprocesses and converts all the statements Ø Converts source code into object code one into a binary file statement at a time 26 Core Elements Ø Variables that can be assigned values and structures Ø Arithmetic operators that perform calculations Ø Keywords and built-ins that perform operations (e.g., print, import) Ø Data types that define values and text Ø Branching controls that change the statement execution sequence Ø Repetition controls that repeat a series of statements Ø Syntax rules for constructing valid statements Ø Terminology to describe language components and their functions 27 Your Toolbox Ø Coding tools: Ø For codifying an algorithm Ø Ex.: Visual Studio Code, PyCharm, Eclipse, Google Colab, Notepad++ Ø Build tools: Ø For transforming code into a binary format Ø Compiler creates machine code, the resulting file is executable Ø Python uses an interpreter Ø Debugging tools: Ø For testing and error identification Ø Ex.: Breakpoints, program animation 28 Next Week – What’s Coming Up? Ø Declare, initialize and manipulate variables Ø Explain significance of primitive data types Ø Demonstrate operational skills with mathematical operators and compound operators Ø Identify and manipulate character data and string data Ø Use built-in functions to manipulate strings Ø Explain meanings of coercion and typecasting in the context of data types 29 30

Use Quizgecko on...
Browser
Browser