2.3.1 Searching algorithms Flashcards

1
Q

What are the two searching algorithms?

A
  • Binary search
  • Linear search
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain binary search

A
  • DIvide and conquer
  • List must be sorted
  • Looks a middle element
  • Looks if desired element is larger or greater
  • Undesired side is discarded
  • Repeat until elemnt is found
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the time and space complexity for binary search

A
  • Time complexity: O(log n)
  • Space complexity: O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain linear search

A
  • Look at first item
  • Is it desired element
  • If not look at next item
  • Repeat until desired element found
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the time and space complexity of linear search?

A
  • Time complexity: O(n)
  • Space complexity: O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly