Substring VS Subsequence

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;

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cho Zin Thet

Cho Zin Thet

Learning javascript and web-development