Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

ARRAY Msc Thai Thuy Han Uyen

ARRAY FUNCTIONS
a = [2, 19, 13, 5, 17]
No. Function Explantion Example
1 len a Returns the length of array. len a
Returns integer value.
A2 a(index) Returns the value of specified a(1)
A
Aa
element at index position, index from a(4)
A 1
A
3 a(start_index, Returns a subarray a(2,…,2)
A …,end_index) a(1,…,len a)
A
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa a(2,…,4)
2
ARRAY FUNCTIONS
a = [2, 19, 13, 5, 17]
No. Function Explantion Example
1 len a Returns the length of array. len a
Returns integer value.
2 a(index) Returns the value of specified a(1)
element at index position, index from a(4)
A
1
A3 a(start_index, Returns a subarray a(2,…,2)
Aa
A …,end_index) a(1,…,len a)
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa a(2,…,4)
3
ARRAY FUNCTIONS
a = [2, 19, 13, 5, 17]
No. Function Explantion Example
1 len a Returns the length of array. len a
Returns integer value.
2 a(index) Returns the value of specified a(1)
element at index position, index from a(4)
1
3 a(start_index, Returns a subarray a(2,…,2)
…,end_index) a(1,…,len a)
a(2,…,4)
4
ARRAY FUNCTIONS
a = [2, 19, 13, 5, 17] b = [4] c = [7, 9]
No. Function Explantion Example
4 a(index)† Update new element at index position a(3) † 11
A new_item
A
5
Aa
hd a Returns a first element of array hd a
A6 tl a Returns a/some last elements of array tl a
A
tl b
A tl c
A
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

5
ARRAY FUNCTIONS
a = [2, 19, 13, 5, 17] b = [4] c = [7, 9]
No. Function Explantion Example
4 a(index)† Update new element at index position a(3) † 11
new_item
A
5 hd a Returns a first element of array hd a
6
Aaa tl a Returns a/some last elements of array tl a
A
tl b
A tl c
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

6
ARRAY FUNCTIONS
a = [2, 19, 13, 5, 17] b = [4] c = [7, 9]
No. Function Explantion Example
4 a(index)† Update new element at index position a(3) † 11
new_item
5 hd a Returns a first element of array hd a
6 tl a Returns a/some last elements of array tl a
tl b
tl c

7
ARRAY FUNCTIONS
a[12, 4, 6, 12, 4, 6, 38, 12]
No. Function Explantion Example
7 cons(new_element,a Inserts an element into the first index cons(6,a)
) of array
A8 inds a Returns the indices of elements inds a
AA
9 elems a Returns a set of elements elems a
A
A
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
8
ARRAY FUNCTIONS
a[12, 4, 6, 12, 4, 6, 38, 12]
No. Function Explantion Example
7 cons(new_element,a Inserts an element into the first index cons(6,a)
) of array
8 inds a Returns the indices of elements inds a
A9 elems a Returns a set of elements elems a
AAA
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

9
ARRAY FUNCTIONS
a[12, 4, 6, 12, 4, 6, 38, 12]
No. Function Explantion Example
7 cons(new_element,a Inserts an element into the first index cons(6,a)
) of array
8 inds a Returns the indices of elements inds a
9 elems a Returns a set of elements elems a

10
EXAMPLE 1 – EXPLICIT –
RECURSIVE METHOD
Find the sum of all elements of the array of real numbers
EXAMPLE 2 – EXPLICIT –
RECURSIVE METHOD
Find the sum of all positive elements of the array of real
numbers
EXAMPLE 3 – EXPLICIT –
RECURSIVE METHOD
Find the maximum element of the
array of integer numbers
EXAMPLE 3 – IMPLICIT – NOT A
RECURSIVE METHOD
Find the maximum element in the array of integer numbers
ASSIGNMENT
Do assignments using recursion.
Specify function to:
1. check whether a given array has any negative element
2. find the sum of all prime elements of integer array
3. check whether a given natural number x occurs in the array
a of natural numbers
4. find the maximum even element in an array
15
ASSIGNMENT
Do assignments using recursion.
Specify function to:
5. return the first index of x in the array a of real numbers or
return 0 if not finding x in the array a
6. find the sum of even index elements in an array
7. check whether there are duplicate elements in an array
8. find the greast common divisor of all elements in a positive
integer array
16

You might also like