Difference between Subarray, Subsequence & Subset

Hardeep Kaur
1 min readAug 19, 2020
  1. 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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Hardeep Kaur
Hardeep Kaur

Written by Hardeep Kaur

Software Engineer at Google, Ex- Smallcase

No responses yet

Write a response