Assignment 5. Arrays 2
Assignment 5. Arrays 2
&
Data
Structures
With
C++
Assignment
5
Arrays
2
1. Implement following a. Binary Search
b. Selection Sort
c. Bubble Sort
d. Insertion Sort.
2. Given an array of positive and negative numbers, find if there is a subarray
(consecutive elements) with 0 sum.
3. Given an array of random numbers, push all the zeros of a given array to the
end of the array. For example,
Input : {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0}
Output : {1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0}.
The order of all other elements should be same.
4. Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements
(towards right).
Eg. Input : {1, 2, 3, 4, 5, 6, 7} n = 7 and d = 2
Output : {3, 4, 5, 6, 7, 1, 2}
5. Find second largest element in an array.
6. A sorted array has been rotated by some number k in clockwise direction. Find
k. E.g. Input: 5,6,1,2,3,4 Output: 2
7. Given an array of integers, sort the array into a wave like array and print it. In
other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >=
a4 <= a5 >= a6....
8. Given a 2D array of size n x n, where every row and column is sorted in
increasing order. Given a number x, check whether this x is present in the
given array.