Skip to content

surazkarn/Data-Structure-and-Algorithm

Repository files navigation

Data Structure and Algorithm

1 ---------------------------------------------------------------------------------------------------------------

  1. WAP to find out the smallest and largest element stored in an array of n integers.

2.WAP to reverse the contents of a dynamic array of n elements.

3.WAP to search an element in a dynamic array of n numbers.

4.WAP to sort a dynamic array of n numbers.

5.Given an unsorted dynamic array of size n, WAP to find and display the number of elements between two elements a and b (both inclusive). E.g. Input : arr = [1, 2, 2, 7, 5, 4], a=2 and b=5, Output : 4 and the numbers are: 2, 2, 5, 4.

6.Given a dynamic array, WAP to print the next greater element (NGE) for every element. The next greater element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as -1. E.g. For the input array [2, 5, 3, 9, 7], the next greater elements for each elements are as follows.

             Element             NEG

            2                         5
            5                         9
            3                         9
            9                         -1
            7                         -1
  1. Let A be nXn square dynamic matrix. WAP by using appropriate user defined functions for the following:

a) Find the number of nonzero elements in A b) Find the sum of the elements above the leading diagonal. c) Display the elements below the minor diagonal. d) Find the product of the diagonal elements.

2 -------------------------------------------------------------------------------------------------------------------------------------

  1. WAP to calculate x^y(x power y) by writing a function(say POWER) for it.

2.WAP to test whether a number n is palindrome number or not using function.

3.WAP to count number of digits of a positive integer n by using recursion.

  1. WAP to find the first digit of a number using function. Example : if the number is 1234. output is 1.

  2. WAP to read a number and delete the even location digit of that number.Example : i) input 1234. output is 13. ii) input 357 output is 37 iii) input 7637272 output is 7322

  3. WAP to test whether a number num (num is entered through keyboard) is a number in the Fibonacci sequence or not.

7.WAP to find out the sum of n elements of an integer array a[] by using recursion.

8.WAP to find the LCM of two numbers a and b by using a suitable function (say LCM) for this.

  1. WAP by designing a recursive function to calculate the sum of all even digits of any given integer.

  2. WAP to find the factorial of a number n by writing a recursive function for it.

  3. WAP to store n employee’s data such as employee name, gender, designation, department, basic pay. Calculate the gross pay of each employees as follows: Gross pay = basic pay + HR + DA HR=25% of basic and DA=75% of basic.

12.WAP to add two distances (in km-meter) by passing structure to a function.

  1. Modify 12 to return a structure pointer

14.WAP return an array of structure using pointer.

3 -------------------------------------------------------------------------------------------------------------------------------------

1.Given an unsorted dynamic array arr and two numbers x and y, find the minimum distance between x and y in arr. The array might also contain duplicates. You may assume that both x and y are different and present in arr. Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4.

2.WAP to find out the second smallest and second largest element stored in a dynamic array.

3.WAP to arrange the elements of a dynamic array such that all even numbers are followed by all odd numbers.

4.Write a program to replace every element in the dynamic array with the next greatest element present in the same array.

5.WAP to replace every dynamic array element by multiplication of previous and next of an n element.

6.WAP to sort rows of a dynamic matrix having m rows and n columns in ascending and columns in descending order.

7.WAP to find out the kth smallest and kth largest element stored in a dynamic array of n integers, where k<n.

8.WAP to find the largest number and counts the occurrence of the largest number in a dynamic array of n integers using a single loop.

9.You are given an array of 0s and 1s in random order. Segregate 0s on left side and 1s on right side of the array. Traverse array only once.

10.WAP to swap all the elements in the 1st column with all the corresponding elements in the last column, and 2nd column with the second last column and 3rd with 3rd last etc. of a 2-D dynamic array. Display the matrix.

11.WAP to arrange the elements of a dynamic array such that all even numbers are followed by all odd numbers using a single loop. 0

4 -------------------------------------------------------------------------------------------------------------------------------------

1.WAP to store n employee’s data such as employee name, gender, designation, department, basic pay. Calculate the gross pay of each employees as follows: Gross pay = basic pay + HR + DA HR=25% of basic and DA=75% of basic.

2.WAP to add two distances (in km-meter) by passing structure to a function.

3.Write a program to perform the following operations in a single linked list by using suitable user defined functions for each case separately. a) create a link list b) Traversal of the list. c) Check if the list is empty. d) insert a new node at the beginning. e) delete a node at the beginning. f) insert a new node at the end. g)delete a node at the end. h) count the total number of elements in a single linked list. i) count total number of odd and even elements. j) count how many primes are there in the linked list k) check the linked list is palindrome or not.