SlideShare a Scribd company logo
DATA STRUCTURES AND
ALGORITHMSI (DSA010)
PREPARED BY BLASIUS K PINIAS
INTRODUCTION TO ALGORITHMS
• At the end of this Chapter, the student will student will be able to:
• Define an algorithm;
• Give examples of algorithms from daily life processes;
• Demonstrate an understanding of how algorithms are constructed;
• Define a program; and
• Identify Relationship between Algorithms and Programs.
• Demonstrate an understanding of Pseudo-code
DEFINITION OF AN ALGORITHM
• What is an algorithm?
• An algorithm can be defined as a sequence of instructions or a set of rules that are
followed to complete a task.
NB: This task can be anything, so long as you can give clear instructions for it.
In other words, an algorithm can also be defined as a step by step solution to a problem.
CHARACTERISTICS:
1. An algorithm should be finite
2. An algorithm should be unambiguous
3. An algorithm must always include all the finer details about a problem that should be solved. (Do
not omit any despite the fact that it may sound trivial)
4. Every algorithm can be transformed into an executable program
5. An algorithm may be written by one person but may in future be used by any other person whom
might not necessarily know how it was derived
6. When an algorithm is executed, it should always give a correct solution to a problem irrespective of
the changing data set as long as the data set belong to a specified data type that from which the
input data should be taken
7. An algorithm is often presented using either pseudo-code; flow charts or Nassi Schneiderman
Diagrams
WHY LEARN ALGORITHMS?
• Data Structures and Algorithms course is designed to prepare you for the
programming course. It is designed to give an understanding of how to make
a computer do anything.To make a computer do anything, you have to write a
computer program. To write a computer program, you have to tell the
computer, step by step, exactly what you want it to do. The computer then
"executes" the program, following each step mechanically, to accomplish the
end goal.
Figure .3 c) Executable file, which results
from the process of compiling
Algorithm to Source Code
DEFINE
• Source code –a text listing of commands to be compiled or assembled into an
executable computer program.
• A compiler is a computer program (or a set of programs) that transforms source
code written in a programming language (the source language) into another
computer language (the target language), with the latter often having a binary
form known as object code.
• A program is a set of instructions derived from a specific algorithm that is written in
a specific programming language.
RELATIONSHIP BETWEEN ALGORITHMS
AND PROGRAMS
• A program is an algorithm that is translated into a set of instructions that the CPU
can understand. A program is executed by a computer in order to give a solution to
a problem for which it was designed to solve. Algorithms are only turned into
programs once they are validated.
PSEUDO-CODE
• Pseudo-code (or Pseudo code) is an informal high-level description of the operating
principle of a computer program or other algorithm.
• The word Pseudo means false.
• Pseudo code is a standard way of representing algorithms.
PSEUDO-CODE
• Problem: Given any two whole numbers, find their sum.
• Algorithm:
. DATA TYPES AND DATA STRUCTURES
• A data type is a set of values that have common characteristics (they belong to the
same domain).
• Data structure is a particular way of organizing data in a computer so that it can
be used efficiently.
. DATA TYPES AND DATA STRUCTURES
Examples of data types:
1. Integers: Set of negative and positive whole numbers
2. Real: A set of all possible numbers including decimal/fractional numbers, also
referred to as floating point numbers.
3. Characters: A set of all possible symbols, including letters of the alphabet. All
symbols found on a computer keyboard including numbers and special signs are
characters.
4. String: Is a group of characters (2 or more) that are used to represent one value
5. Boolean: A set of two values that represent either a true or false situation.
.USER DEFINED DATA STRUCTURES:
can represent more than one value at a time.
Examples of user defined data types:
1. Array: is a data type that is derived from a specific simple data type (same
domain) but can store more than one value at time.
2. File/Record/Structure: A user defined composite data type that groups together
different data values from one or more domains into a single data type.
3. Union: A data type that can only keep one value from a set of specified possible
data types.
. VARIABLES, CONSTANTS AND LITERALS :
Variables and Constants
1. Variable Is a name given to a specific memory location that is reserved to
store/keep a value from a specific data type.
NB: The values kept in a variable may change during program execution.
1. Constant Is a name given to a specific memory location that is reserved to
store/keep a value that cannot change during program execution.
. DECLARING A VARIABLE
Is the process of reserving and naming the memory space that will be used to keep
values from a specific data type during program execution.
How are variables declared
Data_Type Variable_Name
For example, a variable X that keeps an integer value will be declared as
Integer X
. DECLARING A CONSTANTS
How to Declare Constants
1. Constant_name Value
E.g. Rate 2.5 1.
Typed constants are declared as follows:
Data_type Constant_name value
E.g.String institutionName “NSEA”
LITERALS
Literals : is A value written exactly as it's meant to be interpreted. In contrast, a
variable is a name that can represent different values during the execution of the
program. And a constant is a name that represents the same value throughout a
program.
But a literal is not a name -- it is the value itself.
For example, in an expression:
Integer x = 20
The value 20 is a literal, while x is a variable
NAMING CONVENTION FOR VARIABLES AND CONSTANTS
1. Variable or constant name should only be one word.
2. If two or more words are to be used as a variable or constant name, they should be
joined with an underscore e.g. Integer student_age
3. No variable or constant name should start with a number but with a letter from the
alphabet.
4. No two different variables have the same name (same spelling)
5. Some special symbols, e.g. +, -, ‘,/, *, should not be used in a variable name
6. Variable and constant names may consist of one or more letters of the alphabet
7. A number may only be used as part of a variable name only if it written after a letter(s)
of the alphabet.
PROBLEM SOLVING AND BASIC COMPUTER
OPERATIONS
• Seven Basic Steps that should be followed when solving a problem
namely:
Understand/Identify the problem
Outline aSolution
Develop the ouline into an algorithm
Test/Validate your algorithm
Transform your algorithm into a program using a specific programming language
Run/Execute your program
Install, document and maintain the program
PROBLEM SOLVING AND BASIC COMPUTER
OPERATIONS
• Seven Basic Steps that should be followed when solving a problem
At this stage the problem can be divided into three separate components
namely: Three basic stages that are followed by a computer when solving a
problem: 1. Input 2. Processes 3. Output
the inputs
the outputs, and the
processingsteps to produce the required outputs
1. UNDERSTAND/IDENTIFY THE
PROBLEM
STEPS IN ALGORITHM DEVELOPMENT CONTINUE...
• The solution outline developed in step 2 is then expanded into an
algorithm: a set of precise steps that describes exactly the tasks to be
performed and the order in which they are to be carried out. We will be
using pseudo code (a form of structured English) to represent the solution
algorithm. Flowcharts and Nassi-Schneidermann diagrams will also be
introduced as graphical methods of representation
3. DEVELOP THE OULINE INTO AN
ALGORITHM
STEPS IN ALGORITHM DEVELOPMENT
CONTINUE….
• One of the most important steps in the development of a program, often
referred to as desk checking. The main purpose of this step is to identify
major errors early, so that they may easily be corrected. It involves
walking with test data through the logic of the algorithm exactly as a
computer would, keeping track of major variables on a sheet of paper.
4. TEST/VALIDATE YOUR ALGORITHM
STEPS IN ALGORITHM DEVELOPMENT
CONTINUE….
• Only after all design considerations have been met in the previous four
steps, and after you tested whether your algorithm is really working you
should actually start coding the program in your chosen programming
language.
5. TRANSFORM YOUR ALGORITHM INTO A PROGRAM
USING A SPECIFIC PROGRAMMING LANGUAGE
STEPS IN ALGORITHM DEVELOPMENT
CONTINUE….
• This step uses a program compiler / interpreter and programmer-
designed test data to machine test the code for syntax and
syntax/compilation errors (those detected at compile time) and run-
time/logical errors (those detected at run time). At this stage there are
hopefully no logical errors anymore, because they ideally should have
been eradicated in step 4.
6. RUN/EXECUTE YOUR PROGRAM
STEPS IN ALGORITHM DEVELOPMENT
CONTINUE….
• Documentation involves both external documentation (such as hierarchy charts,
the solution algorithm, and the test data results), and internal documentation that
may have been coded in the program. Program maintenance refers to changes
which may need to be made to the program throughout its life cycle.
7. INSTALL, DOCUMENT AND MAINTAIN THE
PROGRAM

More Related Content

PPTX
wCIHc9AaI fgn gfgjhgf bxn ffbb fv .pptx
PPTX
05fghsdgsgrg dxgs sdgfs sdgfd sdgs.pptx
PPTX
Data Structures Unit 1 bnmxc xgfh (1).pptx
PPTX
Programming II - Introductio bncvfh dgdgn.pptx
PPTX
Week 1fah xzvfsgds sdfasdfsfg dsaewag.pptx
PDF
DATA STRUCTURES AND ALGORITHMSI (DSA010).pdf
PDF
DATAND ALGORITHMSI (DSA010)_LESSON 1.pdf
PDF
DPG Class Reps Information 2gffd5 v1.pdf
wCIHc9AaI fgn gfgjhgf bxn ffbb fv .pptx
05fghsdgsgrg dxgs sdgfs sdgfd sdgs.pptx
Data Structures Unit 1 bnmxc xgfh (1).pptx
Programming II - Introductio bncvfh dgdgn.pptx
Week 1fah xzvfsgds sdfasdfsfg dsaewag.pptx
DATA STRUCTURES AND ALGORITHMSI (DSA010).pdf
DATAND ALGORITHMSI (DSA010)_LESSON 1.pdf
DPG Class Reps Information 2gffd5 v1.pdf

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
1_English_Language_Set_2.pdf probationary
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Trump Administration's workforce development strategy
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
IGGE1 Understanding the Self1234567891011
PDF
Empowerment Technology for Senior High School Guide
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Classroom Observation Tools for Teachers
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Lesson notes of climatology university.
Supply Chain Operations Speaking Notes -ICLT Program
1_English_Language_Set_2.pdf probationary
Chinmaya Tiranga quiz Grand Finale.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Trump Administration's workforce development strategy
Weekly quiz Compilation Jan -July 25.pdf
RMMM.pdf make it easy to upload and study
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
IGGE1 Understanding the Self1234567891011
Empowerment Technology for Senior High School Guide
A systematic review of self-coping strategies used by university students to ...
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Hazard Identification & Risk Assessment .pdf
Classroom Observation Tools for Teachers
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Lesson notes of climatology university.
Ad
Ad

DATA STRUCTURES AND ALGORITHMSI (DSA010)_LESSON 1.pdf

  • 1. DATA STRUCTURES AND ALGORITHMSI (DSA010) PREPARED BY BLASIUS K PINIAS
  • 2. INTRODUCTION TO ALGORITHMS • At the end of this Chapter, the student will student will be able to: • Define an algorithm; • Give examples of algorithms from daily life processes; • Demonstrate an understanding of how algorithms are constructed; • Define a program; and • Identify Relationship between Algorithms and Programs. • Demonstrate an understanding of Pseudo-code
  • 3. DEFINITION OF AN ALGORITHM • What is an algorithm? • An algorithm can be defined as a sequence of instructions or a set of rules that are followed to complete a task. NB: This task can be anything, so long as you can give clear instructions for it. In other words, an algorithm can also be defined as a step by step solution to a problem.
  • 4. CHARACTERISTICS: 1. An algorithm should be finite 2. An algorithm should be unambiguous 3. An algorithm must always include all the finer details about a problem that should be solved. (Do not omit any despite the fact that it may sound trivial) 4. Every algorithm can be transformed into an executable program 5. An algorithm may be written by one person but may in future be used by any other person whom might not necessarily know how it was derived 6. When an algorithm is executed, it should always give a correct solution to a problem irrespective of the changing data set as long as the data set belong to a specified data type that from which the input data should be taken 7. An algorithm is often presented using either pseudo-code; flow charts or Nassi Schneiderman Diagrams
  • 5. WHY LEARN ALGORITHMS? • Data Structures and Algorithms course is designed to prepare you for the programming course. It is designed to give an understanding of how to make a computer do anything.To make a computer do anything, you have to write a computer program. To write a computer program, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal.
  • 6. Figure .3 c) Executable file, which results from the process of compiling Algorithm to Source Code
  • 7. DEFINE • Source code –a text listing of commands to be compiled or assembled into an executable computer program. • A compiler is a computer program (or a set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language), with the latter often having a binary form known as object code. • A program is a set of instructions derived from a specific algorithm that is written in a specific programming language.
  • 8. RELATIONSHIP BETWEEN ALGORITHMS AND PROGRAMS • A program is an algorithm that is translated into a set of instructions that the CPU can understand. A program is executed by a computer in order to give a solution to a problem for which it was designed to solve. Algorithms are only turned into programs once they are validated.
  • 9. PSEUDO-CODE • Pseudo-code (or Pseudo code) is an informal high-level description of the operating principle of a computer program or other algorithm. • The word Pseudo means false. • Pseudo code is a standard way of representing algorithms.
  • 10. PSEUDO-CODE • Problem: Given any two whole numbers, find their sum. • Algorithm:
  • 11. . DATA TYPES AND DATA STRUCTURES • A data type is a set of values that have common characteristics (they belong to the same domain). • Data structure is a particular way of organizing data in a computer so that it can be used efficiently.
  • 12. . DATA TYPES AND DATA STRUCTURES Examples of data types: 1. Integers: Set of negative and positive whole numbers 2. Real: A set of all possible numbers including decimal/fractional numbers, also referred to as floating point numbers. 3. Characters: A set of all possible symbols, including letters of the alphabet. All symbols found on a computer keyboard including numbers and special signs are characters. 4. String: Is a group of characters (2 or more) that are used to represent one value 5. Boolean: A set of two values that represent either a true or false situation.
  • 13. .USER DEFINED DATA STRUCTURES: can represent more than one value at a time. Examples of user defined data types: 1. Array: is a data type that is derived from a specific simple data type (same domain) but can store more than one value at time. 2. File/Record/Structure: A user defined composite data type that groups together different data values from one or more domains into a single data type. 3. Union: A data type that can only keep one value from a set of specified possible data types.
  • 14. . VARIABLES, CONSTANTS AND LITERALS : Variables and Constants 1. Variable Is a name given to a specific memory location that is reserved to store/keep a value from a specific data type. NB: The values kept in a variable may change during program execution. 1. Constant Is a name given to a specific memory location that is reserved to store/keep a value that cannot change during program execution.
  • 15. . DECLARING A VARIABLE Is the process of reserving and naming the memory space that will be used to keep values from a specific data type during program execution. How are variables declared Data_Type Variable_Name For example, a variable X that keeps an integer value will be declared as Integer X
  • 16. . DECLARING A CONSTANTS How to Declare Constants 1. Constant_name Value E.g. Rate 2.5 1. Typed constants are declared as follows: Data_type Constant_name value E.g.String institutionName “NSEA”
  • 17. LITERALS Literals : is A value written exactly as it's meant to be interpreted. In contrast, a variable is a name that can represent different values during the execution of the program. And a constant is a name that represents the same value throughout a program. But a literal is not a name -- it is the value itself. For example, in an expression: Integer x = 20 The value 20 is a literal, while x is a variable
  • 18. NAMING CONVENTION FOR VARIABLES AND CONSTANTS 1. Variable or constant name should only be one word. 2. If two or more words are to be used as a variable or constant name, they should be joined with an underscore e.g. Integer student_age 3. No variable or constant name should start with a number but with a letter from the alphabet. 4. No two different variables have the same name (same spelling) 5. Some special symbols, e.g. +, -, ‘,/, *, should not be used in a variable name 6. Variable and constant names may consist of one or more letters of the alphabet 7. A number may only be used as part of a variable name only if it written after a letter(s) of the alphabet.
  • 19. PROBLEM SOLVING AND BASIC COMPUTER OPERATIONS • Seven Basic Steps that should be followed when solving a problem namely: Understand/Identify the problem Outline aSolution Develop the ouline into an algorithm Test/Validate your algorithm Transform your algorithm into a program using a specific programming language Run/Execute your program Install, document and maintain the program
  • 20. PROBLEM SOLVING AND BASIC COMPUTER OPERATIONS • Seven Basic Steps that should be followed when solving a problem At this stage the problem can be divided into three separate components namely: Three basic stages that are followed by a computer when solving a problem: 1. Input 2. Processes 3. Output the inputs the outputs, and the processingsteps to produce the required outputs 1. UNDERSTAND/IDENTIFY THE PROBLEM
  • 21. STEPS IN ALGORITHM DEVELOPMENT CONTINUE... • The solution outline developed in step 2 is then expanded into an algorithm: a set of precise steps that describes exactly the tasks to be performed and the order in which they are to be carried out. We will be using pseudo code (a form of structured English) to represent the solution algorithm. Flowcharts and Nassi-Schneidermann diagrams will also be introduced as graphical methods of representation 3. DEVELOP THE OULINE INTO AN ALGORITHM
  • 22. STEPS IN ALGORITHM DEVELOPMENT CONTINUE…. • One of the most important steps in the development of a program, often referred to as desk checking. The main purpose of this step is to identify major errors early, so that they may easily be corrected. It involves walking with test data through the logic of the algorithm exactly as a computer would, keeping track of major variables on a sheet of paper. 4. TEST/VALIDATE YOUR ALGORITHM
  • 23. STEPS IN ALGORITHM DEVELOPMENT CONTINUE…. • Only after all design considerations have been met in the previous four steps, and after you tested whether your algorithm is really working you should actually start coding the program in your chosen programming language. 5. TRANSFORM YOUR ALGORITHM INTO A PROGRAM USING A SPECIFIC PROGRAMMING LANGUAGE
  • 24. STEPS IN ALGORITHM DEVELOPMENT CONTINUE…. • This step uses a program compiler / interpreter and programmer- designed test data to machine test the code for syntax and syntax/compilation errors (those detected at compile time) and run- time/logical errors (those detected at run time). At this stage there are hopefully no logical errors anymore, because they ideally should have been eradicated in step 4. 6. RUN/EXECUTE YOUR PROGRAM
  • 25. STEPS IN ALGORITHM DEVELOPMENT CONTINUE…. • Documentation involves both external documentation (such as hierarchy charts, the solution algorithm, and the test data results), and internal documentation that may have been coded in the program. Program maintenance refers to changes which may need to be made to the program throughout its life cycle. 7. INSTALL, DOCUMENT AND MAINTAIN THE PROGRAM