Data Structures and algorithms - Solution of first Sessional (SVSU)

0

Ques 1. What is Row major order and column major order method?

Ans. Row major and column order is used to store multidimensional array as one-dimensional array.

Row Major Order

in row major order, the elements of a particular row are stored at adjacent memory locations.
the first element of array (arr[0][0]) is stored at the first location followed by the arr[0][1] and so on. after the first row, elements of the next row are stored next.

arr[2][2] =   [a00, a01]
                   [b10, b11]

Row Major Order = a00, a01, b10, b11

Column Major Order

In column major order, the elements of a column are stored adjacent to each other in the memory.The first element of the array (arr[0][0]) is stored at the first location followed by the arr[1][0] and so on. After the first column, elements of the next column are stored stating from the top.

arr[2][2] = [a00, a01]
                 [b10, b11]

Column Major Order = a00, b10, a01, b11


Ques 2. What is Array with example?write it's operation.

Ans. An array is a collection of elements of similar data type.

int Array[] = {1, 3, 5, 8}

Operations on array
  1. Traversing
  2. Insertion 
  3. Deletion

Ques 3.  Define Data Structure. Explain its operation and types.


Ques 4. Explain PUSH and POP operations of stack with algorithm?

Ans. PUSH - The process of adding an element onto a stack is called PUSH.
        POP - The Process Of removing element from a stack is call POP.

        PUSH Algorithm

PUSH(STACK, TOP, MAX, DATA)
  1. If TOP = MAX
  2. then: print("STACK OVERFLOW") ELSE,
  3. Set TOP = TOP+1.
  4. Set STACK[TOP] = DATA.
  5. Return.
      POP Algorithm

POP(STACK, TOP, DATA)
  1. IF TOP=0, then: print("STACK UNDERFLOW). ELSE,
  2. Set DATA = STACK[TOP]
  3. Set TOP = TOP-1.
  4. Return.

Ques 5. Describe Radix sort with example?

Ans. Radix sort is a non-comparison-based sorting algorithm. The word radix, by definition, refers to the base or the number of unique digits used to represent numbers. In radix sort, we sort the elements by processing them in multiple passes, digit by digit. 

Example 


Ques 6. Describe application of stack?

Ans. 
  1. A Stack can be used for evaluating expressions consisting of operands and operators.
  2. Stacks can be used for Backtracking, i.e., to check parenthesis matching in an expression.
  3. It can also be used to convert one form of expression to another form.
  4. It can be used for systematic Memory Management

Ques 7. Explain the searching algorithm when list is sorted?

Ans. Binary search is an algorithm that works efficiently works on sorted arrays or lists hence, to search an element in a list we must ensure the list is sorted.

Binary search follows the divide and conquer technique in which we divide the list into two equal halves, and then we compare the ITEM with the middle of a list. If the match is found, then the location of the middle element is returned, otherwise we follows the same technique again in either halves of the list depending upon the output.






Post a Comment

0Comments
Post a Comment (0)