Subset vs Subsequence - GeeksforGeeks (2024)

Understanding the concepts of subsets and subsequences is essential in mathematics and computer science. Although they may seem similar at first glance, there are key differences between the two.

What is a Subset?

A subset is a set formed from another set by selecting zero or more elements, regardless of their order. In mathematical definition, a set A is a subset of set B if every element of A is also an element of B. This is denoted as A⊆B.

Key Characteristics of Subsets

  • Order Irrelevant: A subset is a collection of elements from a given set and the order in which the elements appear does not matter. This means that {1, 2} is considered the same subset as {2, 1}.
  • Duplicates Not Allowed: A subset contains unique elements. No element can appear more than once in a subset. Subsets are composed of distinct elements. Even if a set has duplicates, a subset can only contain each distinct element once.
  • Total Subsets: A set with n elements has exactly 2n subsets. This includes both the empty set (with no elements) and the set itself (with all elements). For each element in the set, there are two choices: either include the element in a subset or exclude it.

Example of Subset

For set s = {1, 2, 3}, the subsets are ϕ, {1}, {2}, {3}, {1,2}, {1,3}, {2,3} and {1,2,3}.

What is a Subsequence?

A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

Key Characteristics of Subsequences

  • Order Preserved: In a subsequence, the relative order of elements from the original sequence is preserved. However, elements are not required to be contiguous. For example, {2, 1} is not a subsequence of {1, 2, 3} because the order of 2 and 1 is reversed.
  • Duplicates Allowed: Unlike subsets, subsequences allow repeated elements. If the original sequence contains duplicate elements, those duplicates can appear in the subsequence as well. A subsequence is formed from the original sequence, and as such, it is allowed to include repeated elements from the original.
  • Total Subsequences: A sequence of n elements has 2n subsequences, including the empty subsequence and the sequence itself. This is because each element can either be included or excluded from a subsequence, giving two choices per element.

Example of Subsequence

For sequence s = {1,2,3}, the subsequences are {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3} and {1, 2, 3}. The number of subsequences is 23 = 8.

Difference Between Subset and Subsequence

CharacteristicSubsetSubsequence
Order of ElementsThe order of elements does not matter. A subset consists of any combination of elements chosen from the original set, regardless of their position. Example: For set s = {1, 2, 3}, subset {3, 2} is equivalent to {2, 3}.The elements must appear in the same relative order as in the original sequence, though they do not need to be contiguous. Example: For sequence s = {1, 2, 3}, subsequence {3, 2} is invalid, but {1, 3} or {2, 3} are valid.
Relationship with Original Set/SequenceDefined in the context of sets, duplicates are irrelevant.Defined in the context of sequences, duplicates are preserved.
Size and SelectionFormed by selecting any combination of elements from the set.Formed by deleting specific elements without rearranging the rest.
Contextual UsagePrimarily used in set theory and combinatorics.Primarily used in algorithms, string matching, and sequence alignment.
ExampleFor set s = {1, 2, 3}, subset {3,2} is valid because order does not matter.For subsequence s = {1, 2, 3}, subsequence {3, 2} is invalid because order is not preserved.

Frequently Asked Questions (FAQs)

What are the possible subsequence of s = {1,2,3}?

The total subsequences of s = {1, 2, 3} are: {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3} and {1, 2, 3}. So, there are 8 possible subsequences in total for the sequence s = [1, 2, 3], including the empty subsequence.

Is [2, 1] is a subset of {1, 2, 3} ?

Yes,the set {2, 1} is a subset of {1, 2, 3} because it contains elements 1 and 2, which are both present in {1, 2, 3} regardless of order.

Can a subset be a subsequence?

Yes, a subset can be a subsequence if the subset’s elements appear in the same relative order as they do in the original sequence.

Are subsets and subsequences equal in number?

Yes, the number of subsets and the number of subsequences are both equal to 2n for a sequence or set of size n.

Can subsequences contain duplicates?

Yes, subsequences can contain duplicates. This is because subsequences are derived by deleting some or no elements from the original sequence, but the relative order of the remaining elements must be preserved.


A

adityarana02

Subset vs Subsequence - GeeksforGeeks (1)

Improve

Previous Article

Longest subsequence with a given AND value

Next Article

Subset vs Subsequence - GeeksforGeeks (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Ray Christiansen

Last Updated:

Views: 6478

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.