Professional Documents
Culture Documents
Eastern Visayas State University (EVSU) Master of Science in Information Technology Lecturer: Cesar A. Silay, MSIT
An algorithm is a list of instructions for carrying out some process step by step. It can also be defined as a finite set of instructions to be carried out in order to solve a problem. In other words, an algorithm is a recipe for solving the problem. Two ways of representing algorithms: 1. Pseudocode consists of English-like phrases written in a sequence of lines. Example: A pseudocode for getting the sum of two numbers. Input the first number. Store it in X. Input the second number. Store it in Y. Add X and Y and store the result in SUM. Display the value of SUM.
2. Flowchart a two-dimensional representation of an algorithm which uses predefined graphic symbols. There are 2 kinds of flowcharts: program flowchart describes graphically in detail the logical operations and steps within a program and the sequence in which these steps are to be executed for the transformation of data to produce the needed output. system flowchart portrays the interaction among data, hardware, and personnel. It illustrates more on the components of the system used and little is shown about how processing will be accomplished. This type of flowchart is mainly used for systems analysis and design courses.
Data structures organize data more efficient programs. More powerful computers more complex applications. More complex applications demand more calculations. Complex computing tasks are unlike our everyday experience.
Organizing Data
Any organization for a collection of records can be searched, processed in any order, or modified. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.
6
Efficiency
A solution is said to be efficient if it solves the problem within its resource constraints.
Space Time
The cost of a solution is the amount of resources that the solution consumes.
10
11
12
13
14
If the database is created once and then never changed, a simple linear index would be more appropriate.
15
21
Data Structure
A data structure is the physical implementation of an ADT.
Each operation associated with the ADT is implemented by one or more subroutines in the implementation.
In a OO language such as C++, an ADT and its implementation together make up a class. Data structure usually refers to an organization for data in main memory. File structure: an organization for data on peripheral storage, such as a disk drive.
22
Ex1: transistors gates CPU. In a program, implement an ADT, then think only about the ADT, not its implementation.
23
25
26
Problems
Problem: a task to be performed.
Best thought of as inputs and matching outputs. Problem definition should include constraints on the resources that may be consumed by any acceptable solution.
27
Problems (cont)
Problems mathematical functions
A function is a matching between inputs (the domain) and outputs (the range). An input to a function may be single number, or a collection of information. The values making up an input are called the parameters of the function. A particular input must always result in the same output every time the function is computed.
28
An algorithm takes the input to a problem (function) and transforms it to the output.
A mapping of input to output.
Algorithm Properties
An algorithm possesses the following properties:
It must be correct. It must be composed of a series of concrete steps. There can be no ambiguity as to which step will be performed next. It must be composed of a finite number of steps. It must terminate.
A computer program is an instance, or concrete representation, for an algorithm in some programming language.
31
Programs
A computer program is a concrete representation of an algorithm in some programming language. Naturally, there are many programs that are instances of the same algorithms, since any modern programming language can be used to implement any algorithm.
32
To Summarize:
A problem is a function or a mapping of inputs to outputs. An algorithm is a recipe for solving a problem whose steps are concrete and ambiguous. A program is an instantiation of an algorithm in a computer programming language.
33
Example
Problem: find y = x to the power of 2 Algorithm1: Multiply X by X Algorithm2: Add X to itself X times Program1: for (int i = 0; i<x; i++) y +=x;
34
Example (cont.)
Program2: (Assembly Intel 8086) mov bl,x // read x mov al,bl // store x mov cl,bl // int counter loop: add al,bl // al = al + x dec cl // decrement loop ctr jnz loop
35
Activity
Write a turbo c program that will ask the user to count number of vowels.
36