Skip to content

Sub arrays

Arrays - Subarrays

A subarray is a slice from a contiguous array (i.e., occupy consecutive positions) and inherently maintains the order of elements.

Subarrays are arrays within another array.

  • For example, the subarrays of array {1, 2, 3} are {1}, {1, 2}, {1, 2, 3}, {2}, {2, 3}, and {3}.

sub_array_defn

Note:

  • No of Sub arrays for a Array of Size N - (N*(N+1))/2
  • No of Sub arrays of Size K for a Array of Size N - N-K+1

Problem 1 - Print all values of a sub array

print_values_of_a_subarray

Problem 2 - Sum of a given sub array

sum_of_a_given_subarray

Problem 3 - Print all Sub arrays of a Given Array

print_all_subarray

Problem 4 - Print Sum of Every Sub array

sum_sub_array

Problem 5 - Print Sum of all Sub arrays starting with a given index

sum_sub_arrays_starting_with_index_i

Problem 6 - Given an Array , Find the sum of all subarray sums. - Important

sum_of_all_subarray sum_all_sa_1 sa_all_sa_2 sa_all_sa_3 sa_all_sa_4