Open In App

Subarrays, Subsequences, and Subsets in Array

Last Updated : 15 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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 (1,2,3,4)

Subarray

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), (1,2,3,4).

Subsequences

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.

Subset

Easy Problems on Subarray:

Medium Problems on Subarray:

Hard Problems on Subarray:

Easy Problems on Subsequence:

Medium Problems on Subsequence:

Hard Problems on Subsequence:

Easy Problems on Subset:

Medium Problems on Subset:

Hard Problems on Subset:

Related Articles:

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads