Download Some Data Structure problems with test cases and more Exams Data Structures and Algorithms in PDF only on Docsity!
- (^) Given two sorted arrays X[ ] and Y[ ] of size m and n each, merge elements of X[ ] with elements of array Y[ ] by maintaining the sorted order. i.e. fill X[ ] with first m smallest elements and fill Y[ ] with remaining elements. Input: First number denotes number of elements in first array m and second number denotes number of elements in second array n. Next m+n numbers are elements of two arrays individually sorted. Output: Printing two arrays in sorted order attaining number of elements in the arrays. Example: Input: 4 3 2 4 6 8 1 3 5 Output: 1 2 3 4 5 6 8 Test Cases: Case2: Input: 4 5 1 3 5 7
Output: 1 2 3 4 5 6 7 8 9 10 Case 3: Input: 6 5 1 2 5 7 8 10 3 11 13 15 16 Output: 1 2 3 5 7 8 10 11 13 15 16 Case 4: Input: 3 2 11 12 13 9 10 Output: 9 10 11 12 13
- Given two sorted arrays X[ ] and Y[ ] of size m and n each where m >= n and X[ ] has exactly n vacant cells(vacant cell is denoted by 0), merge elements of Y[ ] in their correct position in array X[ ] i.e. merge (X, Y) by keeping the sorted order. Input:
Case 3:
Input: 8 5 1 0 4 0 5 0 0 0 2 6 7 8 9 Output: 1 2 4 5 6 7 8 9 Case 4: Input: 11 6 6 0 0 8 10 15 0 18 0 0 0 2 3 4 7 8 9 2 3 4 6 7 8 8 9 10 15 18 Case 5: Input: 11 6 0 11 0 12 0 13 0 14 0 15 0 11 12 13 14 15 16
- The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array. 1) The subarray which is already sorted. 2) Remaining subarray which is unsorted. In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray. Now, Implement the selection sort Iterative way
- Implement the above sorting in recursive way.
- Given two sorted arrays X[ ] and Y[ ] of size m and n each where m >= n and X[ ] has exactly n vacant cells(vacant cell is denoted by 0), merge elements of Y[ ] in their correct position in array X[ ] i.e. merge (X, Y) by keeping the sorted order. Input: First number denotes number of elements in first array m and second number denotes number of elements in second array n. Next m+n numbers are elements of two arrays. X[ ] = { 0, 2, 0, 3, 0, 5, 6, 0, 0} Y[ ] = { 1, 8, 9, 10, 15 } The vacant cells in X[ ] is represented by 0
Output: Merging the second array elements in their correct position in first array. X[ ] = { 1, 2, 3, 5, 6, 8, 9, 10, 15 } The above can be represented
Output: -5 -4 9
Case 4: Input: 8 -2 -3 -4 -5 1 2 3 4 Output: -5 -4 4
Case 5: Input: 7 -1 -2 -3 -4 -5 -6 - Output: -1 -2 -
- How do you implement if you want to find minimum product in the above question
- Given an array of integers, move all 0’s present must move to end without changing relative order of non-zeros.
Input: First line integer represents number of array elements and Next line contains n integers Output: print the non-zeros in the relative order flowed by all zeros present in the array Example:- Input: 7 4 0 2 0 3 0 9 Output: