Chapter 1 - Overview of Algorithm and Data Structures
Chapter 1 - Overview of Algorithm and Data Structures
ALGORITHM AND
DATA STRUCTURE
CHAPTER 1 :
OVERVIEW OF ALGORITHM AND DATA
STRUCTURES
SUMMARY
This topic covers on roles of algorithm and
overview of data structures.
COURSE OUTLINE
1.1 Understand Algorithm
1.1.1 Identify the characteristics of algorithm.
1.1.2 Describe the role of algorithm in problem
solving.
What is Algorithm?
- Algorithm is a clearly specified finite set of
instructions a computer follows to solve a
problem.
- An algorithms also can be defined as a step-by-
step procedure for solving a problem. It helps the
user arrive at the correct result in a finite number
of steps.
1.1 UNDERSTAND ALGORITHM
1.1.1 The characteristics of algorithm
1. Precision:
The steps are precisely stated(defined).
2. Uniqueness:
Results of each step are uniquely defined and only depend
on the input and the result of the preceding steps.
3 Finiteness:
The algorithm stops after a finite number of instructions
are executed.
1.1 UNDERSTAND ALGORITHM
1.1.1 Identify the characteristics of algorithm
4. Input:
The algorithm receives input.
5. Output:
An algorithm produces at least one output.
6 Generality:
The algorithm applies to a set of inputs.
1.1 UNDERSTAND ALGORITHM
1.1.1 Identify the characteristics of algorithm
iv. With the use of an algorithm, the same specified steps are
used for performing the tasks. This makes the process more
consistent and reliable.
1.2 UNDERSTAND DATA STRUCTURES
Dynamic
- The data structure is allowed to grow and shrink as the
demand for storage arises.
- The programmer should also set a maximum size to help
avoid memory collisions.
1.2 UNDERSTAND DATA STRUCTURES
1.2.2 Identify the types Data Structures
Example
1.2 UNDERSTAND DATA STRUCTURES
Example (Static)
1.2 UNDERSTAND DATA STRUCTURES
Example (Dynamic)
1.2 UNDERSTAND DATA STRUCTURES
Advantage and Disadvantage of Static vs. Dynamic
1.2 UNDERSTAND DATA STRUCTURES
Declaring Structure:
- Structure is a collection of related data items using one
similar name.
- The elements of structure, known as members can be of
different data types.
- Each structure you define can have an associated structure
name which is referred to as structure tag.
- To declare a structure, use the struct statement. It
declares a new data type, with more than one member.
1.2 UNDERSTAND DATA STRUCTURES
Declaring Structure: Cont..
- Syntax:
- Example:
1.2 UNDERSTAND DATA STRUCTURES
Declaring Structure:
- Declare a structure to illustrate student details contained information such as name, Id, Class and Session and CGPA.
1.2 UNDERSTAND DATA STRUCTURES
Declaring Structure: Case Study
- Declare a structure called AddressInfo which holds an info such as address, town, state, and postcode.
1.2 UNDERSTAND DATA STRUCTURES