Unit 11: Data structures Flashcards

1
Q

What is a data structure in programming?

A

A way of organizing and storing data so it can be accessed and modified efficiently.

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

What two things usually go together in program design?

A

The choice of data structures and the algorithms used to process them.

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

What are parallel arrays?

A

Multiple arrays used to represent a single group of records, where each array stores a different field.

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

Example use of parallel arrays?

A

An address book with names[], addresses[], and phoneNumbers[], where index i across all arrays relates to one person.

System.out.println(name[i] + " " +
address[i] + " " + phone[i]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a partially filled array?

A

A fixed-size array where only some elements are actively used. The rest of the array is unused but available for future data.

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

Why are partially filled arrays useful?

A

They allow flexibility within fixed-size arrays, helping manage memory while tracking only the meaningful (used) data.

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

What variable is typically used alongside a partially filled array?

A

currentSize – the index of the first unused element.

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

What is the boolean inUse[] array used for?

A

It tracks which indices of the main array actually hold valid data (true) and which don’t (false).

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

Advantage of using inUse[] over currentSize?

A

No need to shuffle on deletion; the position is simply marked as not in use.

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

How do you mark all array positions as unused?

A

for (int i = 0; i < size; i++) inUse[i] = false;

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

How do you count the number of used elements?

A
int count = 0;
for (int i = 0; i < size; i++)
    if (inUse[i]) count++;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you mark a value as deleted?

A

inUse[i] = false;

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

How do you insert a new value?

A
for (int i = 0; i < size; i++) {
    if (!inUse[i]) {
        data[i] = value;
        inUse[i] = true;
        break;
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you find a value in a partially filled array?

A
for (int i = 0; i < size; i++)
    if (inUse[i] && data[i] == value) return i;
return -1;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly