Algorithms Flashcards

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

What is an algorithm?

A

A series of steps to solve a given problem

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

What is algorithmic thinking?

A

A way of solving problems by producing algorithms

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

Writing down an algorithm

A

Can be written as a set of numbered steps to follow

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

What is often used to represent algorithms?

A

Pseudocode or flow diagrams

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

How do you interpret an algorithm?

A

Identify what the algorithm does

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

What is a search algorithm?

A

A set of instructions for finding a specific item of data within a data set

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

What is an effective search?

A

A search that will 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
8
Q

What is an efficient search?

A

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
9
Q

What are examples of search algorithms?

A

1) linear search 2) Binary search

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

What is linear search?

A

A simple searching algorithm

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

What is the concept of linear search?

A

If you were looking for a specific piece of paper in a stack of papers, then one way to find it would be to work from the top of the stack to the bottom, checking each paper on the way.

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

Linear search -

A

1) Check the first item in the dataset:
- if it is what we are looking for, return it
2) Check the second item in the dataset:
- if it is what we are looking for, return it
3) Continue for the rest of the items

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

What does it mean when you reach the end of the dataset in linear search?

A

The item was not in the data set

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

Linear search pseudocode example =

A
for item in dataset
 if item = target then
     return True
   endif
endfor
return False
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the pros of linear search?

A

Very easy to implement

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

What are the cons of linear search?

A

Slow on a longer list

17
Q

What is binary search?

A

A divide and conquer algorithm

18
Q

What is the concept of binary search?

A

If you try to find a certain page in a book, it’s unlikely that you check every page on the way
- you are more likely to split the book in 2 then see if the page you need is before or after the split & repeat

19
Q

Binary search -

A

1) Find the middle of the dataset
- if the middle value is greater than the target then:
- - repeat on first half of dataset
2) If the middle value is lesser than the target then:
- repeat on second half of dataset
3) If the middle value is the target:
- We found it
4) Stop repeating once the size of our dataset is zero

20
Q

Binary search pseudocode example =

A
dataset = [...] 
min = 0; max = len(dataset)
while (min target then
max = midpt - 1
else if dataset+ [midpt] < target then
min = midpt + 1
endif
endwhile
return False
21
Q

What are the pros of binary search?

A

Faster than linear search on a large dataset

22
Q

What are the cons of binary search?

A

Dataset must be sorted before starting

23
Q

What are the 3 basic constructs when needed to design an algorithm?

A

Iteration, Selection & Sequence