Home »
Data Structure
Array Data Structure
An array is a data structure for storing elements of one data type sequentially. The elements of an array are allocated at the adjacent memory location. Each element of an array is uniquely identified by an array index or key. In general, the simplest form of data structure is a linear array known as a one-dimensional array.
Arrays are known to be the most important data structure because of its wide use as it's used in implementing other data structures as hash-table, heaps, stack, queue, etc. Arrays are one of the oldest data structures in the computer programming field.
Following diagram explains arrays:
The memory location of the first element of the array is, in general, is in general by the name of the array. For the above case, Arr is that location that points to the first element.
Searching and Sorting
- Alternative Sorting
- Sort a Nearly Sorted Array (K Sorted Array)
- Sort an array according to the absolute difference of the given value
- Sort an array in waveform
- Sort an array that contains 1 to N elements
- Sort an array that contains only 0's and 1's
- Sort 1 to N by swapping adjacent elements
- Sort elements by frequency (Solution 2)
- Sort an Array of 0s, 1s and 2s
- Union and Intersection of Two Sorted Arrays
- Union and Intersection of Two Unsorted Arrays
- Shortest Un-ordered Subarray
- Two elements whose sum is closest to zero
- Print all distinct elements of a given integer array
- Product of maximum in the first array and minimum in second
- Merge an array of size n into another array of size m+n
- Find the minimum length unsorted subarray, sorting which makes the complete array sorted
- Median in a stream of integers (running integers)
- Count the number of possible triangles
- Find the number of pairs(x, y) in an array such that x^y > y^x
- Construct an array from its pair-sum array
- Count all distinct pairs with difference equal to k
Array Rotation
- Program for array rotation
- Reversal Algorithm of Array Rotation
- Block Swap Algorithm for Array Rotation
- Program to Cyclically Rotate an Array by One
- Search an element in a sorted and rotated array
- Given a sorted and rotated array, find if there is a pair with a given sum
- Find maximum value of Sum( i*array[i] ) with only rotations on given array allowed
- Find the rotation count in rotated sorted array
- Quickly find multiple left rotations of an array
- Find the minimum element in a sorted and rotated array
- Reversal algorithm for right rotation of an array
- Queries on Left and Right Circular Shift on the Array
- Print left rotation of array in O(n) time and O(1) space
- Find element at given index after a number of rotations
Arrangement Rearrangement
- Rearrange the element such that array[i] = i
- Write a program to reverse an array
- Move all zeroes to the end of the array
- Minimum swaps required to bring all elements less than or equal to k together
- Rearrange the array such that the even positioned are greater than odd
- Rearrange the array in order - smallest, largest, 2nd smallest, 2nd largest, so on
- Double the first element and move zero to end
- Reorder an array according to given indexes
- Rearrange the array such that arr[i]>=arr[j] if i is even and arr[i]<=arr[j] if i is odd and j<i
- Arrange given numbers to form the biggest number
- Rearrange an array in maximum minimum form
- Rearrange an Array in maximum minimum form with O(1) extra space
- Move all negative elements to end in order with extra space allowed
- Rearrange the array such that even index elements are smaller and the odd index elements are greater
- Replace every array element by multiplication of previous and next
- Rearrange positive and negative elements in O(n) time and O(1) extra space
- Shuffle a given array using Fisher-Yates shuffle Algorithm
- Segregate odd and even numbers using Lomuto's Partition scheme
Array coding problems