Escolar Documentos
Profissional Documentos
Cultura Documentos
Unit 1
General Concepts
References
UNIT 1: GENERAL CONCEPTS
Basic references
B. Meyer, Construccin de Software Orientado a Objetos, Captulo 6: Tipos
Abstractos de Datos. Segunda edicin, Prentice-Hall (1999)
M. T. Goodrich & R. Tamassia, Data Structures and Algorithms in Java,
Chapter 4 6th Edition. International Student Version, John Wiley (2011).
PowerPoint PDF Handouts:
http://bcs.wiley.com/hebcs/Books?action=chapter&bcsId=8950&itemId=1118808576&chapterId=1
01146
Specific references
J. V. Guttag, E. Horowitz and D. R. Musser, Abstract Data Types and the
Development of Data Structures, Communications of ACM, 20, 396-404 (1977)
J. V. Guttag, E. Horowitz and D. R. Musser, Abstract Data Types and Software
Validation, Communications of ACM, 21, 1048-1064 (1978)
Outline
UNIT 1: GENERAL CONCEPTS
1. Introduction
2. Data structures and Abstract Data Types (ADTs)
3. ADTs specification
3.1. UML based specification
3.2. Algebraic specification
3.2.1. Syntactic specification
3.2.2. Semantic specification
4. Analysis of algorithms
4.1. RAM model
4.2. Primitive operations
4.3. Big-Oh notation
4.4. Asymptotic analysis
5. Useful tips (reminder)
1. Introduction (I)
This is a course about what in computer science are called data
structures. What is that?
A data structure is a data container (it stores and supplies data).
A data structure is related to the concepts of data type and abstract
data type.
Remember, a data type represents a set of values (recall the
primitive data types).
A structured data is a set of variables of, possibly, different data
types.
1. Introduction (II)
Data structures are fundamental components of algorithms (which
are specifically considered in Programming
Methodology/Metodologa de la Programacin in the second
semester).
In this course, we will consider the most common data structures:
Data structures
Linear
Trees
Lists
Stacks
Nonlinear
Graphs
Queues
1. Introduction (III)
Very important: THIS COURSE IS NOT FOCUSED ON
PROGRAMMING.
Programming will be mainly a tool for implementing examples
using data structures.
The goal is not, specifically, to implement data structures.
In fact, most of the data structures are already available in standard
packages.
Lets consider in more detail both, data structures and abstract data
types.
10
You NEVER work with an ADT (data structure) by accessing its data
because those data depend on the implementation used.
However, the operations do not depend on the implementation.
11
3. ADTs specification
How can we describe, specify, the behavior of an ADT?
The basic idea is to be able to describe the operations of the ADT
(remember, the ADT is defined by its operations not by its data).
12
Thus, we can specify the data that the method acts on (the formal
parameters) and the result produced (the return type).
We should specify every method (operation) associated to the ADT.
However, the most complete (sometimes too complete)
specification method is the traditional algebraic specification.
13
14
15
16
Partial
functions
Syntax
17
18
true
false
top(init)
top(push(p, e))
error
e
size (init)
size (push(p, e))
0
size (p)+1
pop(init)
pop(push(p, e))
error
p
19
Running Time
best case
average case
worst case
120
100
80
60
40
20
0
1000
2000
3000
4000
Input Size
20
15
25
125
32
33
100
10
10
100
664
104
106
1030
1000
1000
10
104
106
109
10300
10000
10000
13
105
108
1012
103000
log n n log n
10
10
100
21
22
23
24
25
26
Evaluating an expression
Assigning a value to a variable
Indexing into an array
Calling a method
Returning from a method
27
# operations
2
2n+1
2(n 1)
2(n 1)
2(n 1)
1
Total 8n 2
Best case? We never execute currentMax A[i]
Total 6n
28
3n
2n+
10
n
1.000
10
1
1
10
100
1.000
From n=10, the growth rate is the same for the two functions.
Escuela Superior de Informtica de Ciudad Real (UCLM)
29
f(n) is O(g(n))
g(n) is O(f(n))
Yes
No
No
Yes
Same growth
Yes
Yes
30
Example:
We determine that algorithm arrayMax executes at most 8n 2
primitive operations.
T(n) = 8n when n
We say that algorithm arrayMax runs in O(n) time
31
Class definition
Inheritance
Polymorphism
Interfaces
Exceptions
Generics
Linked list/variables
32
Recommended activities
UNIT 1: GENERAL CONCEPTS
Recommended readings
http://www.informatik.unibremen.de/agbkb/forschung/formal_methods/completed_projects/compass/7years_e.htm
http://en.wikipedia.org/wiki/Exponential_growth
http://en.wikipedia.org/wiki/Wheat_and_chessboard_problem
Recommended activities
Invent some ADTs, and develop the corresponding specification.
Solve the unsolved problems from the list proposed.
Apply the asymptotic analysis to your own algorithms.
33