daa unit i notes

Upload: sridharanc23

Post on 03-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 DAA Unit I Notes

    1/8

    1) What is a Computer Algorithm?

    An algorithm is a sequence of unambiguous

    instructions for solving a problem, i.e., forobtaining a required output for any legitimate

    input in a finite amount of time.

    2) What are the features of an algorithm? More precisely, an algorithm is a method or process to solve a problem satisfying

    the following properties:

    Finiteness terminates after a finite number of steps

    Definiteness

    Each step must be rigorously and unambiguously specified.

    -e.g., stir until lumpy Input

    Valid inputs must be clearly specified.

    Output

    can be proved to produce the correct output given a valid can beproved to produce the correct output given a valid input.

    Effectiveness Steps must be sufficiently simple and basic.

    3) Show the notion of an algorithm.

    4) What are different problem types?

    5) What are different algorithm design techniques/strategies?

  • 7/28/2019 DAA Unit I Notes

    2/8

    Brute force

    Divide and conquer

    Decrease and conquer

    Transform and conquer

    Space and time tradeoffs

    Greedy approach

    Dynamic programming

    Backtracking

    Branch and bound

    6) What are fundamental data structures?

    list array

    linked list string

    stack

    queue

    priority queue graph

    tree

    set and dictionary

    7) What are the sequence of steps in designing and analyzing the algorithm?

    Fundamentals of Algorithmic Problem Solving

    Understanding the problem

    Asking questions, do a few examples by hand, think about special cases,etc.

    Deciding on

    Exact vs. approximate problem solving

    Appropriate data structure Design an algorithm

    Proving correctness

    Analyzing an algorithm Time efficiency : how fast the algorithm runs

    Space efficiency: how much extra memory the algorithm needs.

    Coding an algorithm

  • 7/28/2019 DAA Unit I Notes

    3/8

    8) What is algorithm analysis framework?

    Analysis of algorithms means to investigate an algorithms efficiency with respect to

    resources: running time and memory spaceTime efficiency: how fast an algorithm runs.

    Space efficiency: the space an algorithm requires.

    Typically, algorithms run longer as the size of its input increases

    We are interested in how efficiency scales wrt input size

    Analysis Framework

    Measuring an inputs size

    Measuring running time

    Orders of growth (of the algorithms efficiency function)

    Worst-base, best-case and average-case efficiency

    9) How the running time of an algorithm is measured?

    Units for Measuring Running Time

  • 7/28/2019 DAA Unit I Notes

    4/8

    Count the number of times an algorithms basic operation is executed.

    Basic operation: the operation that contributes the most to the total

    running time.

    For example, the basic operation is usually the most time-consuming

    operation in the algorithms innermost loop.

    10) How time effieciency is analysed? Time efficiency is analyzed by determining the number of repetitions of the basic

    operation as a function of input size.

    11) What is orders of growth?

    Orders of Growth

    12) What are Worst-Case, Best-Case, and Average-Case Efficiency ?

    Worst case Efficiency

    Efficiency (# of times the basic operation will be executed) for the worstcase input of size n.

    The algorithm runs the longest among all possible inputs of size n.

    Best case

    Efficiency (# of times the basic operation will be executed) for the bestcase input of size n.

    The algorithm runs the fastest among all possible inputs of size n.

    runningtime

    execution timefor the basic

    operation

    Number of times the

    basic operation is

    executed

    input

    size

    T(n) copC (n)

  • 7/28/2019 DAA Unit I Notes

    5/8

    Average case:

    Efficiency (#of times the basic operation will be executed) for a

    typical/random input of size n.

    NOT the average of worst and best case

    How to find the average case efficiency?

    13) What are asymptotic notations? Explain in detail.Asymptotic Growth Rate

    Three notations used to compare orders of growth of an algorithms basic

    operation count

    O(g(n)): class of functionsf(n) that grow no fasterthang(n)

    (g(n)): class of functionsf(n) that grow at least as fastas g(n)

    (g(n)): class of functionsf(n) that grow at same rate asg(n)

    O-notation

    Formal definition

    A function t(n) is said to be in O(g(n)), denoted t(n) O(g(n)), ift(n) is

    bounded above by some constant multiple ofg(n) for all large n, i.e., ifthere exist some positive constant c and some nonnegative integern0 such

    that

    t(n) cg(n) for all n n0

    -notation

    Formal definition

  • 7/28/2019 DAA Unit I Notes

    6/8

    A function t(n) is said to be in (g(n)), denoted t(n) (g(n)), ift(n) is

    bounded below by some constant multiple ofg(n) for all large n, i.e., if

    there exist some positive constant c and some nonnegative integern0 such

    that

    t(n) cg(n) for all n n0

    -notation

    Formal definition

    A function t(n) is said to be in (g(n)), denoted t(n) (g(n)), ift(n) is

    bounded both above and below by some positive constant multiples ofg(n) for all large n, i.e., if there exist some positive constant c1 and c2 and

    some nonnegative integern0 such thatc2 g(n) t(n) c1 g(n) for all n n0

  • 7/28/2019 DAA Unit I Notes

    7/8

    12) What are basic efficiency classes?

    Basic Efficiency classes

    1 constant

    log n logarithmic

    n linear

    n log n n log n

    n2 Basic Efficiency

    classes

    quadratic

    n3 cubic

    2n exponential

    n! factorial

    13) Give an example for basic operations.

    Input size and basic operation examples

    Problem Input size measure Basic operation

    Searching for key in a

    list ofn items

    Number of lists items,

    i.e. nKey comparison

    Multiplication of two

    matrices

    Matrix dimensions or

    total number of elements

    Multiplication of two

    numbers

    Checking primality of agiven integern

    nsize = number of digits(in binary representation)

    Division

    Typical graph problem #vertices and/or edgesVisiting a vertex or

    traversing an edge

  • 7/28/2019 DAA Unit I Notes

    8/8

    14) Write an algorithm for counting binary digits for a decimal number.

    15) Write an algorithm for matrix multiplication.