2.1 Search Algorithms Flashcards

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

What is a search algorithm

A
  • A search algorithm is a set of instructions for finding a specific item of data within a data set.
  • Computer systems can store and process billions of pieces of data so it is vital that computers can find the information they need efficiently.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Effective searching

A

An effective search is one which will always either find the solution or determine that the target data is not present.

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

Efficient searching

A

An efficient search will find the solution quickly regardless of its location within the data set.

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

What are the two common search algorithms

A

Linear search
Binary search

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

Linear Search

A
  • Check the first item in the dataset:
    • If it is what we are looking for, return it.
  • Check the second item in the dataset:
    • If it is what we are looking for, return it.
  • Continue for rest of items.
  • If we reach the end of the data set, then the item was not in our data set.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Pros and cons of linear search

A

Easy to implement

Slow on a long list

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

Binary search

A
  • Find the middle of the dataset.
  • If the middle value is greater than the target then:
    • Repeat on the first half of dataset.
  • If the middle value is lesser than the target then:
    • Repeat on the second half of dataset.
  • If the middle value is the target:
    • We found it!
  • Stop repeating once the size of our dataset is zero.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Pros and cons of binary search

A

Faster than linear search on a large data base

Dataset must be sorted before starting

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