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:

Array data structure

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

  1. Alternative Sorting
  2. Sort a Nearly Sorted Array (K Sorted Array)
  3. Sort an array according to the absolute difference of the given value
  4. Sort an array in waveform
  5. Sort an array that contains 1 to N elements
  6. Sort an array that contains only 0's and 1's
  7. Sort 1 to N by swapping adjacent elements
  8. Sort elements by frequency (Solution 2)
  9. Sort an Array of 0s, 1s and 2s
  10. Union and Intersection of Two Sorted Arrays
  11. Union and Intersection of Two Unsorted Arrays
  12. Shortest Un-ordered Subarray
  13. Two elements whose sum is closest to zero
  14. Print all distinct elements of a given integer array
  15. Product of maximum in the first array and minimum in second
  16. Merge an array of size n into another array of size m+n
  17. Find the minimum length unsorted subarray, sorting which makes the complete array sorted
  18. Median in a stream of integers (running integers)
  19. Count the number of possible triangles
  20. Find the number of pairs(x, y) in an array such that x^y > y^x
  21. Construct an array from its pair-sum array
  22. Count all distinct pairs with difference equal to k

Array Rotation

  1. Program for array rotation
  2. Reversal Algorithm of Array Rotation
  3. Block Swap Algorithm for Array Rotation
  4. Program to Cyclically Rotate an Array by One
  5. Search an element in a sorted and rotated array
  6. Given a sorted and rotated array, find if there is a pair with a given sum
  7. Find maximum value of Sum( i*array[i] ) with only rotations on given array allowed
  8. Find the rotation count in rotated sorted array
  9. Quickly find multiple left rotations of an array
  10. Find the minimum element in a sorted and rotated array
  11. Reversal algorithm for right rotation of an array
  12. Queries on Left and Right Circular Shift on the Array
  13. Print left rotation of array in O(n) time and O(1) space
  14. Find element at given index after a number of rotations

Arrangement Rearrangement

  1. Rearrange the element such that array[i] = i
  2. Write a program to reverse an array
  3. Move all zeroes to the end of the array
  4. Minimum swaps required to bring all elements less than or equal to k together
  5. Rearrange the array such that the even positioned are greater than odd
  6. Rearrange the array in order - smallest, largest, 2nd smallest, 2nd largest, so on
  7. Double the first element and move zero to end
  8. Reorder an array according to given indexes
  9. 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
  10. Arrange given numbers to form the biggest number
  11. Rearrange an array in maximum minimum form
  12. Rearrange an Array in maximum minimum form with O(1) extra space
  13. Move all negative elements to end in order with extra space allowed
  14. Rearrange the array such that even index elements are smaller and the odd index elements are greater
  15. Replace every array element by multiplication of previous and next
  16. Rearrange positive and negative elements in O(n) time and O(1) extra space
  17. Shuffle a given array using Fisher-Yates shuffle Algorithm
  18. Segregate odd and even numbers using Lomuto's Partition scheme

Array coding problems





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.