Professional Documents
Culture Documents
This Study Resource Was: CS 315 Homework Assignment 1
This Study Resource Was: CS 315 Homework Assignment 1
e r as
co
eH w
CS 315
o.
rs eHomework Assignment 1
ou urc
Arrays in C, Javascript, Python, Perl and PHP
o
aC s
v i y re
ed d
ar stu
sh is
#21602169
CS 315-1
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
C:
1. What types are legal for subscripts?
m
• Dynamic Arrays : Runtime
e r as
co
4. When does allocation take place?
eH w
o.
• Static Arrays : Load Time
rs e
• Dynamic Arrays : Runtime
ou urc
5. Are ragged or rectangular multidimensional arrays allowed, or both?
o
• Both ragged and rectangular multidimensional arrays are allowed. We can use
aC s
pointer array for this purpose or we can define our arrays as multidimensional
v i y re
already.
• In theory, C can take any numbers of subscripts which is about the level of
ar stu
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory or the compiler specification.
sh is
2
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Javascript:
1. What types are legal for subscripts?
• No. There is no range check mechanism in Javascript. The script continues to run
without any error, but the array returns ‘undefined’ as the result for out-of-ranged
subscript.
m
• Since Javascript is an interpreted language, the range binding takes place in runtime.
e r as
co
4. When does allocation take place?
eH w
o.
• Since Javascript is an interpreted language, the allocation takes place in runtime.
rs e
ou urc
5. Are ragged or rectangular multidimensional arrays allowed, or both?
• In theory, Javascript can take any numbers of subscripts which is about the level of
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory.
ed d
ar stu
• Yes. Arrays have slice function which can be used to slice arrays in Javascript.
3
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Python:
1. What types are legal for subscripts?
• There is no array type in python. However, list objects can be used as arrays, and
for the list objects only int type is legal for subscripts in Python. Also, associative
arrays can be also considered as arrays. In Python, there is the dictionary data
structure and it can take immutable data types as key for its subscripts. Therefore, it
can be said that float, string, even tuple can be used for subscript beside int.
• Yes. There is a range check mechanism which takes place in runtime in Python. On
the other hand, Python accepts out-of-bounded operations while slicing, but it
m
returns only the elements inside the bounds.
e r as
co
3. When are subscript ranges bound?
eH w
•
o.
Since Python is an interpreted language, the range binding takes place in runtime.
rs e
ou urc
4. When does allocation take place?
• In theory, Python can take any numbers of subscripts which is about the level of
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory.
sh is
• Yes. There is no array type in python. However, list objects can be used as arrays,
and list objects can be initialized.
• Yes. Python supports slice operations for list objects which can be used as arrays.
4
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Perl:
1. What types are legal for subscripts?
• Only int type is legal for subscripts in Perl. Also, associative arrays can be also
considered as arrays, and Perl allows us to use string type for keys.
• No. There is no range check mechanism in Perl. The script continues to run without
any error, but the array returns nothing as the result for out-of-ranged subscript.
m
• Since Perl is an interpreted language, the range binding takes place in runtime.
e r as
co
4. When does allocation take place?
eH w
o.
• Since Perl is an interpreted language, the range binding takes place in runtime.
rs e
ou urc
5. Are ragged or rectangular multidimensional arrays allowed, or both?
• In theory, Perl can take any numbers of subscripts which is about the level of
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory.
ed d
ar stu
5
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
PHP:
1. What types are legal for subscripts?
• Since all arrays in PHP are maps, all legal types (except Arrays and Objects) are
accepted for subscripts. They all hashed into long type key values which are used in
map to hold the values.
• Yes. There is a range check mechanism in PHP. If the subscript is a key and the key
does not exist, then PHP gives out of bound error. If the subscript is an integer and
the index is out of the range of array, then PHP gives out of range error.
m
3. When are subscript ranges bound?
e r as
co
• Since it is an interpreted language, range binding in PHP takes place in runtime.
eH w
o.
4. When does allocation take place?
rs e
ou urc
• Since it is an interpreted language, allocation in PHP takes place in runtime.
• In theory, PHP can take any numbers of subscripts which is about the level of
ed d
multidimension of the array. On the other hand, there is a limitation about this and
ar stu
6
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Discussion About Language Preference:
I prefer Python for array operations among these five languages. Array operations are mostly
used for mathematical and statistical purposes, and from my view, Python is the most suitable
one. It does not have array structures but it has lists which can be used as arrays, and the list
objects have lots of different operations for the manipulation of the data they store. Also, Python
has NumPy beside List, and it is also another powerful tool for array operations.
m
e r as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th
7
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/