Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Definition of subarray

Tags:

arrays

I am unclear about the definition of a sub array. Does it mean a contiguous list of indexes , such as a[i..j] or can it be non contiguous, such as a[0], a[5],a[6]

like image 443
Programmer Avatar asked Mar 14 '11 12:03

Programmer


2 Answers

Subarrays are arrays within another array.Subarrays contains contiguous elements whereas subsequences are not.

An Example would make it clear

Consider an array {1,2,3,4}

List of all its subarrays are {},{1},{2},{3},{4},{1,2},{2,3},{3,4},{1,2,3,4}

List of all its subsequences are {},{1},{2},{3},{4},{1,2},{1,3},{1,4},{2,3},{2,4},{3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4},{1,2,3,4}

like image 63
Uttamraj Rangapur Avatar answered Oct 17 '22 22:10

Uttamraj Rangapur


I think the subarray means the array in which the contiguousness is based on the index . for example lets take an example

2 3 1 3 1 (index are 0,1,2,3,4 respectively )

so subarray is 2,3,1 3 (index 0,1,2,3) But (1,2 1) (index 2,0,4) cannot be a subarray coz the indexes are non-contiguous ..

Hope its helpfull ;)

like image 22
CRAZY_LOVER Avatar answered Oct 17 '22 21:10

CRAZY_LOVER