CS 161: Chapter 7 Data Structures

Download Report

Transcript CS 161: Chapter 7 Data Structures

Data Structures
Winter
2012
What is a Data Structure?
• A data structure is a method of organizing
data.
• The study of data structures is particularly
important when using a procedural
programming language.
Simple Data Types
• Many programming languages provide
built-in simple data types. For example:
–
–
–
–
–
Characters
Integers
Real Numbers
Boolean (TRUE, FALSE)
Strings (words)
Arrays
• A one-dimensional array can be thought of
as a list or a vector. It is a homogeneous
collection of data.
• For example, an array of 10 integers might
take 20 bytes of storage. If the name of the
array is IntArray, the 10 integers might be
accessed as IntArray[0], IntArray[1], ... ,
IntArray[9].
Arrays II
• Most programming languages provide builtin arrays.
• Most programming languages provide for
multi-dimensional arrays.
• A two-dimensional array, for example,
allows the programmer to think of the data
as being organized in a table (rows and
columns). Note this is a virtual table.
Records
• A record is a heterogeneous data structure.
• For example, a student record, or a
customer record.
• The individual components of a record are
called fields.
Abstract Data Type
• An ADT is a data structure together with the
operations that are allowed on the data
structure.
• STACK: FILO structure, top, Push, Pop
• QUEUE: FIFO structure, head, tail (front,
back), Enqueue, Dequeue
• LIST: head, tail, current, Insert, Delete,
Next
Pointers
• A pointer is a structure that contains not
data but an address that points to data.
• The Program Counter can be considered as
a pointer.
• Pointers allow for dynamic memory
allocation.
• Many data structures can be implemented
either with dynamic or static memory
allocation.
Other Structures
• Trees: Family tree, Directory
• Graphs: A general graph is a mathematical
structure that consists of a set of vertices
and a set of edges. The study of graph
theory is very important in theoretical
Computer Science.
To study for the quiz
What is an Abstract Data Type?
Be able to describe the following ADT’s by
their actions and how they can be
implemented:
Stack, Queue, Binary Tree, Graph
Distinction between dynamic and static.