Lecture 6_Introduction to DS File

Download Report

Transcript Lecture 6_Introduction to DS File

Maitrayee Mukerji
INPUT
DATA
PROCESS
MEMORY
INFO
OUTPUT
 Representation
of data and its
associated operations
 int or char is a simplest data structure
 Systematic
way of organizing or
structuring a collection of data
items
 Array of names



How to structure information for efficient
processing to solve a given problem given specific
resource constraints
Measure effectiveness of solutions/ approaches to
solve a given problem and determine the most
appropriate one
Calculate tradeoffs/cost benefit (time & space)
associated with different data structures




A data structure requires a certain amount of space for
each data item it stores, a certain amount of time to
perform a single basic operation (insert, delete, search),
and a certain amount of programming effort.
Each problem has constraints on available space and
time.
Each solution to a problem makes use of the basic
operations in some relative proportion, and the data
structure selection process must account for this.
Only after a careful analysis of your problem’s
characteristics can you determine the best data
structure for the task.

Analyze the problem to determine the basic
operations that must be supported.
 Examples of basic operations include inserting a data
item into the data structure, deleting a data item from
the data structure, and finding a specified data item.

Quantify the resource constraints for each
operation.

Resource constraints on certain key
operations normally drive the data structure
selection process.
 Are all data items inserted into the data structure at
the beginning, or are insertions interspersed with
other operations?
 Can data items be deleted?
 Are all data items processed in some well-defined
order, or is search for specific data items allowed?

Select the data structure that best meets
these requirements.

A simple model of bank supports opening of
accounts, closing of accounts, and adding
money or withdrawing money from accounts.


A company is developing a database system
containing information about cities and towns
in the India. There are many thousands of
cities and towns, and the database program
should allow users to find information about
a particular place by name.
Users should also be able to find all places
that match a particular value or range of
values for attributes such as location or
population size.

A type is a collection of values
◦ Boolean Type : true or false
◦ Simple Types Vs Aggregate/Composite types

A data type is a type together with a
collection of operations to manipulate the
type.
 For example, an integer variable is a member of the
integer data type.
 Addition is an example of an operation on the integer
data type.



An abstract data type (ADT) is the realization of a
data type as a software component.
The interface of the ADT is defined in terms of a
type and a set of operations on that type.
The behavior of each operation is determined by its
inputs and outputs.


An ADT does not specify how the data type
is implemented. These implementation
details are hidden from the user of the ADT
and protected from outside access, a
concept referred to as encapsulation.
A data structure is the implementation for
an ADT.

An ADT for a list of integers might specify the
following operations:
◦
◦
◦
◦
◦
Insert a new integer at a particular position in the list.
Return true if the list is empty.
Reinitialize the list.
Return the number of integers currently in the list.
Delete the integer at a particular position in the list.

In an object-oriented language, an ADT and
its implementation together make up a class.
◦ Each operation associated with the ADT is
implemented by a member function or method.
◦ The variables that define the space required by a
data item are referred to as data members.
◦ An object is an instance of a class, that is,
something that is created and takes up storage
during the execution of a computer program.


The term “data structure” often refers to data
stored in a computer’s main memory.
The related term file structure often refers to
the organization of data on peripheral
storage, such as a disk drive or CD-ROM.

A distinction should be made between the
logical concept of a data type and its physical
implementation in a computer program.
◦ LIST can be implemented using either arrays or
linked list
◦ Array – “ambiguous” term – it can either refer to a
data type or implementation

A problem is a task to be performed.
◦ often expressed in terms of inputs and matching
outputs.

A problem definition should not include
any constraints on how the problem is to be
solved.
◦ The solution method should be developed only
after the problem is precisely defined and
thoroughly understood.

However, a problem definition should include
constraints on the resources that may be
consumed by any acceptable solution.
◦ For example, any computer program may use only the main
memory and disk space available, and it must run in a
“reasonable” amount of time.




An algorithm is a method or a process followed to
solve a problem.
If the problem is viewed as a function, then an
algorithm is an implementation for the function
that transforms an input to the corresponding
output.
A problem can be solved by many different
algorithms. A given algorithm solves only one
problem
Associated with each data structure are algorithms
for manipulating the data,


It must be correct / gives intended output
for specified inputs
It is composed of a series of concrete steps.
◦ Action specified by the step is completely
understood and is doable

There can be no ambiguity as to which step
will be performed next
◦ Conditional, Branching, Repetitions

It must terminate. In other words, it may
not go into an infinite loop.
◦

A program is an instantiation of an algorithm
in a computer programming language.

Each data structure and each algorithm has
costs and benefits
◦ How to assess cost and benefit?

Related to costs and benefits is the notion
of tradeoffs
◦ Time vs Speed

Programmers should know enough about
common practice to avoid reinventing the
wheel.
◦ Thus, programmers need to learn the commonly
used data structures, their related algorithms,
and the most frequently encountered design
patterns found in programming.

Data structures follow needs.
◦ Programmers must learn to assess application
needs first, then find a data structure with
matching capabilities.

Chapter 1 on Clifford A. Shaffer (2011), A
Practical Introduction to Data Structures and
Algorithm Analysis Edition 3.1 (Java Version),
Available at
http://people.cs.vt.edu/˜shaffer/Book/