Algorithms Complexity and Data Structures Efficiency (1)

Embed Size (px)

Citation preview

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    1/17

    Algorithms Complexity and

    Data Structures Efficiency

    1. Fundamental Data Structures Comparison

    Arrays vs. Lists vs. Trees vs. Hash-Tables

    2. Choosing Proper Data Structure for a program

    will increase the efficiency of a program.

    3. Data structures and algorithms are the

    foundation of computer programming

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    2/17

    Algorithms Complexity

    Algorithmic thinking, problem solving and data

    structures are vital for software engineers.

    Time Complexity space complexity.

    Mean, Average and Worst Case.

    Worst-caseAn upper bound on the running time for any input

    of given size

    Average-case

    Assume all inputs of a given size are equally likely Best-case

    The lower bound on the running time

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    3/17

    Why we should analyze algorithms?

    Predict the resources that the algorithmrequires Computational time (CPU consumption) Memory space (RAM consumption) Communication bandwidth consumption

    The running time of an algorithm is: The total number of primitive operations

    executed (machine independent steps)

    Also known as algorithm complexity

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    4/17

    Big O notation

    Time complexity in so-called "Big O"notation.

    This, approximately, describe the time

    taken for an algorithm to solve thegiven task.

    Prefer Time complexity", rather than"space complexity" mostly because now

    a days space doesnt matter. The big 0notation will calculate time

    complexity in worst case scenario.

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    5/17

    Lists or Tables

    Table BST AVL BB+Hashing

    For table the

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    6/17

    The time complexity for an table is O(n).

    To search an element in an table it may take

    maximum of n iteration for n elements. So to over come above problems we

    introduced BST(binary search tree).

    The time complexity of an BST is O(log2 n).

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    7/17

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    8/17

    Its has no difference between tables and BST if

    it is not a balanced tress.

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    9/17

    AVL tress

    An AVL tree is a binary search tree which has

    the following properties.

    The sub-trees of every node differ in height by

    at most one.

    Every sub-tree is an AVL tree.

    An balanced BST is an is an AVL tree.

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    10/17

    B tress

    In BST and AVL we have only oneroot element and time complexity isO(log n)

    If we have m elements in root thetime complexity is O(log m n).

    Where m is number of elements inroot.

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    11/17

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    12/17

    If we have even number of keys the it arises

    two cases

    left biased

    right biased

    B+ tree is an advanced version of b tree.

    When a leaf node would split off, its reference

    is kept in successor node.

    If an internal node would split up its same asin B tree.

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    13/17

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    14/17

    Hashing

    Hash tables support one of the most efficient types ofsearching hashing. Fundamentally, a hash table consistsof an array in which data is accessed via a special indexcalled a key.

    The primary idea behind a hash table is to establish amapping

    between the set of all possible keys and positions inthe array using a hash function. A hash function

    accepts a key and returns its hash coding, or hashvalue.

    Keys vary in type, but hash coding are always integers.

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    15/17

    The complexity of good hash function is O(1).

    The complexity of bad hash function is O(n).

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    16/17

  • 8/2/2019 Algorithms Complexity and Data Structures Efficiency (1)

    17/17