0% found this document useful (0 votes)
8 views

DSA Array&Strings Lecture 5

Uploaded by

ajay babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DSA Array&Strings Lecture 5

Uploaded by

ajay babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Arrays, Strings

Arrays
An array is a collection of data elements of similar type, such that the
elements in the array are stored at contiguous memory locations
Arrays have indexes, which can be used to access elements. Generally, in most
programming languages, indexing starts from 0, which means that the index of
the first element is 0
Consider, the following code block, which contains an array, and the indexes of
the different elements in the array

array -> [1,2,3,4,5]


Value - Index
1 0
2 1
3 2
4 3
5 4

Strings
Strings are a group of characters. They can also be referred as an array of
characters
The difference between a string and an array of characters, lies in the way
they are stored in the memory
Strings are stored in memory such that, they terminate with a special
character, \0
Just like in arrays, strings also have indexes, which can be used to fetch
character. For example, consider the string → aabcc , the element stored at
$0th$ position is a , while the character stored at the second position is
also a , the element stored at 3rd position is b , and so on
Some general terms associated with strings are → Substrings and Subsequences
A substring is a continuous sequence of characters within a string.

For example, given the string "abc"


All the substrings of the string are
"a"
"ab"
"abc"
"b"
"bc"
"c"

A subsequence is a sequence of characters, which can be derived from a given


string, without changing the order of elements in the original string

For example, given the string "abc"


All the subsequences of the string are
"a"
"ab"
"abc"
"ac"
"b"
"bc"
"c"

You might also like