Lec 4 Data Structures and Algorithm Analysis
Lec 4 Data Structures and Algorithm Analysis
Lec 4 Data Structures and Algorithm Analysis
•Algorithm Analysis.
Application/ Data
Data
Program
5
Data is classified into data types. e.g. char, float, int, etc.
A data type is (i) a domain of allowed values and (ii) a set
of operations on these values.
Compiler signals an error if wrong operation is performed
on data of a certain type. For example, char x,y,z; z =
x*y is not allowed.
6
Examples
7
Simple Data types: also known as atomic data
types have no component parts. E.g. int,
char, float, etc.
21 3.14 ‘a’
8
A particular way of storing and organizing data in a
computer so that it can be used efficiently and
effectively.
Data structure is the logical or mathematical model of
name.
◦ For example, an array of integers
Structured Data types: can be broken into
component parts. E.g. an object, array, set,
file, etc. Example: a student object.
NameA H M A D
Age 20
C S C
Branch
A Component part
10
Types of Data Structures
Array
Linked List
Queue Stack
Tree
Design Issue:
◦ select and design appropriate data types
(This is the main motivation to learn and understand
data structures)
(Demonstrate using class room
example!)
Navigating
Accessing each data element exactly once so
that certain items in the data may be processed
Searching
Finding the location of the data element (key)
in the structure
Insertion
Adding a new data element to the structure
Deletion
◦ Removing a data element from the structure
Sorting
◦ Arrange the data elements in a logical order
(ascending/descending)
Merging
◦ Combining data elements from two or more
data structures into one
A finite set of instructions which accomplish a particular
task
A method or process to solve a problem
Transforms input of a problem to output
Algorithm = Input + Process + Output
systematic way
Using pseudo-code, it is easier for a non-
programmer to understand the general workings of
the program
Use PLs construct that are consistent with
modern high level languages, e.g. C++,
Java, ...
Use appropriate comments for clarity
Be simple and precise
Expressions
Standard mathematical symbols are used
o Left arrow sign (←) as the assignment operator in assignment statements
(equivalent to the = operator in Java)
o Equal sign (=) as the equality relation in Boolean expressions (equivalent to the "=
=" relation in Java)
o For example
Sum ← 0
Sum ← Sum + 5
if condition then
true-actions
[else
false-actions]
We use indentation to indicate what actions should be included in the true-
actions and false-actions
For example