Subarrays, Subsequences, and Subsets in Array

  • Last Updated : 15 Sep, 2022

What is a Subarray?

A subarray is a contiguous part of array, i.e., Subarray is an array that is inside another array.

In general, for an array of size n, there are n*(n+1)/2 non-empty subarrays.

For example, Consider the array [1, 2, 3, 4], There are 10 non-empty sub-arrays. The subarrays are:

(1), (2), (3), (4), 
(1,2), (2,3), (3,4), 
(1,2,3), (2,3,4), and 

What is a Subsequence?

A subsequence is a sequence that can be derived from another sequence by removing zero or more elements, without changing the order of the remaining elements.

More generally, we can say that for a sequence of size n, we can have (2n – 1) non-empty sub-sequences in total.

For the same above example, there are 15 sub-sequences. They are:

(1), (2), (3), (4), 
(1,2), (1,3),(1,4), (2,3), (2,4), (3,4), 
(1,2,3), (1,2,4), (1,3,4), (2,3,4), 

What is a Subset?

If a Set has all its elements belonging to other sets, this set will be known as a subset of the other set.

A Subset is denoted as ““. If set A is a subset of set B, it is represented as A ⊆ B.

For example, Let Set_A = {m, n, o, p, q}, Set_ B = {k, l, m, n, o, p, q, r}

Then, A ⊆ B.




Problems on Subarray:

Problems on Subsequence:

Problems on Subset:

Data Structure and Algorithms Course
Recent articles on Subarray
Recent articles on Subsequence
Recent articles on Subset

Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above

My Personal Notes arrow_drop_up

Writing code in comment? Please use, generate link and share the link here.