Selection sort - Arrays and Linked list Flashcards

1
Q

How is computer memory conceptually organized?

A

Like a giant set of drawers, where each drawer (memory slot) has an address and can hold one element.

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

What are the two basic ways to store multiple items in memory?

A
  • Arrays
  • Linked lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are items stored in an array?

A

Contiguously (right next to each other) in memory.

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

How are items stored in a linked list?

A

Items can be anywhere in memory, with each item storing the address of the next item.

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

What happens when you need to add an item to an array that’s full?

A

You need to request a new, larger chunk of memory and move all existing items there.

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

What is a common workaround for the array expansion problem?

A

“Holding seats” by requesting more memory slots than initially needed.

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

What are the downsides of “holding seats” in arrays?

A
  • Memory may be wasted if extra slots aren’t used
  • You may still need to move if you exceed the extra capacity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why are linked lists better for insertions?

A

You can place the new item anywhere in memory and update the previous item to point to it.

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

What does “random access” mean?

A

The ability to jump directly to any element by its index (like arrays provide).

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

What does “sequential access” mean?

A

Reading elements one by one starting from the first element (as in linked lists).

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

Which data structure is better for reading random elements?

A

Arrays, because you can calculate the exact memory address of any element immediately.

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

Which data structure is better for insertions and deletions in the middle?

A

Linked lists, because you only need to update the pointers of adjacent elements.

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

How does selection sort work?

A

Find the smallest/largest element, add it to a new list, and repeat with the remaining elements.

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

What is the time complexity of selection sort?

A

O(n²) time.

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