c3 Flashcards

(17 cards)

1
Q

Why is the linear search also called “sequential search”?

A

Because it checks each element one by one in order.

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

If a linear search function is searching for a value that is stored in the last element of a 10,000-element array, how many elements will the search code have to read?

A

10,000 elements.

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

In an average case involving an array of N elements, how many times will a linear search function have to read the array to locate a specific value?

A

N/2 times.

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

A binary search function is searching for a value that is stored in the middle element of an array. How many times will the function read an element before finding the value?

A

Once.

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

What is the maximum number of comparisons that a binary search function will make when searching for a value in a 1,000-element array?

A

About 10 comparisons.

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

Why is the bubble sort inefficient for large arrays?

A

Because it repeatedly passes through the array, leading to many operations.

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

Why is the selection sort more efficient than the bubble sort on large arrays?

A

Because it minimizes swaps by selecting the correct element and moving it directly.

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

The __________ search algorithm steps sequentially through an array, comparing each item with the search value.

A

linear

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

The __________ search algorithm repeatedly divides the portion of an array being searched in half.

A

binary

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

The __________ search algorithm is adequate for small arrays but not large arrays.

A

linear

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

The __________ search algorithm requires that the array’s contents be sorted.

A

binary

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

If an array is sorted in __________ order, the values are stored from lowest to highest.

A

ascending

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

If an array is sorted in __________ order, the values are stored from highest to lowest.

A

descending

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

If data are sorted in ascending order, it means they are ordered from lowest value to highest value.

A

True

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

If data are sorted in descending order, it means they are ordered from lowest value to highest value.

A

False

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

The average number of comparisons performed by the linear search on an array of N elements is N/2 (assuming the search values are consistently found).

17
Q

The maximum number of comparisons performed by the linear search on an array of N elements is N/2 (assuming the search values are consistently found).