You are on page 1of 28

# DATA STRUCTURE

## It is a way of storing data in a computer

so that it can be used efficiently.
Is a collection of data objects and a set of
legal operations to be performed on
them.
method of organizing large amounts of
data
Filing cabinets with alphabetized folders
The correct choice of data structure
allows major improvements in program
efficiency.

ALGORITHM
manipulate the data in these structures in
various ways, such as inserting anew data item,
searching for a particular item, or sorting the
items.
You can think of analgorithm as a recipe: a list
of detailed instructions for carrying out an
activity.
Step-by-step procedure used to solve a
problem
These steps should be capable of being
performed by a machine
Must eventually stop and so produce an answer
WHAT SORTS OF PROBLEMS CAN YOU
SOLVE WITH A KNOWLEDGE OF THESE
TOPICS?

theyre useful into three categories:

- Real-world data storage
- Programmers tools
- Modeling
REAL-WORLD DATA STORAGE
Some examples are a personnel record that
describes an actual human being, an inventory
record that describes an existing car part or grocery
item, and a financial transaction record.
A non-computer example of real-world data storage
is a stack of index cards.(address book or home
inventory)
PROGRAMMERS TOOLS

Not all data storage structures are used to store
real-world data.
Typically, real-world data is accessed more or less
directly by a programs user.
However, some data storage structures are not
meant to be accessed by the user, but by the
program itself.
A programmer uses such structures as tools to
facilitate some other operation.
Stacks, queues, and priority queues are often used
in this way.
REAL-WORLD MODELING

Some data structures directly model a real-world
situation.
Stacks, queues, and priority queues are often used
for this purpose.
A queue, for example, can model customers waiting
in line at a bank, whereas a priority queue can
model messages waiting to be transmitted over a
local area network
OVERVIEW OF DATA STRUCTURE
OVERVIEW OF DATA STRUCTURE
OVERVIEW OF ALGORITHM
Many of the algorithms apply directly to specific
data structures.
For most data structures, you must know how to do
the following:
Insert a new data item.
Search for a specified item.
Delete a specified item.
traverse through all the items in a data structure
Sorting
Recursion
ALGORITHM ANALYSIS

Analysis:
How to predict an algorithms performance
How well an algorithm scales up
How to compare different algorithms for a problem
Data Structures
How to efficiently store, access, manage data
Data structures effect algorithms performance

EXAMPLE ALGORITHMS
Two algorithms for computing the Factorial
Which one is better?

int factorial (int n) {
if (n <= 1) return 1;
else return n * factorial(n-1);
}

int factorial (int n) {
if (n<=1) return 1;
else {
fact = 1;
for (k=2; k<=n; k++)
fact *= k;
return fact;
}
}

EXAMPLES OF FAMOUS ALGORITHMS
Constructions of Euclid
Newton's root finding
Fast Fourier Transform
Compression (Huffman, Lempel-Ziv, GIF, MPEG)
DES, RSA encryption
Simplex algorithm for linear programming
Shortest Path Algorithms (Dijkstra, Bellman-Ford)
Error correcting codes (CDs, DVDs)
TCP congestion control, IP routing
Pattern matching (Genomics)
Search Engines

ROLE OF ALGORITHMS IN MODERN
WORLD
Enormous amount of data
E-commerce (Amazon, Ebay)
Network traffic (telecom billing, monitoring)
Database transactions (Sales, inventory)
Scientific measurements (astrophysics, geology)
Sensor networks. RFID tags
Bioinformatics (genome, protein bank)

Amazon hired first Chief Algorithms Officer
(Udi Manber)

A REAL-WORLD PROBLEM
Communication in the Internet
Message (email, ftp) broken down into IP
packets.
The packets are routed through the Internet by
special computers called Routers.
Each packet is stamped with its destination
Because the Internet topology and network load
is constantly changing, routers must discover
routes dynamically.
What should the Routing Table look like?
HOW TO MEASURE ALGORITHM
PERFORMANCE
What metric should be used to judge
algorithms?
Length of the program (lines of code)
Ease of programming (bugs, maintenance)
Memory required
Running time

Running time is the dominant standard.
Quantifiable and easy to compare
Often the critical bottleneck

PRIMITIVE TYPES
are data types provided by a
programming language as basic
building blocks. Primitive types are
also known as built-in types or basic
types.
PRIMITIVE TYPES
Character
Integer
String
Double
Float
Array

SPECIAL TYPES
Character
It is a unit of information that roughly
corresponds to a grapheme, grapheme-like
unit, or symbol. Such as in an alphabet or
syllabary.

Ex. Letter
Numeral
Punctuation Mark

Integer
Is used to refer a data type which
represents some finite subset of
mathematical integers.
Also known as integral data types.

Integral Types:
Unsigned
Signed

Binary Coded Decimal
It is another representation of
integer which is commonly used
in mainframe financial
applications and in database.

String
Is an ordered sequence of symbols.

Binary string

Byte string
Are used to suggest strings
in which the stored data does
not represent text.
Double
Double precision is a computer
numbering format that occupies two
memory.

Double
or
Double precision number
Defined to be
an integer,
fixed point, or
floating point.
Float
describes a system for numerical
representation in which a string of
digits (or bits) represents a real
number.
The term floating point refers to the
fact that the radix point (decimal point,
or, more commonly in computers,
binary point) can "float": that is, it can
be placed anywhere relative to the
significant digits of the number
Array
Is a data structure consisting of a
group that are accessed by
indexing.

Classification of Array
Fixed-sized arrays
Dynamic arrays
DIFFERENT ALGORITHMS FOR
SAME PROBLEM
Devise an algorithm to find the solution to a number
raised to a positive power
eg 4
5
or 10
3
ie number
power
2 Loop 1 to power times
Notice the
layout and
numbering
FIND THE RESULT OF NUMBER
POWER
2 Loop for 1 to 5 times
2
1 1
2 2
4 3
8 4
16 5
32 ?
2
5
3
4
2 Loop for 1 to 4 times
3
Loop
1 1
3 2
9 3
27 4
81 ?