Transcript Lecture1

DATA STRUCTURES
1
INSTRUCTORS


Lectures:
 Dr. Shimaa Ibrahim Hassan
 Time: Monday @ 9:45
 [email protected][email protected]
Sections:
 Eng: Mohamed Hussien
 Time: Sec.1 Sunday @ 9:00
Sec.2 Tuesday @ 9:00
2
TEXTBOOKS

Main book:


Data Structures and Algorithms in C++, 2nd edition
Goodrich, Michael T.; Tamassia, Roberto; Mount,
David M.
My reference books:
ADTs, Data Structures, and Problem Solving with
C++, Prentice Hall, Larry Nyhoff
 Data Structures And Problem Solving Using C++,
Mark Allen Weiss
 Data Structures and Algorithms in Java, Robert
Lafore


Extra reference book:

The C++ Porgramming language, Addison Wesley,
Stroustrup --- creator of C++
3
COURSE OVERVIEW
A fundamental computer engineering course
- Essential for programming
- Essential for advanced courses
 A challenging course, which needs
- Mathematical and logic thinking
- Programming

4
COURSE PREREQUISITE

Programming skills





Basic mathematical skills


Need to know C++ or JAVA
PC programming environment
Good programming skills
Translate pseudo-codes into codes
Solving recursive equations, manipulation of symbols,
etc.
Computer architecture

Pointers, storage, memory access, etc.
5
ASSIGNMENTS
Lab assignments.
 Programming assignments

Due by time specified
 Run on PC
 Detailed analysis report


Late policy :





Must be submitted by 12:00 am of the due date
One day late costs 10% off
Two days late costs 20% off
Three days late costs 40 % off
Four days late is not accepted
6
COURSE OBJECTIVES

Study an effective programming method for
software projects of realistic size.
Difficulties arise not in finding a solution, but rather
in deciding on the best algorithm to use
 The greatest room for variability in algorithm design
is in the way in which the data are stored:

How they are arranged in relation to each other
 Which data are kept in memory
 Which are calculated when needed
 Which are kept in files, and how the files are arranged


Present several ideas for data organization and
several algorithms for important data processing
tasks such as sorting and searching.
7
COURSE OUTLINE










Program development process
Data modeling and ADT
OOP and classes
Arrays, Records and Sets
Linked Lists
Recursion
Stacks and Queues
Trees
Sorting and Searching
Graphs
8
GRADING SYSTEM
Final exam ..................................... 75 degrees
 Mid-term ...................................... 20 degrees
 Lab and practical exam.................. 20 degrees
 Project ........................................... 10 degrees

PROGRAM
DEVELOPMENT
PROCESS
10
SOFTWARE DEVELOPMENT CYCLE

Steps for writing small programs:







Get the assignment
Devise an algorithm for solving the problem
Express the algorithm as a computer program in a
specific language
Type the program into the computer
Compute the program; revise it to correct errors
(compiler errors)
Run the program with sample data; check for the
correct answers; correct the discovered errors (run
time errors)
Run the program with actual data and get the results
11
DEVELOPING A SOFTWARE SYSTEM

User requirement


System analysis


Between software team and user
Technical statement that shows the major
components of the system, data flow, required
outputs, errors to check for, procedures to follow,
constraints … etc.
System design
Choosing data types and algorithms for each major
component of the system specified in the pervious
stage.
 Breaking the system into small functions
 May include writing some pseudo codes.

12
DEVELOPING A SOFTWARE SYSTEM (CONT.)

Implementation
The designed system is translated into code in HLL
 Correcting the compiler’s error


Testing
Running the system with data for which the correct
results are known and check for the output results
and correcting the errors if found
 Running the system with some data containing
errors that requirements ask to be checked
 Running the system with real data supplied by the
client and fix errors if found.

13
DEVELOPING A SOFTWARE SYSTEM (CONT.)

Installation
The system and required software are placed on the
clients’ machines.
 The personnel who will operate the system are
trained


Maintenance

This term includes everything that is done to the
system after the user has accepted the initial version,
such as:
Correcting errors not detected earlier
 Adding new features
 Modification required related to H/W updates

14
CHARACTERISTICS OF A GOOD PROGRAM
Correctness
 Reliability

Correct output for correct input
 Meaningful error messages for incorrect input


Portability


Easily moved from one machine to another with
minimum modifications. Using popular programming
language and avoiding non-standard language
features
Maintainability

Easily to be maintained by achieving readability
feature
15
CHARACTERISTICS OF A GOOD PROGRAM
(CONT.)

Readability
Making the program easy to read by good program
design; using good comments and meaningful
variable names
 A readable program is:

More likely to be correct
 Faster and cheaper to test
 Faster and cheaper to maintain
 Faster and cheaper to modify


Use of resources

A good program is fast and uses minimum of storage
16
PROGRAMING STYLE






Choose meaningful names
Declare all constants in the declaration section
Minimize the number of global variables
Declare the variable wisely in the program to
minimize used resources
Use spaces, blank lines and end lines to promote
clarity
Use comments intelligently:
Detailed comment at the beginning of the program and
each function to describe their general purpose
 Inline comments as required


organize your program into functions, each with
coherent purpose

The main program should be mainly function calls
17
DATA MODELING &
ADTS
18
DATA MODELING
Real-world applications need to be reduced to a
small number of existing problems (top-down
design)
 Real-world data need to be described in an
abstract way in terms of fundamental structures
 The collection of data in some organization is
called a “Data Structure”
 The sequences of operations to be done on the
data are called “Algorithms”
 An Algorithm is a procedure to do a certain task
 An Algorithm is supposed to solve a general,
well-specified problem

19
DATA MODELING
A
real-world application is basically
Data Structures + Algorithms
 Data and the Operations on that data are
parts of an object that cannot be
separated.
 These two faces of an object are linked.
Neither can be carried out independently
of the other.
20
THE DATA CONE
Real-world Data
ADTs
Data Structures
Fundamental
Data
Types
21
ABSTRACT DATA TYPES
(ADTS)
The most important attribute of data is its type.
 Type implies certain operation. It also prohibits
other operations.
 For example, + - * / are allowed for types int and
double, but the modulus (%) is allowed for int
and prohibited for double.
 When a certain data organization + its operations
are not available in the language, we build it as a
new data type. To be useful to many applications,
we build it as an Abstract Data Type.

22
ABSTRACT DATA TYPES
(ADTS)



An ADT represents the logical or conceptual
level of the data.
It consists of:
1. A collection of data items in some Data
Structure
2. Operations (algorithms) on the data items
For example, a Stack supports retrieval in
LIFO (Last In First Out) order. Basic
operations are push and pop. It can be
implemented using arrays (static or dynamic)
or linked lists
23
ABSTRACT DATA TYPES (ADTS)
 The
Data Structure used in implementing
an ADT is usually dependent on the
language.
 In contrast, the definition of the ADT is
separated from its implementation (Data
Abstraction) e.g. ADT Stack can be
implemented using a static array, a
dynamic array or pointers.
 An ADT can be used in more than one
application.
24
USING ADT’S
ADT
ADT
Application
ADT
ADT
Application
Standard Types/Libraries
ADT
Application
User Built ADT’s
25
A CLASSIFICATION OF ABSTRACT
STRUCTURES

According to the relationship between
members
Abstract Structures
Sets
Linear
Trees
Graphs
26
SETS
 Order
of elements does not matter. Only
that they are members of the same set
({1,3,4} is identical to {1,4,3}).
 Can be implemented using arrays or
linked lists.
 Used


in problems seeking:
groups
collection
27
LINEAR STRUCTURES
Sequential, one-to-one relationship.
Examples:
Tables, Stacks, Queues, Strings
 Can be implemented using arrays and linked
lists (structs and pointers).


Used in problems dealing with:



Searching, Sorting, stacking, waiting lines.
Text processing, character sequences, patterns
Arrangements, ordering, tours, sequences.
28
TREES
 Non-Linear,
hierarchical one-to-many.
Examples:
Binary Trees, Binary Search Trees (BST)
 Can be implemented using arrays, structs
and pointers
 Used




in problems dealing with:
Searching
Hierarchy
Ancestor/descendant relationship
Classification
29
GRAPHS
 Non-Linear,
many-to-many.
 Can be implemented using arrays or
linked lists
 Used
to model a variety of problems
dealing with:





Networks
Circuits
Web
Relationship
Paths
30
31