2.3 Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

When is a linear search used?

A

When items are not in an ordered sequence.

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

What does a linear search do?

A

Searches through a list one item after another until the required item is found or the end of the list is reached.

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

What is a benefit of a linear search?

A

It is very simple

Can search unordered lists

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

What is a con of a linear search?

A

It is inefficient, especially for long lists.

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

What does a binary search do?

A

Divides the area of where the item could be by two.

Finds the middle item of the list and removes one half depending if the middle item is bigger or smaller than the required item.

Continues to half list until item is found as middle number or one item is left.

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

When is a binary search used?

A

When a list is ordered.

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

Why is it important to sort data in processing?

A

Because it is more efficient to search an ordered list than an unordered one.

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

What is a benefit of a binary search?

A

It is more efficient than a linear search

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

What is a con of a binary search?

A

It can only be used on a sorted list.

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

What do both linear and binary searches use to know which item they are looking at in a list?

A

An index

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

What is bubble sorting?

A

Going through a list and comparing the first two values, and ordering them. Then moving onto the next pair and ordering them. Repeat until the list is sorted.

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

Which value will be sorted after the first pass of a bubble sort?

A

The last value of a list.

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

What is insertion sorting?

A

The first item from the unsorted list is not moved. The second item is then removed and the first item is either moved or not depending on whether it is bigger or smaller than the item that was removed. The removed item is then inserted into the empty space. This continues with the sorted items moving to create the correct space for the unsorted item to be inserted into.

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

What is a benefit of bubble sorting?

A

It is very simple and easy to understand.

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

What is a con of bubble sorting?

A

It is very inefficient as it requires lots of passes.

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

What is a benefit of insertion sorting?

A

It is more efficient than bubble sorting.

17
Q

What is a con of insertion sorting?

A

It is more complicated than bubble sorting.

18
Q

When would bubble sorting be used?

A

To introduce the concept of sorting to students.

19
Q

When would insertion sorting be used?

A

Short lists / almost sorted long lists.

20
Q

What would you use a binary search for?

A

Searching database indexes / binary data items.