Arrays Flashcards

1
Q

Definition

A

it’s a contiguous area of memory consisting of equal sized elements indexed by contiguous integers

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

what is special about an array?

A

it has constant time access and write O(1)

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

how to calculate the position of an element in an array

A

array_add + element_size * (i - first_element)

first_element can be 0 or 1

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

how are multi-dimensional arrays are laid out in memory?

A

Row major or column major

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

Times for common operations? Beginning , middle , end to add or remove element

A
Add    Remove
Beginning     O(N)   O(N)
because we need to shift all the elements
Middle           O(N)   O(N)
because again we need to shift elements
End                O(1)      O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Characteristics Of simple array?

A

it’s a collection of same type elements
Fixed size
Zero indexed
Same Data type

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

why choose a simple array?

A

because the more constraints u have on your data structure the smaller it will get meaning it will be faster

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

What are arrays in java?

A

it’s an object consisting of a numbered list of variable each one can be a primitive type or a reference to an object

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

what is a multidimensional array?

A

it’s an array of arrays

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

what is a dynamic array?

A

instead of storing the size of the array we just keep track of the pointer pointing to the array and when we need to resize the array we just make it point to another location of memory but we must simulate it like a real array meaning the normal operations like get and set and remove to be of constant time

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

what are the common implementations of dynamic array in c++ , java , python

A

vector , arraylist , list and python doesn’t have static arrays

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

what r the runtimes of dynamic arrays like get , set , pushback , remove , size

A

O(1) , O(1) , O(N) , O(N) , O(1)

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

what is a jagged array?

A

it’s like a multidimensional array but each row has a different number of data and it’s uses like different days of each month in two dimensional array

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

what are the five requirements in any data structure?

A

access , insert , delete , find , sort

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

do programming languages always use the same sorting algorithm for the array?

A

No, they look at the size of the array like .NET uses insertion , heap , quick depending on the size of the array

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

what are the general types of sorting arrays?

A

u can do an in place sorting or copy the entire array to another one

17
Q

can u sort a custom array of objects using the language built in functionality?

A

No, u must provide an implementation of your own sorting algorithm

18
Q

how to search in an array?

A

Linear which is O(N) and sometimes when u search for something u move the variable found to the beginning which will make the algorithm a little bit better and most built in searching uses this and there is binary search which is O(LOG N)

19
Q

how to do a linear search?

A

u go over every item in the array checking for the value

20
Q

how to do binary search?

A

u can’t do a binary search on an unordered data set …. u go to the middle of the array if the number is larger u move to the right half and discard the left until u find an element or u don’t