Difference between subarray, subset & subsequence

前端 未结 6 2237
鱼传尺愫
鱼传尺愫 2020-12-08 02:49

I\'m a bit confused between subarray, subsequence & subset

if I have {1,2,3,4}

then

subsequence can be {1,2,4} OR

6条回答
  •  长情又很酷
    2020-12-08 03:13

    In the context of an array, SubSequence - need not be contigious but needs to maintain the order. But SubArray is contigious and inherently maintains the order.

    if you have {1,2,3,4} --- {1,3,4} is a valid SubSequence but its not a subarray.

    And subset is no order and no contigious.. So you {1,3,2} is a valid sub set but not a subsequence or subarray.

    {1,2} is a valid subarray, subset and subsequence.

    All Subarrays are subsequences and all subsequence are subset.

    But sometimes subset and subarrays and sub sequences are used interchangably and the word contigious is prefixed to make it more clear.

提交回复
热议问题