Week 2 - Arrays and Linked Lists Flashcards

1
Q

What is computer memory?

A

Computer memory is a long sequence of bytes and is byte-addressable. It can be imagined as a single drawer that holds a single item.

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

What is an Array?

A

An array is a data structure that stores elements in a continuous block of memory, allowing efficient access to each element.

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

How is a new item inserted into an array?

A

Inserting a new item into an array often requires shifting elements. If there isn’t enough space, the entire array may need to be relocated in memory first.

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

What’s a solution to the issue of arrays not fitting in memory

A

One solution is to allocate a larger array with dummy values in the extra slots, but this can waste space. If the extra space is filled, the problem persists.

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

What are linked lists?

A

Linked lists are a data structure where each element stores the address of the next, forming a chain. This makes inserting a new element easier than in an array, but it has a time complexity of O(n) to find a specific element in the list.

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

What module in python allows you to use linked lists?

A

structlinks

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

What is the Big-O time complexity of reading and inserting in an array and linked list?

A

Array
Reading –> O(1) Constant time
Inserting (instant access) –> O(n)
Deleting (instant access) –> O(n)
Insert/ Delete at index –> O(n)

Linked List
Reading –> O(n)
Inserting (instant access) –> O(1)
Deleting (instant access) –> O(1)
Insert/ Delete at index –> O(n)

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

What is a constant time O(1) algorithm?

A

A constant time algorithm performs a fixed number of steps or operations, regardless of the input size.

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

What is the difference between access in arrays and linked lists?

A

Arrays allow for random access, unlike linked lists which have sequential access.

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

What is selection sort and how does it work?

A

Selection sort is a sorting algorithm that repeatedly finds the smallest/ largest element from the unsorted list and places it in the sorted portion. It’s like picking the top songs one by one until all are sorted. It has a time complexity of O(n^2) (Quadratic time)

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