lec1

download lec1

of 53

description

data stucture

Transcript of lec1

  • Introduction to Data Structures and Algorithm Analysis

  • Computer Engineering is about

  • Programming Life Cycle ActivitiesProblem analysisunderstand the problem

    Requirements definition specify what program will do

    High- and low-level designhow it meets requirements

    Implementation of designcode it

    Testing and verificationdetect errors, show correct

    Deliveryturn over to customer

    Operationuse the program

    Maintenancechange the program

  • Software EngineeringA disciplined approach to the design, production, and maintenance of computer programs

    that are developed on time and within cost estimates,

    using tools that help to manage the size and complexity of the resulting software products.

  • Toolboxes:Hardware.SoftwareIdeaware (focus of the course!): the shared body of knowledge that programmers have collected over time, including algorithms, data structures, programming methodologies, tools

  • An Algorithm Is . . .A logical sequence of discrete steps that describes a complete solution to a given problem computable in a finite amount of time.

  • Goals of Quality SoftwareIt works. It can be read and understood. It can be modified. It is completed on time and within budget.

  • Specification: Understanding the ProblemDetailed Program Specification

    Tells what the program must do, but not how it does it.

    Is written documentation about the program.

  • Writing Detailed Specifications

    Detailed Program Specification Includes:Inputs

    Outputs

    Processing requirements

    Assumptions

  • AbstractionA model of a complex system that includes only the details essential to the perspective of the viewer of the system.

  • Information HidingHiding the details of a function or data structure with the goal of controlling access to the details of a module or structure.

    PURPOSE: To prevent high-level designs from depending on low-level design details that may be changed.

  • Two Approaches to Building Manageable ModulesFUNCTIONAL DECOMPOSITIONOBJECT-ORIENTED DESIGNFOCUS ON: processes FOCUS ON: data objects

  • Functional Design ModulesMainPrint DataPrint Heading

    Get DataPrepare File for Reading

  • Object-Oriented DesignA technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data.Private data

    get...ignorecincout

  • More about OODLanguages supporting OOD include: C++, Java, Smalltalk, Eiffel, and Object-Pascal, C,

    A class is a programmer-defined data type and objects are variables of that type.

    In C++, cin is an object of a data type (class) named istream, and cout is an object of a class ostream. Header files iostream.h and fstream.h contain definitions of stream classes.

  • Procedural vs. Object-Oriented Code Read the specification of the software you want to build. Underline the verbs if you are after procedural code, the nouns if you aim for an object-oriented program.

    Brady Gooch, What is and Isnt Object Oriented Design, 1989.

  • Verification of Software Correctness Testing Debugging Program verification

  • Program Verification is the process of determining the degree to which a software product fulfills its specifications.

    Program VerificationPROGRAMSPECIFICATIONS

    Inputs

    Outputs

    Processing Requirements

    Assumptions

  • Program TestingTesting is the process of executing a program with various data sets designed to discover errors.

    DATA SET 4

    . . .

  • Origin of BugsVarious Types of Errors:

    Design errors occur when specifications are wrong

    Compile errors occur when syntax is wrong

    Run-time errors result from incorrect assumptions, incomplete understanding of the programming language, or unanticipated user errors.

  • Design for Correctness

  • RobustnessRobustness is the ability of a program to recover following an error; the ability of a program to continue to operate within its environment.

  • An AssertionIs a logical proposition that is either true or false (not necessarily in C++ code).

    EXAMPLES studentCount is greater than 0

    sum is assigned && count > 0

    response has value y or n

    partNumber == 5467

  • Preconditions and PostconditionsThe precondition is an assertion describing what a function requires to be true before beginning execution.

    The postcondition describes what must be true at the moment the function finishes execution.

    The caller is responsible for ensuring the precondition, and the function code must ensure the postcondition.FOR EXAMPLE . . .

  • Design Review ActivitiesDeskchecking: tracing an execution of a design or program on paper

    Walk-through: a verification method in which a team performs a manual simulation of the program or design.

    Inspection: a verification method in which one member of a team reads the program or design line by line an the others point out errors.

  • Program TestingUnit Testing: testing a module or function by itself Data Coverage: testing all possible input values (Black Box Testing)Code Coverage: testing program paths (Clear/White Box Testing)Test PlansPlanning for DebuggingIntegration Testing

  • Tasks within each test case:determine inputs that demonstrate the goal.

    determine the expected behavior for the input.

    run the program and observe results.

    compare expected behavior and actual behavior. If they differ, we begin debugging.

  • Integration TestingIs performed to integrate program modules that have already been independently unit tested.

    FindWeighted AveragePrintWeighted AverageMainPrint DataPrint Heading

    Get DataPrepare File for Reading

  • Integration Testing ApproachesEnsures correct overall design logic.

    Ensures individual moduleswork together correctly, beginning with the lowest level.

    TOP-DOWN BOTTOM-UPUSES: placeholder USES: a test driver to callmodule stubs to test the functions being tested.the order of calls.

  • Life-Cycle Verification Activities:Analysis DesignCodeTestDeliveryMaintenance

  • Programs and ProgrammingThe computer only knows what is told through programs, so they must be accurate and very specific.The process of creating programs is programming.A program follows a step-by-step logic algorithm to solve a problem.Note: never a attempt to program before developing an algorithm that solve the problem

  • Control StructuresControl Structure is the logic behind the program.Sequence: Input, Storage, Arithmetic and outputDecision: comparing two values an selecting one.Repetition: Going through loop

  • Programming Languageis a set of restricted vocabulary and structured syntax that a computer can understandis a language used to write computer programs, which involve a computer performing some kind of computation or algorithm and possibly control external devices such as printers, robots, and so on.

  • Programming LanguageLevel of Computer LanguagesLow level : at the level of the computerBinary format Intermediate Level : close to computer language but uses English languageAssemblerHigh Level: at the level of programmer using English words and clearly defined syntaxTranslated to binary to implement itNeed software program for conversion

  • Programming Language Total = 0 A=1 B=2 Total = A + BTranslationProgram 0110101011 0100101 01011010 01010010Graphical Representation

  • High level to BinaryCompilerprogram that translates a high-level language program, such as a C++ program, into a machine-language program that the computer can directly understand and executeLinkerThe object code for your C++ program must be combined with the object code for routines (such as input and output routines) that your program uses. This process of combining object code is called linking and is done by a program called a linker. For simple programs, linking may be done for you automatically.

  • Programming LanguageTypes of Computer LanguageProcedural: Monolithic program that runs from the start to finish with no intervention from user other than input.CBasicObject Oriented/Event Driven: programs that use objects which responds to events;Visual Basic

  • What is an Algorithm?A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.Algorithms are used for calculation, data processinglist of well-defined instructions for completing a task

  • What is an Algorithm?An algorithm is a well-developed, organized approach to solving a complex problem.Computer Scientists ask themselves four critical questions when they evaluate algorithms

  • Algorithm QuestionsDoes the algorithm solve the stated problem?Is the algorithm well-defined?Does the algorithm produce an output?Does the algorithm end in a reasonable length of time?

  • Developing an AlgorithmIdentify the InputsIdentify the ProcessesIdentify the OutputsDevelop a HIPO ChartIdentify modules

  • 1. Identify the InputsWhat data do I need?How will I get the data?In what format will the data be?

  • 2. Identify the ProcessesHow can I manipulate data to produce meaningful results?Data vs. Information

  • 3. Identify the OutputsWhat outputs do I need to return to the user?What format should the outputs take?

  • 4. Develop a HIPO ChartHierarchy of Inputs Processes & Outputs

  • 5. Identify Relevant ModulesHow can I break larger problems into smaller, more manageable pieces?What inputs do the modules need?What processes need to happen in the modules?What outputs are produced by the modules?

  • Importance of AlgorithmUsing an algorithm in planning for a solution helps in several ways:First, it allows the individual to see things in a wider perspective thereby weeding through all other possible solutions to pick the best one. Since in coming up with an algorithm the individual is not stuck with using a specific language, the person may use whatever tool (i.e. flowchart, layman's term, etc.) that is comfortable; putting emphasis on how to go about solving an issue.

  • Importance of AlgorithmSecond, algorithms serve as the framework to which the actual solution is patterned after. This guides the individual in the process of deriving the solution, thus saving time and effort as compared to having one jump immediately to this stage without any plan.

  • Importance of AlgorithmLastly, algorithms can become generic templates to which other issues may refer to for solutions. If properly documented or easily recalled, an algorithm used to solve one problem can guide the individual in resolving another one of similar nature.

  • Properties of Algorithm1) Finiteness: - an algorithm terminates after a finite numbers of steps. 2) Definiteness: - each step in algorithm is unambiguous. This means that the action specified by the step cannot be interpreted (explain the meaning of) in multiple ways & can be performed without any confusion. 3) Input:- an algorithm accepts zero or more inputs

  • Properties of Algorithm4) Output: it produces at least one output. 5) Effectiveness:- it consists of basic instructions that are realizable. This means that the instructions can be performed by using the given inputs in a finite amount of time.

    *****************************High-level languages resemble human languages in many ways. They are designed to be easy for human beings to write programs in and to be easy for human beings to read. *