Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Problem Solving: A Guide to Analyzing & Solving Problems with Algorithms & Flowcharts, Study Guides, Projects, Research of Programming Languages

An in-depth exploration of problem-solving techniques, including defining and analyzing problems, designing algorithms, coding, documenting programs, compiling and executing programs, testing, debugging, and maintaining programs. It covers various strategies for problem solving, such as divide and conquer, greedy method, dynamic programming, backtracking, and branch and bound. The document also includes examples and activities to help students understand the concepts.

Typology: Study Guides, Projects, Research

2021/2022

Uploaded on 02/17/2022

nguyen-ly-6
nguyen-ly-6 🇻🇳

4.8

(12)

41 documents

1 / 48

Toggle sidebar

Related documents


Partial preview of the text

Download Problem Solving: A Guide to Analyzing & Solving Problems with Algorithms & Flowcharts and more Study Guides, Projects, Research Programming Languages in PDF only on Docsity! Lecture 05: Problem Solving Ai UNIVERSITY of @s7 GREENWICH @ Pearson Alliance with ago. Education BT E C • Basic concepts of problem solving • Steps involved in program development • Top-down programming • Programming languages, their types, and features Objectives • There is no universal method for solving a given problem – Different strategies are good for different problems • Some of the well-known strategies are – Divide and conquer – Greedy method – Dynamic programming – Backtracking – Branch and Bound Strategies for problem solving • The various steps involved are – Defining or Analyzing the problem – Design (Algorithm) – Coding – Documenting the program – Compiling and running the program – Testing and Debugging – Maintenance Steps in Program Development • The problem is defined by doing a preliminary investigation • Defining a problem helps us to understand problem clearly • It is also known as Program Analysis Analyzing or Defining the Problem • The output specification is obtained by answering the following questions – What values will be produced? – What is the format of these values? – What specific annotation, headings, or titles are required in the report? – What is the amount of output that will be produced? Specifying the output requirements • The processing requirement is obtained by answering following questions – What is the method (technique) required in producing the desired output? – What are the validation checks that need to be applied to the input data? – What calculations are needed? Specifying the processing requirements (Bil UNIVERSITY of qs GREEN WICH @ Pearson Alliance with ago. Education BTEC ° Input? * Output? ¢ Process? Activity: Find Factorial Number (Ql UNIVERSITY of G@PcreNwich @ Pearson Main elements of use-case diagram Alliance with ago. Education BTEC Element Description Symbol Actor An actor is a person, organization, or external system that plays a role in one or more interactions with your system Actor Use-cases A use case describes a sequence of actions that provide something of measurable value to an actor Use Case Associations Associations between actors and use cases: An association exists whenever an actor is involved with an interaction described by a use case Some other The relationships among actors, or use-cases like ———_{> relationships | inheritance, extends, includes, etc. = === spineludeane == >> wore <<oxtonda>> ~~, System A rectangle around the use cases, called the system boundary boundary box, to indicates the scope of your system. boxes (optional) Packages UML constructs that enable you to organize model Cd (optional) elements (such as use cases) into groups package You are hired to develop FAI’s library system with following description - Admin who could - Manage books, readers (staff, lecturers, and students), etc. - Manage borrow/return books - Users (staff, lecturers, students) who could - View/search books - Reserve books - Borrow/return books Please draw Use-case diagram for this scenario Activity: Draw use-case diagram • A design is the path from the problem to a solution in code • The well designed program is likely to be: – Easier to read and understand later – Less of bugs and errors – Easier to extend to add new features – Easier to program in the first place Design • Please list the steps inside an algorithm to find factorial number of a positive integer Activity: Find factorial number • Step 1: Start • Step 2: Initialize factorial to be 1, i to be 1 • Step 3: Input a number n • Step 4: Check whether the number is 0. If so report factorial is 1 and go to step 9 • Step 5: Repeat step 6 through step 7 n times • Step 6: Calculate factorial = factorial * i • Step 7: Increment i by 1 • Step 8: Report the calculated factorial value • Step 9: Stop Activity: Find factorial number • Pseudo code is an informal high-level description of an algorithm – It uses the structural conventions of programming languages, but – It omits language-specific syntax • It is an outline of a program written in English or the user’s natural language Pseudo Code Gi UNIVERSITY o GD GREENWICH @ Pearson Flowchart symbols (1/2) Represents Start, End Represents Process (actions, calculations) Represents Decision Making - y Represents Input, Output data Represents Pre-defined Process / module GD UNIVERSITY of GO CREN cl @ Pearson Flowchart symbols (2/2) Represents off page connector which are used to indicate that the flow chart icontinues on another page. Page numbers are usually placed inside for easy reference. (Connector Symbol represents the exit to, or entry from, another part of the same flow chart. It is usually used to break a flow line that will be continued jelsewhere. | | (The Document Symbol is used to represent any type of hard copy input or loutput (i.e. reports). Represents control flow • Draw a flowchart for the algorithm to find factorial number in previous activity Activity: Drawing flowchart • Documentation comes in two forms – External documentation, which includes things such as reference manuals, algorithm descriptions, flowcharts, and project workbooks – Internal documentation, which is part of the source code itself (essentially, the declarations, statements, and comments) Forms of documentation • Compilation is a process of translating a source program into machine understandable form • The compiler is system software – It examines each instruction for its correctness – It does the translation • During the execution – Program is loaded into the computer’s memory – The program instructions are executed Compiling and Executing the Program • Testing is the process of executing a program with the deliberate intent of finding errors • Testing is needed to check whether the expected output matches the actual output • Testing is done during every phase of program development • Initially, requirements can be tested for its correctness • Then, the design (algorithm, flow charts) can be tested for its exactness and efficiency – Structured walk through is made to verify the design Testing • Debugging is a process of correcting the errors – Programs may have logical errors which cannot be caught during compilation – Debugging is the process of identifying their root causes – One of the ways is to print out the intermediate results at strategic points of computation – Another way is to use support from the IDE • Testing vs Debugging – Testing means detecting errors – Debugging means diagnosing and correcting the root causes Debugging • Program maintenance – Continuing process of maintenance and modification – To keep pace with changing requirements and technologies • Maintainability of the program is achieved by – Modularizing it – Providing proper documentation for it – Following standards and conventions (naming conventions, using symbolic constants, etc.) Maintenance • It is an art of making a computer to do the required operations – By means of issuing sequence of commands to it • It can be defined as – A vocabulary (unique set of characters/keywords) – A set of grammatical rules (syntax) • The term programming languages usually refers to high- level languages – E.g., BASIC, C, C++, COBOL, FORTRAN, Ada, and Pascal What is a Programming Language? • Every language has its strengths and weaknesses • FORTRAN is good for numeric data but not good to organize large program • PASCAL is good for structured and readable programs, but it is not as flexible as C • C++ has powerful object-oriented features, but it is complex and difficult to learn • The choice of PL depends on type of the computer used, type of program, and the expertise of the programmer What makes a good language? • Following are the most important features that would make a programming language efficient and easy to use: – Clarity, simplicity and Unity – Orthogonality – Naturalness for the application – Support for abstraction – Portability of Programs – Cost of use – Cost of Program Maintenance Criteria of efficient/easy to use • Programming on Host Environment: – The environment under which a program is designed, coded, tested & debugged • Operating on Target Environment – The external environment which supports the execution of a program Target Host/Target Environments Hello.c Hello.exe ll . ll . Hello.exe • Scoping is another technique that helps keep procedures modular – It prevents the procedure from accessing the variables of another procedures Procedures and modularity X = A; Y = B; C = A + B; A = 3 B = 4 C = 7 X • It has the ability to specify a simple interface, to be self- contained, and to be reused – Procedures are a convenient vehicle for making pieces of code written by different people or different groups, including through programming libraries Procedures and modularity • Procedural programming language is also imperative languages – They give commands to instruct computer to do things – They describe how computer should do things • Declarative programming languages like SQL just explain what should be done Imperative vs Declarative for (i = 0; i < n; i++) { if (a[i] == x) { printf(“found”); break; } } SELECT name from STUDENT WHERE id = ‘001’;
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved