Title: CSCE 210 Data Structures and Algorithms
1CSCE 210Data Structures and Algorithms
- Prof. Amr Goneid
- AUC
- Part 1. Introduction to S/W Design
2Introduction to S/W Design
- Software for Problem Solving
- Software Development Process
- Top-Down Design
- Elements of Module Design
- Example of a Design Document
31.Software for Problem Solving
Problem Domain
S/W
TO
Decide, Learn, View Interact, Play, .
42. Software Development Process
Specify Requirements
Solution Strategy
S/W Production
S/W Testing
Problem Definition
Maintenance Upgrade
5Software Production
Implementation (Programs)
Debugging
S/W Design
Performance Analysis / Benchmarks
63. Top-Down Design
- Divide and Conquer Strategy.
- Given problem X (Level 0). Divide it into
sub-problems X1, X2, , Xn (Level 1) such that
solving X1, then X2, then solves X completely. - Repeat for each sub-problem until we reach basic
or trivial implementation level.
7Top-Down Design
0
X
1
X1
X2
X3
Xn
2
X21
X22
. .
8Modules
Function Xi
Sub-Problem Xi
Implemented as
Main Function X
Main Problem X
Implemented as
94. Elements of Module Design
With What Resources? (Data)
What? Purpose
How? (Algorithm)
Module Design
10Elements of Module Design
Functional Specs
Data Specs
Algorithm Specs
Pseudo- code
11Elements of Module Design
- S/W Design for Each Module
- Functional Specifications the purpose of the
module and what it is supposed to do (What to do) - Data Specifications the data resources needed by
the module to achieve it functionality (with
what) - Algorithm Specification the algorithm or
methodology used by the module (How to do it) - In addition, for Each Module we should specify
- Precondition the state of processing or data
before the module is executed (state before) - Postcondition the state of processing or data
after the module is executed (state after)
12Some Guidelines for Module Design
- Transparency of Purpose
- Correctness
- Completeness
- Ease of Use
- Efficiency
- Writability
- Maintainability
135. Example of a Design Document
- Problem Definition
- To find the median of (n) integers.
- Requirement Specification
- - Input(s) n, and list of integers in random
order. - - Output(s) The median.
14Example(continued)
- Solution Strategy
- The median of a list of integers is an integer
below which and above which there is an equal
number of integers. To find the median of a list
of (n) integers - 1. Input random list of (n) integers
- 2. Sort list in ascending order.
- 3. Median is the integer at (n/2)
- 3. Print median.
15Example(continued)
- S/W Design
- Structured (Top-Down) Design
- Yields a main module, a sorting module, and a
median module.
main
sort
median
16Example(continued)
- Sorting Module sort( )
- Functional Specification
- Receives list, returns sorted list.
- Input (s) n and list
- Output (s) sorted list
- Precondition none
- Postcondition the list is sorted
- Data Specification
- No extra data needed
- Algorithm Specification
- Uses the method of Selection Sort.
17Example(continued)
- How selection sort works (optional)
- Assume list occupies locations 0.. n-1
- Repeat for list items k from 0 to n-2
- Assume smallest item to be at location (k)
- Examine items k1 to n-1 and find location of
smallest - Exchange that element with that at (k)
18Example(continued)
- Median Module median( )
- Functional Specification
- Receives sorted list, returns median.
- Input (s) n and list
- Output (s) median
- Precondition list is sorted
- Postcondition none
- Data Specification
- No extra data needed
- Algorithm Specification
- median is the element at (n/2) in the sorted
list
19Example(continued)
- Main Module main( )
- Functional Specification
- Inputs list, prints median.
- Input (s) n and list (form keyboard)
- Output (s) median (on screen)
- Precondition none
- Postcondition median is printed
- Data Specification
- - MAX 100 to represent maximum list size
- - An Array (a) of size MAX to store list.
- - n is the actual list size.
20Example(continued)
- main( ) (continued)
- Algorithm Specification
- Input n.
- Check that n does not exceed MAX.
- Input random list into array (a).
- Call sorting module.
- Call median module
- Display median
21Example (implementation)
- include ltiostreamgt
- using namespace std
- typedef int itemtype
- // Function Prototypes
- void sort (itemtype a , int n)
- itemtype median (itemtype a , int n)
- //________________________________________________
__________ - int main( ) // Start of main function
-
- const int MAX 100 // Data Declarations
- itemtype aMAX, m
- int k, n
- cin gtgt n // Read size of data
- if (n gt MAX) n MAX // to prevent array
overflow
22Example (implementation)
- for (k 0 k lt n k) cin gtgt ak // Read
data into array - sort(a,n) // Call sorting module
- m median(a,n) // Call median module
- cout ltlt m // Display median
- return 0
-
- //________________________________________________
___
23Example (implementation)
- void sort (itemtype a , int n) // Sort module
-
- // Selection Sort Algorithm
- // Precondition None
- // Postcondition Array a is sorted
- int k, j, min // Module Local Data
- itemtype temp
- for (k 0 k lt n-1 k )
-
- min k
- for ( j k1 j lt n j) if (aj lt amin )
min j - temp amin amin ak ak temp
-
-
- //________________________________________________
____
24Example (implementation)
- itemtype median (itemtype a , int n) //median
module -
- // Computes median
- // Precondition Array a is sorted
- // Postcondition None
- return (an/2)
-
- //________________________________________________
____
25Learn on your own about
- Waterfall and Spiral Models
- UML
- S/W system Life Cycle