Data Structures - Arrays, Lists, Python Lists Flashcards
What is an array?
An array is considered a static data structure that can store a fixed number of elements that are stored in coninunuous memory locations and of a specific data type.
What is a one dimensional array?
It is the most fundamental form of an array where its elements are stored linearly and the individual elements can be accessed by referring to the indices of an array.
How do you declare a 1-D array of size 5 in pseudocode?
DECLARE arrayName: ARRAY[1:5] of INTEGER
What is [1, 2] + [3, 4]?
[1, 2, 3, 4]
grades = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’]
what is grades[0] ?
A
grades = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’]
what is grades[2:4] ?
[‘C’, ‘D’]
What is the application of an array?
It stores a fixed number of elements that are stored in continuous memory locations.
The number of elements and type of data it can store are determined at declaration, and cannot be changed thereafter.
What are the pros of arrays?
- In an array, accessing an element is very easy by using the index number
- Efficient Memory Usage
- Flexibility in Data Types
What are the cons of arrays?
- Wastage of Memory
- Difficulty in Inserting and Deleting Elements
- Inefficient for Search
When using pseudocode involving arrays, how do you add items to the list?
ar[i] ← <item></item>
How to initialise elements to 1-D arrays?
DECLARE ar: ARRAY[1:10] of INTEGER
FOR i = 1 to 10
ar[i] ← -10
How to declare a 2-D array?
e.g.
DECLARE alphabets: ARRAY[1:5][1:8] OF STRINGS
What is a two dimensional array?
An array is considered a static data structure that can store a fixed number of elements that are stored in coninunuous memory locations and of a specific data type.
A two dimensional array can hold more than one set of data. It can be thought of as a table with columns and rows.