Title: 2.1 Data Structures
1Computer-Aided Engineering
Knowledge Component 2 Building Knowledge
Representations
2.1 Data Structures
Ian F. C. Smith EPFL, Switzerland
2Module Information
- Intended audience
- Beginners
- Key words
- Data types, linked lists, graphs, trees, stacks
and queues - Author
- Ian Smith, EPFL, Switzerland
- Reviewer
- Frank Boukamp, UIUC, USA
3- Review Board
- Renate Fruchter, ExCom Past Chair, Stanford
University, USA - Carlos Caldas, TCCIT DIM Committee Chair,
University of Texas Austin, USA - Bill OBrian, TCCIT IC Committee Chair,
University of Texas Austin, USA - Guillermo Salazar, TCCIT Edu Committee Chair,
Worcester Polytechnic Institute, USA - William Rasdorf, TCCIT JCCE editor, North
Carolina State University, USA - Chimay Anumba, Loughborough University, UK.
- The ASCE GCEC Officers
- Tomasz Arciszewski, ExCom Chair, George Mason
University, USA - Ian Smith, ExCom Vice-Chair, EPFL, Switzerland
- Hani Melhem, ExCom Vice-Chair, Kansas State
University, USA - The ASCE Technical Council on Computing and IT
- Officers
- Renate Fruchter, ExCom Past Chair, Stanford
University, USA - Kim Roddis, ExCom Chair, George Washington
University, USA - Raymond Issa, ExCom Vice Chair, University of
Florida Gainesville, USA - Hani Melhin, ExCom Secretary, Kansas State
University, USA
4Data Structures
- Data structures reflect the organization of data
in software - Organization of data determines
- Computational complexity of algorithms
- Maintainability of applications
- Versatility for a range of applications
- Some user interface characteristics
5Structured Organization of Data
Logically related data are grouped together to
form a structure. A data structure may contain
elements that are themselves be data structures.
This results in a decomposition hierarchy.
6Structured Organisation of Data (contd.)
- Flat list of data items
- Door width
- Door height
- Window width
- Window height
Hierarchical organisation of data
Building
Door
Window
Height
Width
Width
Height
7Outline
Abstract Data Types Linked lists Graphs Trees
Stacks Queues
8Introduction
- Basic data types are groups such as integer,
string and real. Abstract data types are more
general. - When details are left out, data often have
standard forms. Abstract data types are standard
forms of data structures. - Common abstract data types are
- Linked lists
- Graphs
- Trees
- Stacks
- Queues
9Operations on Abstract Data Types
Standard operations are defined on each abstract
data type. Such operations permit descriptions of
algorithms using standard vocabulary. For
example, a person who knows about queues will
understand when we say Element X is added to
the queue and element Y is removed from the
queue. Note that each element in an abstract
data type may be assigned a basic element type.
10Outline
Abstract Data Types Linked lists Graphs Trees
Stacks Queues
11Linked Lists
A linked list organises a collection of data
items (elements) such that elements can easily be
added to and deleted from any position in the
list.
NULL
There are also doubly linked lists. They are not
in the scope of this module
12Operations on Linked Lists
Operations such as inserting an element and
deleting an element are easily carried out. Only
references to next elements are updated in these
operations. There is no need to copy or move
large blocks of data to facilitate insertion and
deletion of elements. Lists grow and shrink
dynamically.
13Linked Lists Insertion
New data
NULL
14Linked Lists Deletion
Deleted element
NULL
15Outline
Abstract Data Types Linked lists Graphs Trees
Stacks Queues
16Graphs
A graph data structure consists of vertices and
elements.
Example A network of computers is represented as
a graph.
17Types of Graphs
Directed graph Each edge of the graph has a
direction (arrow). Connected graph A graph in
which there exists a path between every pair of
nodes. Acyclic graph A graph not containing any
cycle.
18Types of Graphs (contd.)
Weighted graph Each edge has an allotted value
(weight). For example, this weight can represent
distance or duration. Planar graph A graph is
planar if it can be drawn in 2-D so that the
edges do not cross over each other.
19Possible Applications of Graphs
- Reasoning with inter-connected objects, for
example - Road networks
- Office buildings (access, fire escapes, etc.)
- Structures and frameworks
- Social networks (for example, those used to deal
with sicknesses such as SARS and AIDS)
20Review Quiz I
- What are data structures?
- What is an advantage of data structures?
- Name the five common abstract data types.
21Answers to Review Quiz I
- What are data structures?
- Organizations of data
- What is an advantage of data structures?
- They provide understandability and
maintainability through common types. - Name the five common abstract data types.
- Linked lists, graphs, trees, stacks and queues.
22Outline
Abstract Data Types Linked lists Graphs Trees
Stacks Queues
23Trees
A tree is a graph that does not contain any
cycles. Efficient algorithms are available for
processing trees.
A tree
Not a tree
24Example Classification tree
Bridges
N1
N3
N4
N2
Country
USA
UK
Switzerland
N6
N5
N7
N8
Type
Cable-stayed
Cable-stayed
Pre-stressed
Arch
N12
N9
N10
N11
Short
Span
Long
Medium
Long
Tacoma Narrows
Name
Lutrive
London
25Graphs and Trees
Graph
Connected graph
Connected acyclic graph (Tree)
Directed graph
26Outline
Abstract Data Types Linked lists Graphs Trees
Stacks Queues
27Stacks
Stacks are LIFO (Last In First Out) data
structures. Operations on stacks are to add an
element to the top of the stack (push) and
extract an element from the top of the stack
(pop).
Add an element (push)
Remove an element (pop)
28An Example of Stacks
Stacks are used to keep track of changes in order
to be able to carry out backtracking (undo).
The changes are added (push) to the stack.
During the undo operation, the changes are
withdrawn from the top of the stack (pop).
Therefore, the last changes are there to be
popped out (LIFO).
29Outline
Abstract Data Types Linked lists Graphs Trees
Stacks Queues
30Queues
Queues are FIFO (First In First Out) data
structures. Standard operations are Enqueue (add
element to the tail of the queue) and Dequeue
(take out element from the front of the
queue). Examples order processing queues,
messaging queues in computer networks, etc.
Add an element (Enqueue)
Remove an element (Dequeue)
31Remarks
Abductive tasks Abductive engineering tasks are
well supported by the abstract data types. (see
Knowledge Component 1 Module 1.3) Exponential
complexity The presence of stacks in the loops
of a program may indicate exponential complexity.
(see Knowledge Component 1 Modules 1.2.1 and
1.2.2)
32Review Quiz II
- What is the difference between a stack and a
queue? - Name two uses for stacks.
- What feature of trees makes reasoning with trees
easier than with other types of graphs?
33Answers to Review Quiz II
- What is the difference between a stack and a
queue? - In a stack, the last data entry is used first
while in a queue, the first data entry is used
first - Name two uses for stacks.
- Undo and backtracking
- What feature of trees makes reasoning with trees
easier than with other types of graphs? - A tree graph contains no cycles (acyclic) and
therefore, there is no risk of endless loops.
33
34Discussion
- Once data is organized into forms such as trees,
stacks and queues, standard algorithms can be
used to process them. - Properly organized data lead to
easy-to-understand user interfaces - Data structure design is an important task.
- It should begin at the start of software
application development.
35Further Reading
- Kruse, R. L., Leung, B. P. and Tondo, C. L. Data
Structures and Program Design in C, Englewood
Cliffs NJ Prentice Hall, 1991 - Liu, C. L., Elements of Discrete Mathematics, New
York McGraw-Hill, 1997 - Raphael, B. and Smith, I.F.C. Fundamentals of
Computer-Aided Engineering, Wiley, 2003