Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... ·...

28
Introduction to Data Structures & Algorithms SCSJ2013 Data Structures & Algorithms Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi Faculty of Computing

Transcript of Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... ·...

Page 1: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Introduction to

Data Structures & Algorithms SCSJ2013 Data Structures & Algorithms

Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi

Faculty of Computing

Page 2: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Objectives:

problem solving

algorithm concept

data structure concept

Page 3: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Problem Solving

Taking the statement of a problem and develop a computer program to solve problems.

The entire process requires to pass many phases

understanding the problem

design solution

implement the solution

Page 4: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Problem Solving

A solution to a problem is computer program written in programming language which consist of modules.

Type of Modules:

function method class

several functions or classes

other

Page 5: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Problem Solving

A good solution consists of Modules that

– organize data collection to facilitate operations

– must store, move, and alter data

– use algorithms to communicate with one another

Advantage of module:

Constructing

programs Debugging programs

Reading programs

Modifying programs

Eliminating redundant

code

Page 6: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Problem Solving - Modularity

Example

book

title

year

author

publisher

price

getData()

print()

checkPrice()

checkPublisher()

produce

author

firstName

secondName

getData()

print()

write()

edit()

Page 7: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Algorithm

Module implements algorithms

Algorithm

step-by-step recipe for performing a task

operate on a collection of data

problem solving using logic

Page 8: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Algorithm

Well-defined instructions in algorithm

includes:

1. when given an initial state (INPUT)

2. proceed through a well-defined series of

successive states (PROCESS)

3. eventually terminating in an end-state

(OUTPUT)

Page 9: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Algorithm

Page 10: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Algorithm

3 types of algorithm basic control structure

Sequential Selection Repeatition

Basic algorithm characteristics

Finite solution

Clear instructions

Has input Has output Operate

effectively

Page 11: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Algorithm

The techniques to design algorithm are such as: – Flowchart, pseudo code, State machine and others

Factors for measuring good algorithm

Running time Total memory

usage

Page 12: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Data Structure

Data Structure

– A way of storing and organizing data in a

computer so that it can be used efficiently

Choosing the right data structure will allow the most

efficient algorithm to be used

A well-designed data structure :

– allows a variety of critical operations to be

performed

– enable to use few resources (for both execution

time and memory space as possible)

Page 13: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Data Structure

Operations to the Data Structure

Traversing

Searching

Insertion

Deletion

Sorting

Merging

Page 14: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Data Types

• 2 data types

• Basic Data Types (C++) – store only a single data – Integral

• Boolean – bool

• Enumeration – enum

• Character - char

• Integer – short, int, long

• Floating point – float, double

Basic data types

Structured data types

Page 15: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Structured Data Types

Storage

Structure

Linked

Structure

State

Structure

•Array

•Structure

(struct)

•Unsorted

Linked List •Sorted Linked

List

•Binary Tree

•Graph

•Network

•Stack •Queue

Data Types

Page 16: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Storage Structure

Storage Structure

– Array

– Structure

typedef struct {

int age;

char name[25];

enum {male, female} gender;

} Person;

Person student[30];

Page 17: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Linked Data Structure

Linear Data Structure with

restriction

Queue

Stack

Linear Data Structure with no restriction

Unsorted linked list

Sorted linked list

Non-linear Data Structure

Tree

Graph

Page 18: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Linear Data Structure with restriction

Queue

In

Out

Back Front

Page 19: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Queue Application

Page 20: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Linear Data Structure with restriction Stack

In Out

Top

Page 21: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Stack Application

Page 22: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Linear Data Structure with no

restriction

3 12 11

Linked list

Page 23: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Linear Data Structure with no

restriction Sorted linked list

– Data stored in ascending or descending order

with no duplicates

– Insertion at front, middle or rear of the list

– Deletion will not affect the ascending /

descending order of the list

Unsorted linked list

– A linked list with no ordering

Page 24: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Non-linear Data Structure

Root

leaf

Children of node 2

vertex

Sibling

Tree

Page 25: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Non-linear Data Structure

Directed Undirected graph

Graph

Page 26: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Non-linear Data Structure

Weighted network

Page 27: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Conclusion In this class you have learned about:

• Problem solving is the entire process of taking the

statement of a problem and develop a computer

program to solve problems.

• Algorithm is step-by-step recipe for performing a

task operate on a collection of data

• Data structure is a way of storing and organizing

data in a computer, it allows efficient algorithm to

be used

• The knowledge given is to ensure that you are able

to provide good solution to problem solving

Page 28: Introduction to Data Structures & Algorithmsocw.utm.my/file.php/298/notes/01-Introduction_to... · Data Structure Data Structure –A way of storing and organizing data in a computer

Thank You

http://comp.utm.my/