Data Structures and Algorithms –Intro

download Data Structures and Algorithms –Intro

of 20

Transcript of Data Structures and Algorithms –Intro

  • 8/12/2019 Data Structures and Algorithms Intro

    1/20

    Data Structures and Algorithms

    Introduction

  • 8/12/2019 Data Structures and Algorithms Intro

    2/20

    Subject Overview

    Introduction to many of the basic data structuresused in computer software Understand the data structures

    Analyze the algorithms that use them Know when to apply them

    Practice design and analysis of data structures.

    Practice using these data structures by writing

    programs. Make the transformation from programmer to

    computer scientist

  • 8/12/2019 Data Structures and Algorithms Intro

    3/20

    Data Structures

    Cleverways to organize information in order

    to enable efficientcomputation

    What do we mean by clever?

    What do we mean by efficient?

  • 8/12/2019 Data Structures and Algorithms Intro

    4/20

    Picking the best

    Data Structure for the job

    The data structure you pick needs to

    supportthe operations you need

    Ideally it supports the operations you will

    use most often in an efficientmanner

    Examples of operations:

    A Listwith operations insertand delete

    A Stackwith operationspushand pop

  • 8/12/2019 Data Structures and Algorithms Intro

    5/20

    Why So Many Data Structures?

    Ideal data structure:

    fast, elegant, memory efficient

    Generates tensions: time vs.space

    performance vs.elegance

    generality vs. simplicity one operations performance vs.anothers

    The study of data structures is the study of

    tradeoffs. Thats why we have so many of

    them!

  • 8/12/2019 Data Structures and Algorithms Intro

    6/20

    6

    The Need for Data Structures

    Data structures organize data

    more efficient programs.

    More powerful computers

    more complexapplications.

    More complex applications demand morecalculations.

    Complex computing tasks are unlike oureveryday experience.

  • 8/12/2019 Data Structures and Algorithms Intro

    7/20

    7

    Organizing Data

    Any organization for a collection ofrecords can be searched, processed inany order, or modified.

    The choice of data structure and algorithmcan make the difference between aprogram running in a few seconds ormany days.

  • 8/12/2019 Data Structures and Algorithms Intro

    8/20

    8

    Efficiency

    A solution is said to be efficient if it solvesthe problem within its resourceconstraints.

    Space

    Time

    The cost of a solution is the amount of

    resources that the solution consumes.

  • 8/12/2019 Data Structures and Algorithms Intro

    9/20

    9

    Selecting a Data Structure

    Select a data structure as follows:

    1. Analyze the problem to determine theresource constraints a solution must

    meet.2. Determine the basic operations that must

    be supported. Quantify the resource

    constraints for each operation.3. Select the data structure that best meets

    these requirements.

  • 8/12/2019 Data Structures and Algorithms Intro

    10/20

    10

    Data Structure Philosophy

    Each data structure has costs and benefits.

    Rarely is one data structure better thananother in all situations.

    A data structure requires:

    space for each data item it stores,

    time to perform each basic operation,

    programming effort.

  • 8/12/2019 Data Structures and Algorithms Intro

    11/20

    11

    Data Structure Philosophy (cont)

    Each problem has constraints on availablespace and time.

    Only after a careful analysis of problem

    characteristics can we know the bestdata structure for the task.

    Bank example:

    Start account: a few minutes Transactions: a few seconds Close account: overnight

  • 8/12/2019 Data Structures and Algorithms Intro

    12/20

    Terminology

    Abstract Data Type (ADT) Mathematical description of an object with set of

    operations on the object. Useful building block.

    Algorithm A high level, language independent, description of a step-

    by-step process

    Data structure A specific family of algorithms for implementing an abstract

    data type.

    Implementation of data structure A specific implementation in a specific language

  • 8/12/2019 Data Structures and Algorithms Intro

    13/20

    13

    Abstract Data Types

    Abstract Data Type (ADT): a definition for adata type solely in terms of a set of valuesand a set of operations on that data type.

    Each ADT operation is defined by its inputsand outputs.

    Encapsulation: Hide implementation details.

  • 8/12/2019 Data Structures and Algorithms Intro

    14/20

    14

    Data Structure

    A data structure is the physicalimplementation of an ADT. Each operation associated with the ADT is

    implemented by one or more subroutines inthe implementation.

    Data structure usually refers to anorganization for data in main memory.

    File structure is an organization for data onperipheral storage, such as a disk drive.

  • 8/12/2019 Data Structures and Algorithms Intro

    15/20

    15

    Metaphors

    An ADT manages complexity throughabstraction: metaphor. Hierarchies of labels

    Ex: transistors gatesCPU.

    In a program, implement an ADT, then think

    only about the ADT, not its implementation.

  • 8/12/2019 Data Structures and Algorithms Intro

    16/20

    Data Structures

    A data structure is a scheme for

    organizing data in the memory

    of a computer.

    Some of the more commonly

    used data structures include lists,

    arrays, stacks, queues, heaps,

    trees, and graphs.Binary Tree

  • 8/12/2019 Data Structures and Algorithms Intro

    17/20

    Data Structures

    The way in which the data is

    organized affects the

    performance of a program for

    different tasks.

    Computer programmers decide

    which data structures to use

    based on the nature of the

    data and the processes that

    need to be performed on that

    data.

    Binary Tree

  • 8/12/2019 Data Structures and Algorithms Intro

    18/20

  • 8/12/2019 Data Structures and Algorithms Intro

    19/20

  • 8/12/2019 Data Structures and Algorithms Intro

    20/20

    Thank You