Difference between Subarray, Subsequence & Subset
- SubArray
A subbarray is a contiguous part of array. It is an another array which is inside the original array.
for example: If an array A = { 1, 2, 3 }, then the subarrays of array A will be (1), (2), (3), (1,2), (2,3) and (1,2,3)
Note : for an array of length n, there are n(n+1)/2 subarrays.
2. SubSequence
A subsequence is a sequence that can be derived from another sequence by zero or more elements, without changing the order of the remaining elements.
For the same example, there are 15 sub-sequences. They are (1), (2), (3), (1,2), (1,3), (2,3), (1,2,3). More generally, we can say that for a sequence of size n, we can have (2n-1) non-empty sub-sequences in total.