data structure first home work

Upload: narinder-pal-saini

Post on 10-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Data Structure First Home Work

    1/10

    ASSIGNMENT: - 1

    BY: - NARINDER PAL

    CLASS: - MSC (cs)

    DEPARTMENT: - COMPUTER SCINCE

    PART-A

    Q1:- Why structuring of data is required .Take one example problem and

    discuss various problems that can be faced if wrong choice has been made

    in selecting data structure for the problem.

    ANS: - DATA STRUCTURE : -

    A data structure is a specialized format for

    organizing and storing data. General data structure types include the array, the

    file, the record, the table, the tree, and so on. Any data structure is designed to

    organize data to suit a specific purpose so that it can be accessed and worked

    with in appropriate ways. In computer programming, a data structure may be

    selected or designed to store data for the purpose of working on it with various

    algorithms.

    In programming, the term data structure refers to a scheme for organizing

    related pieces of information. The basic types of

    Data Structures Include :-

  • 8/8/2019 Data Structure First Home Work

    2/10

    Files

    Lists

    Arrays

    RecordsTrees

    Tables

    Example : - The implementation of a data structure usually requires writing a

    set of procedures that create and manipulate instances of that structure. The

    efficiency of a data structure cannot be analyzed separately from those

    operations.

    Take 10 numbers and store them in number1, number2, number3,

    number4 .. number10

    Set max = number5.

    If number2 > max then: max = number2

    If number3 > max then: max = number3:

    If number10 > max then max = number10Display max

    On the other hand: When an array of size 50 is used, the algorithm can be

    written as:-

    1. Set max = number [0]

    2. Repeat step3 varying i from 1 to 49

    3.If number[i] > max then: max = number[i]

    4. Display max

    From the preceding two algorithms, it can be seen that the algorithm using an

    array manipulates memory much more efficiently than the algorithm using 50

    variables. Also, the algorithm using an array involves few steps and is

    therefore, easier to understand and implement as compared to the algorithm that

    uses 50 variables.

  • 8/8/2019 Data Structure First Home Work

    3/10

    Q2 Delineate the concept of abstract data type in data structures.

    ANS: - INTROCUCTION OF ABSTRACT DATA TYPE : -

    A set of data

    values and associated operations that are precisely specified independent of any

    particular implementation. Also known as ADT.

    A n abstract data type is a

    mathematical model for a certain class of data structures that have similar behaviour; or for certain data types of one or more programming languages that

    have similar semantics. An abstract data type is defined indirectly, only by the

    operations that may be performed on it and by mathematical constraints on the

    effects (and possibly cost) of those operations.

    The implementation of a data structure usually requires writing a set of

    procedures that create and manipulate instances of that structure. The efficiencyof a data structure cannot be analyzed separately from those operations.

    This observation motivates the theoretical concept of an

    abstract data type, a data structure that is defined indirectly by the operations

    that may be performed on it, and the mathematical properties of those

    operations (including their space and time cost).

    Q3:- List out Applications areas of various data structure.

    ANS : - DATA STRUCTURE APPLICATION AREAS : -

    A data structure is

    used for the storage of data in computer so that data can be used efficiently. For

  • 8/8/2019 Data Structure First Home Work

    4/10

    the organization of mathematical and logical concepts data structure provides a

    methodology. With the proper selection of data structure you can also get

    efficient algorithm. With very few resources like memory space and time

    critical operations can be carried out with a well designed data structure. Themajor use of data structure is its implementation in the programming language.

    Database Management System

    Statistical Analysis Package

    Artificial Intelligence

    Simulation

    Compiler Design

    Perating System

    Numerical Analysis

    Graphics

    Operating System

    PART B

    Q4:-Elaborate the concept of Algorithm complexity and Complexity

    notations with suitable examples.

    ANS: - INTRODUCTION OF ALGORITHM COMPLEXITY: -

    An algorithm is a

    procedure (a finite set of well-defined instructions) for accomplishing some task

    which, given an initial state, will terminate in a defined end-state. The

    computational complexity and efficient implementation of the algorithm are

    important in computing, and this depends on suitable data structures.

  • 8/8/2019 Data Structure First Home Work

    5/10

    Examples of such resources would be time or memory storage. Nowadays,

    memory storage is almost a non-essential factor when designing algorithms but

    be aware that several systems still have memory constraints, such as Digital

    Signal Processors in embedded systems.

    Complexity notations:-

    Linear Search

    Binary Search

    Bubble Sort

    Selection SortInsertion Sort

    Heap Sort

    Merge Sort

    Quick Sort

    Examples of such resources would be time or memory storage.

    Nowadays, memory storage is almost a non-essential factor when

    designing algorithms but be aware that several systems still have memory

    constraints, such as Digital Signal Processors in embedded systems.

    Different algorithms may complete the same task with a different set of

    instructions innless or more time, space or effort than other. The analysis

    and study of algorithms is a discipline in Computer Science which has a

    strong mathematical background. It often relies on theoretical analysis of

    pseudo-code. To compare the efficiency of algorithms, we don't rely onabstract measures such as the time difference in running speed, since it

    too heavily relies on the processor power and other tasks running in

    parallel. The most common way of qualifying an algorithm is the

    Asymptotic Notation, also called Big O specific amount of a certain

    resource an algorithm needs.

    Examples of such resources would be time or memory storage.

    Nowadays, memory storage is almost a non-essential factor when

  • 8/8/2019 Data Structure First Home Work

    6/10

    designing algorithms but be aware that Processors in embedded systems.

    Different algorithms may complete the same task with a different set of

    instructions innless or more time, space or effort than other. The analysis

    and study of algorithms is a discipline in Computer Science which has astrong mathematical background. It often relies on theoretical analysis of

    pseudo-code.

    Q:-5 Consider the array NAME

    Mary

    Jane

    Diana

    Susan

    Karen

    Edith

    (i)Write the Algorithm to delete an element from an array and

    also delete jane from the array NAME.

    (ii) Write the algorithm to INSERT an element in an algorithm

    and also add ABC into the array NAME.

    ANS: - (1) Algorithm to delete an element from an array:-

    (Deleting an item from an Array) DELETE (LA,n,k,ele).

    Here LA is an

    Linear array with n elements and k is an positive integer

    Such that k

  • 8/8/2019 Data Structure First Home Work

    7/10

    1. Set

    Item=LA[k].

    2. Repeat for J= k to n-1 :

    [Move J+1st itemupward] Set A[J] := A[J+1].[End Of Loop.]

    3.[Reset the number n of elements in A] Set n := n-1.

    4. Exit.

    Algorithm to Delete jane from Array Name:-

    Here Name [0] =Marry,

    Name [1] =Jane, Name [2] =Diana,

    Name [3] =Susan,

    Name [4] =Karen,

    Name [5] =Edith.

    Steps of algorithm to delete Jane from Name

    Array: 1. Set item=jane.

    2. Repeat for J=1 to 5.

    [Move J+1 st item Upward] Set A[J]:=A[J+1].

    [End of Loop.]

    3. [Reset the number of element in A] set n=5.

    4. Exit.

    2algo

    (ii) Algorithm to insert an element in Array:-(Inserting into a linear Array)INSERT (LA,n,k,item)

    Here LA is an Linear

    Array with n elements and k is an positive

    Integer such that k=k.

  • 8/8/2019 Data Structure First Home Work

    8/10

    3. [Move Jth element downward] Set LA [J+1:= LA[J].

    4. [Decrease Counter.] Set J: = J-1.

    [End of Step 2 Loop].

    5. [Insert Element.] Set LA[k] =item.6. [Reset n.] Set n=n+1.

    7. Exit.

    Algorithm to insert ABC in Array at 7th Position 1.[Initialize counter] Set J:= 6

    and item=ABC.

    2. Repeat Steps 3 and 4 while J>=6.

    3. [Move Jth element downward] Set A[J+1] := A[J].4. [Decrease Counter.] Set J: = 5.

    [End of Step 2 Loop].

    5.[Insert Element.] Set A[k] =item.

    6. [Reset n.] Set n=7.

    7. Exit.

    6Q:- An array A contains 30 positive integers .Write algorithm which find

    all pair of elements whose sum is 25 .

    ANS:-

    #include

    #includeVoid main ()

    {

    Int a[30],I,m,n,k;

    printf(enter the 30 elementd);

    for (i=1;i

  • 8/8/2019 Data Structure First Home Work

    9/10

    }

    Printf(the elements are)

    For(i=1;i

  • 8/8/2019 Data Structure First Home Work

    10/10

    Void main ()

    {

    Float a [20], I;

    Printf (enter the markds of students);For (i=1;i