Arrays Flashcards

1
Q

Introduction to array data structure.

A

An array is a linear data structure consisting of a collection of elements, each
identified by an index or key.
Elements are stored sequentially in memory, with each element occupying a
contiguous memory location.
The index provides a means to access individual elements within the array,
starting from index 0 in most programming languages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 2 uses of array in programming ?

A

Storing and Accessing a Sequence of Data:
Arrays provide a convenient way to store and access a sequence of data elements of the
same type.
Elements within an array are accessed using their index, allowing for efficient retrieval and
manipulation.
Using Array in Application/Coding:
Lists and Collections:
Arrays are commonly used to represent lists or collections of items, such as a list of names,
numbers, or objects.
Example: Storing a list of student grades, employee salaries, or inventory items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are arrays stored linearly in memory?

A

Arrays are stored as contiguous blocks of memory, with each element occupying a fixed-size
memory location.
Elements are arranged sequentially in memory, with the first element starting at a specific
memory address, and subsequent elements following in consecutive memory addresses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Efficiency and advantage of an array

A

Index-Based Access Mechanism: (the way array is store)
Each element in the array is uniquely identified by an index, starting from 0 for the first element.
Fast access for read and write operations by index1.
Simplicity and ease of use in programming2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Inefficiency and disadvantage of an array

A

Fixed Size and Contiguous Memory Allocation (the way array is store)
Arrays have a fixed size, meaning they allocate a predetermined amount of memory when
created.
Elements are stored in contiguous memory locations, ensuring efficient access but limiting
flexibility in size

Then how? I still want to insert a new fruit to my array
Resizing:
Resizing an array involves allocating a new array with a larger size, copying existing elements into the
new array, and deallocating the old array.
1.
Resizing operations can be inefficient, especially if done frequently, as it involves memory allocation and
data copying
2.
Deletion:`
Deleting an element from an array may also require shifting subsequent elements to fill the gap left by
the deleted element.
Similar to insertion, deleting elements from the beginning of the array may result in shifting all
subsequent elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly