Vous êtes sur la page 1sur 11

Questions

• What are data structures and algorithms?


• What good it will do me to know about them?
• Why can’t I just use arrays and for loops to
handle my data?
• When does it make sense to apply what I learn
here?

1
What is a Program
• Algorithm = Logic + Control (e.g., search, insert,
sort)

• Data Structure = An arrangement of data (A


Container that stores Data) in computer’s
memory

• A program is a set of Data Structures and


Algorithms
Why can’t I just use arrays and loops to
handle my data?
• What data structure will you use in the following Scenarios:
– Undo the last operations in a word document in reverse order
– Implement printer spooler so that jobs can be printed in the
order of their arrival
– Each process is having priority, the Operating System schedules
the one having the highest priority
– You need to store the friendship information on a social
networking site, i.e., who is friends with who
– Model routes between cities and find shortest paths
– To lookup a dictionary for word definitions by keyword

• You won’t be able to answer all of these problems until you


learn more about data structures
Common Data Structures
• List Abstract Data Type:
– Arrays (concrete)
– Linked Lists (concrete)
– Hash Tables

• Stack Abstract Data Type

• Queue Abstract Data Type:


– First-In-First-Out (FIFO) Queue
– Priority Queue

• Trees
– Binary Search Trees
– Heaps

• Graphs 4
Data abstraction - Abstract Data Type
• An abstract data type(ADT) is a data type that is
organized in such a way that
– the specification of the objects and
the operations on the objects
is separated from
– the representation of the objects and
the implementation of the operations.

• We know what it does, but not necessarily how it


will do it.
ADT vs Data Structure
Abstract Data Type Data Structures

• WHAT service is provided? • HOW is the service


Function specification: implemented?
– Operation specification – Specific choice of data
– function name types
– the types of arguments – Specific algorithm to
implement the functions
– the type of the results
ADT vs Data Structure
• Abstract Data Type • Data structures
– Abstract – Concrete implementation
– Operations & semantics – Set of algorithms
– Data-less – Holds data
– One – Many implementations
– No notion of running – Very particular running
time or complexity time and complexities
Abstract Data Types
• An ADT is abstract in the sense that nothing is said about
how the ADT is implemented

• The advantages of using an ADT are:


– Abstraction: the user of a type does not need to know or
understand any implementation details of the type, which
reduces the complexity of the programming task.
– Flexibility of making changes: if the programmer decides to
change the representation of a type (e.g., to change the
representation of a set from a list of elements to a bit vector),
then only the implementation of the ADT need be changed; code
that uses the type is not affected.
– Localization of errors: if there are errors either in the
representation or implementation of the type, the errors are local
to the ADT, and cannot be caused by code that uses the type.
Operations on data structures
• Operations on data structures can be grouped
into two categories:
– queries, which simply return information about
the set, and
– modifying operations, which change the set.
Check the next slide for a list of typical operations.

• Any specific application will usually require


only a few of these to be implemented.

9
Operations on data structures
• Insert
• Delete
• Search
• Minimum
• Maximum
• Sort
• Successor
• Predecessor
Which Data Structure or Algorithm is
better?
• Different data structures and algorithms may correctly solve a
given task, which should I use?

• Algorithm analysis (machine independent)


– time complexity: What is the running time of the algorithm
– space complexity: How much storage does it consume (low
RAM footprint)

Vous aimerez peut-être aussi