Substring VS Subsequence

Cho Zin Thet
Jan 25, 2021

--

Substring and Subsequence

Substring

Substring is a sub continous part of a string.

(a, b, c, d) has 10 substrings.

(a)(b)(c)(d)(a, b)(b, c)(c, d)(a, b, c)(b, c, d)(a, b, c, d)

Number of substrings in a string = (n * (n + 1) )/ 2 ;

Subsequence

Subsequence is a sub part of a string in order.

There are 15 subsequence in (a, b, c, d) string

(a)(b)(c)(d)(a,b)(a,c)(a,d)(b,c)(b,d)(c,d)(a,b,c)(a,b,d)(a,c,d)(b,c,d)(a,b,c,d)

Number of subsequence in a string =(2^n)-1;

--

--

Cho Zin Thet

Learning javascript and web-development