Data Structures Key

Embed Size (px)

Citation preview

  • 7/31/2019 Data Structures Key

    1/6

    GRT GROUP OF EDUCATIONAL INSTITUTIONS

    GRT INSTITUTE OF ENGINEERING AND TECHNOLOGY

    DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

    DATA STRUCTURES

    UNIT I (2 Marks and 16 Marks Answers)

    PART A

    1. What is meant by an Abstract data type (ADT)?

    An Abstract data type (ADT) is a set of operations. Abstract data types are

    Mathematical abstractions.

    Example:

    Object such as set, list, and graphs along their operations can be viewed as ADT. Union,intersection, size, complement and find are the various operations of ADT.

    2. What does List ADT mean?

    General list: A1, A2, A3,..An

    A1-> first element

    An-> last element

    In general Ai is an element in a list I

    Ai-> current element position

    Ai+1-> predecessor

    3. What are the various operations done under list ADT?

    Insert element insertion

    Ex: Insert (x, 3)

    Insert the element X in 3rd position

    Delete-Element deletion

    Ex: Delete (52)

    Deletes the element

    Find-searching an element in the list

    Ex: find (34)

    Finds the element

    * Next -Successor

    * Previous -predecessor

    * Print list -Print all the elements in the list

    *Make empty - Emptying the list

  • 7/31/2019 Data Structures Key

    2/6

  • 7/31/2019 Data Structures Key

    3/6

    Consider the list

    W E L C O M E

    A (0) A (1) A (2) A (3) A (4) A (5) A (6)..A (50)

    To delete L

    Step 1: Find the position of the element.

    Step 2: Delete the data and push all other data up

    W E C O M E

    A (0) A (1) A (2) A (3) A (4) A (5).A (50)

    10.What is doubly linked list?

    In a simple linked list , there will be one pointer named as NEXT POINTER to point

    the next element /data location, where as in a doubly linked list, there will be two pointers one

    to point the next and other to point the previous element location

    11.Define double circularly linked list.

    In doubly circular linked list, if the last node or pointer of the list, points to the first

    element of the list, then it is a circularly linked list

    12. List three examples that use linked list.

    Linked list are used by,

    1. Polynomial ADT

    2. Radix sort3. Multi lists.

    13. What is the cursor implementation of linked list?

    1. Data is stored in a collection of objects; each object contains the data and a pointer to

    the next object.

    2. A new object that can be obtained from the system is global memory by a call to new

    and released by a call to delete

    14. What are the applications of stack?

    Stack can be applied in different situations. Some of the examples where is applied are

    explained below.

    1. Infix, Prefix & Postfix expression.

    2. Conversion of infix to postfix expression.

    3. Evaluating postfix expression.

    4. Balancing symbols. 5. Tower of Hanoi.

  • 7/31/2019 Data Structures Key

    4/6

    15. Assuming S as an array representing the stack, Top is the pointer to top of the stack

    and N is the maximum capacity of the stack, write an algorithm for pushing an element in

    to the stack.

    Algorithm for pushing an element into the stack

    Step 1: If Top >= N

    Then write (stack overflow)

    Return

    Step 2: Top Top +1

    Step 3: S [Top] X

    Step 4: Return.

    16.Assuming S as an array representing the stack, Top is the pointer to top of the stack

    and N is the maximum capacity of the stack, write an algorithm for popping an element

    from the stack.

    Algorithm for popping an element from the stack

    Step 1: [Check for underflow on stack]

    If Top = 0

    Then write (Stack overflow on pop)

    Exit

    Step 2: [Decrement pointer]

    Top Top 1

    Step 3: [Return former top element of stack]

    Return (S [Top +1])

    17.Assuming S as an array representing the stack, Top is the pointer to top of the stack

    and N is the maximum capacity of the stack, write an algorithm to find out or display the

    content of the stack at a particular index.

    Algorithm for popping into the stack at an Index I:

    Step 1: [Check for stack underflow]

    If Top I + 1 0

    Then write (Stack underflow on peep]

    Exit.

    Step 2: [Return the element from top of stack]

    Return (S [Top I + 1])

  • 7/31/2019 Data Structures Key

    5/6

    18. Assuming S as an array representing the stack, Top is the pointer to top of the stack

    and N is the maximum capacity of the stack, write an algorithm to change the content of

    the stack at location I.

    Algorithm to change the content of the stack at location I.

    Step 1: [Check for Stack underflow]

    If Top I + 1 0

    Then write (Stack underflow on change)

    Return.

    Step 2: [Check the I th element from the top of the stack]

    S [Top I + 1] X

    Step 3: [Finished]

    Return

    19. What is the solution for the Towers of Hanoi problem?

    The solution for the Tower of Hanoi problem is,

    1. Move N-1 disk from A to B.

    2. Move disc N from A to C.

    3. Move N-1 disk from B to C.

    20. What is meant by list ADT?

    List ADT is a sequential storage structure, general list of the form a1, a2, a3an and the

    size of the list is n. any element in the list at the position i is defined to be ai.ai+1 is the

    successor of ai and ai-1 is the predecessor of ai.

    21. What are the different ways to implement the list?

    Ways to implement the lists are,

    1. Simple array implementation of list

    2. Linked list implementation of list

    22. What is a pointer?

    Pointer is a variable, which stores the address of the next element in the list. Pointer is

    basically a number.

    23. Why do we convert the infix expression into suffix expression?

    We find it more convenient, to evaluate an infix arithmetical expression by first

    converting it to a suffix expression and then evaluating the latter. This approach will eliminate

    the repeated scanning of an infix expression, in order to obtain its value.

  • 7/31/2019 Data Structures Key

    6/6

    24. What is meant by degree of an operator?

    The degree of an operator is a number of operands, which that operator has, example:

    Degree of the addition operator is two.

    25. Define suffix expression.

    Suffix expression is given by,

    1. A single symbol is an expression

    2. If x1,x2,xn are expressions and oi is of degree n, then x1,x2,..xn oi is

    an expression

    3. The only valid expressions are those obtained by steps a and b.

    PART B

    1. What is stack ADT? Give any implementation of stack ADT and explain clearly the

    data structures with routines.(16)

    i) Definition of stack (2)

    ii) Explanation of ADT (2)

    iii)Example(6)

    iv)Explanation(6)

    2. How does a Queue works? Give one example for insertion and deletion of elements

    from queue.(16)

    i) Definition of queue (2)

    ii) Algorithm for insertion (7)

    iii)Algorithm for deletion(7)

    3.(i)What is meant by ADT?Expalin in detail about ADT?(8)

    i)Definition of ADT.(2)

    ii)Explanation of ADT.(4)

    iii)Diagram(2)

    3.(ii)What is meant by linked list?Expalin in detail.(8)

    i)Definition of linked list(2)

    ii)Explanation(6)