Subsequence Vs Substring Vs Subarray
Substring π
A substring is a contiguous(continuous) sequence of characters present within a string. It is a string present inside a string.
For instance, the substrings of the string βtreeβ would be:
βt,β βr,β βe,β βtr,β βtre,β βtree,β βre,β βree,β βeeβ and ββ
We can use single β β or double β β quotes to denote substring.
The entire string is a substring of itself.
An empty string is also a substring of the given string.
Sub-array π
We all know that an array is a contiguous memory block.
So a subarray is a contiguous sequence of elements within an array. An empty array is also a subarray of an array.
Arrays can be denoted by curly brackets {} or square brackets [].
The example below gives a clear view of the subarrays of an array:
int array[ ] = {1, 5, 4};
Therefore, subarrays for the array {1,5,4} are {1}, {1,5}, {1,5,4}, {5}, {5,4}, {4} and {}
Sequence π
A Sequence can be thought of as a list of elements with a particular order.
For example, [A, B, C, D, E, F] is a sequence or [1,4,3,2,1,5] => While the elements in this sequence are of different types (numbers and letters), they are presented in a specific order, separated by commas, which makes it a sequence.
Subsequence π
A subsequence is a sequence that can be derived from another sequence of elements without changing the order of the remaining elements.
For example: {A, B, D} is one of the subsequences of the sequence {A, B, C, D, E} obtained after removing {C} and {E}.
Parties: Subsequence and Longest Common Subsequence (LCS) https://www.youtube.com/watch?v=VbcDFmHkuoA
Subscribe to my newsletter
Read articles from Ashik Bhuyan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ashik Bhuyan
Ashik Bhuyan
A forward-thinking software engineer. who can work as a web developer in dynamic environments. Strong knowledge of MERN Stack with vast experience in building Web Applications, using React.js, Next.js, and Redux for the client side, Node.js/Express for the server side, and MongoDB, SQL Server for the database.