Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views1 page

Assignment 5. Arrays 2

The document provides 8 programming assignments involving arrays: 1) Implementing binary search, selection sort, bubble sort, and insertion sort. 2) Checking if a subarray with sum of 0 exists. 3) Pushing all zeros to the end of the array. 4) Rotating an array by a given number of elements. 5) Finding the second largest element. 6) Finding the number an array was rotated by. 7) Sorting an array into a wave-like format. 8) Checking if a number exists in a 2D array where rows and columns are sorted.

Uploaded by

tika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views1 page

Assignment 5. Arrays 2

The document provides 8 programming assignments involving arrays: 1) Implementing binary search, selection sort, bubble sort, and insertion sort. 2) Checking if a subarray with sum of 0 exists. 3) Pushing all zeros to the end of the array. 4) Rotating an array by a given number of elements. 5) Finding the second largest element. 6) Finding the number an array was rotated by. 7) Sorting an array into a wave-like format. 8) Checking if a number exists in a 2D array where rows and columns are sorted.

Uploaded by

tika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Foundations

& 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.

You might also like