Arrays

75 programs in this topic — each includes source code, sample output and explanation.

  1. Array Initialization and Traversal

    This program demonstrates initialization and traversal of a single dimensional array.

  2. Array Sum Calculation

    This program calculates the sum of elements in an array.

  3. Array Maximum Element

    This program finds the maximum element in an array.

  4. Array Reverse Traversal

    This program prints array elements in reverse order.

  5. Array Average Calculation

    This program calculates the average of array elements.

  6. Linear Search in Array

    This program performs linear search to find an element in an array.

  7. Binary Search in Array

    This program performs binary search to find an element in a sorted array.

  8. Bubble Sort Implementation

    This program sorts an array using bubble sort algorithm.

  9. Selection Sort Implementation

    This program sorts an array using selection sort algorithm.

  10. Insertion Sort Implementation

    This program sorts an array using insertion sort algorithm.

  11. Copy Elements of Array

    This program copies elements from one array to another.

  12. Merge Two Arrays

    This program merges two arrays into one.

  13. Insert Element in Array

    This program inserts an element at a specific position in an array.

  14. Delete Element from Array

    This program deletes an element from a specific position in an array.

  15. Rotate Array Elements

    This program rotates array elements to the left by 2 positions.

  16. Matrix Initialization and Display

    This program initializes and displays a 3x3 matrix.

  17. Addition of Two Matrices

    This program adds two matrices element wise.

  18. Subtraction of Two Matrices

    This program subtracts one matrix from another element wise.

  19. Multiplication of Two Matrices

    This program multiplies two matrices.

  20. Transpose of Matrix

    This program finds the transpose of a matrix.

  21. Sum of Main Diagonal Elements

    This program calculates the sum of main diagonal elements of a matrix.

  22. Sum of Secondary Diagonal Elements

    This program calculates the sum of secondary diagonal elements of a matrix.

  23. Row Sum of Matrix

    This program calculates the sum of each row in a matrix.

  24. Column Sum of Matrix

    This program calculates the sum of each column in a matrix.

  25. Identity Matrix Check

    This program checks if a matrix is an identity matrix.

  26. Symmetric Matrix Check

    This program checks if a matrix is symmetric.

  27. Sparse Matrix Check

    This program checks if a matrix is sparse.

  28. Boundary Elements of Matrix

    This program prints boundary elements of a matrix.

  29. Rotate Matrix 90 Degrees

    This program rotates a matrix by 90 degrees clockwise.

  30. Rotate Matrix 180 Degrees

    This program rotates a matrix by 180 degrees.

  31. Rotate Matrix 270 Degrees

    This program rotates a matrix by 270 degrees clockwise (or 90 degrees counter clockwise).

  32. Symmetric Matrix Extended Check

    This program checks if a matrix is symmetric and prints mismatched positions.

  33. Sparse Matrix Representation

    This program represents a sparse matrix using triplet form.

  34. Boundary Sum of Matrix

    This program calculates the sum of boundary elements of a matrix.

  35. Spiral Traversal of Matrix

    This program prints elements of a matrix in spiral order.

  36. Linear Search with Early Exit

    This program performs linear search with early exit optimization.

  37. Recursive Binary Search

    This program performs binary search using recursion.

  38. Print Both Diagonals of Matrix

    This program prints both main and secondary diagonals of a matrix.

  39. Jagged Array Initialization

    This program initializes and displays a jagged array.

  40. Jagged Array Traversal

    This program traverses a jagged array and prints elements with indices.

  41. Frequency of Elements in Array

    This program calculates frequency of each element in an array.

  42. Frequency of Characters in Array

    This program calculates frequency of characters in a character array.

  43. Find Most Frequent Element

    This program finds the most frequent element in an array.

  44. Find Least Frequent Element

    This program finds the least frequent element in an array.

  45. Frequency Distribution of Array

    This program prints frequency distribution of elements in an array.

  46. Prefix Sum of Array

    This program calculates prefix sums of an array.

  47. Maximum Subarray Sum (Kadane's Algorithm)

    This program finds maximum subarray sum using Kadane's algorithm.

  48. Subarray with Given Sum

    This program finds subarray with a given sum.

  49. Boundary Traversal of Matrix

    This program prints boundary traversal of a matrix.

  50. Check Rotated Matrix Equality

    This program checks if one matrix is rotation of another.

  51. Range Sum Query using Prefix Sum

    This program answers range sum queries using prefix sums.

  52. Maximum Length Subarray with Given Sum

    This program finds maximum length subarray with sum equal to target.

  53. Spiral Traversal Extended

    This program prints elements of a 4x4 matrix in spiral order.

  54. Check Rotated Matrix Equality (180 Degrees)

    This program checks if one matrix is rotation of another by 180 degrees.

  55. Check Rotated Matrix Equality (270 Degrees)

    This program checks if one matrix is rotation of another by 270 degrees.

  56. Partition Array into Even and Odd

    This program partitions an array into even and odd numbers.

  57. Partition Array Around Pivot

    This program partitions an array around a pivot element.

  58. Find Equilibrium Index

    This program finds equilibrium index of an array.

  59. Boundary Diagonals of Matrix

    This program prints boundary diagonals of a matrix.

  60. Maximum Sum Subarray of Size K

    This program finds maximum sum subarray of size K using sliding window.

  61. Subarray with Given Sum using Two Pointers

    This program finds subarray with given sum using two pointers.

  62. Count Subarrays with Given Sum

    This program counts the number of subarrays with a given sum.

  63. Maximum Circular Subarray Sum

    This program finds maximum circular subarray sum.

  64. Sum of Boundary Diagonals

    This program calculates sum of both diagonals of a matrix.

  65. Longest Subarray with Equal 0s and 1s

    This program finds longest subarray with equal number of 0s and 1s.

  66. Optimized In Place Transpose of Square Matrix

    This program performs in place transpose of a square matrix without using extra space.

  67. Rotated Spiral Traversal

    This program prints matrix elements in spiral order starting from bottom left corner.

  68. Sparse Matrix Compression (Triplet Form)

    This program compresses sparse matrix into triplet form.

  69. Maximum Product Subarray

    This program finds maximum product subarray.

  70. Subarray Product Less Than K

    This program counts subarrays with product less than K.

  71. Transpose and Rotate Matrix

    This program transposes a matrix and then rotates it by 90 degrees.

  72. Reverse Spiral Traversal

    This program prints matrix elements in reverse spiral order.

  73. Sparse Matrix Compression (Row Wise)

    This program compresses sparse matrix row wise.

  74. Subarray Product Equals Target

    This program finds subarray with product equal to target.

  75. Maximum Product of Subarray of Size K

    This program finds maximum product of subarray of fixed size K.

Quick Links to Explore