2.1 Algorithms - Linear Search Flashcards

1
Q

What is a searching algorithm?

A

A searching algorithm is an algorithm that is used to search data in a list.

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

How does a linear search algorithm work?

A

The search begins with the first item and checks whether a match is found, then it moves to the second item, and so on. This search continues until a match is found or the end of the list is reached with no match found.

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

What is the pseudocode for a while loop in linear search algorithms?

A

while (position<len and list[position]!= item)
position = position + 1
endwhile

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

What is the pseudocode for if…else… statement in a linear search algorithm?

A

if position> len then
print (“item not found”)
else
print (“item found at position ” position)
endif

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

Assume that there is a list of 7 elements. The search element is at position 4. How many times is the while loop executed?

A

5 times (value of position starts from 0)

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

Assume that there is a list of 7 elements. The search element is at position 4. How many times is the if…else… statement executed?

A

Only once

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

Assume that there is a list of 10 elements. The search element is not in list. How many times is the while loop executed?

A

10 times

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

Assume that there is a list of 10 elements. The search element is not in list. How many times is the if…else… statement executed?

A

Only once

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