2.3.1 Searching Algorithms Flashcards

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

Which search algorithm requires data to be sorted before perfoming the algorithm?

A

Binary Search

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

Perform linear search for 9 :
[ 1, 2, 3, 5, 7, 9, 11, 12 ]

A

Check till find 9 and then terminates.

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

What is the time complexity of Binary Search?

A

O (log n)

Very efficient for more items

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

Perform Binary search for 6 :
[ 1, 3, 6, 7, 9, 12, 13 ]

A
  • Goes to midpoint, 7
  • 6 < 7 Therefore goes to the left of 7
  • Array is now [ 1, 3, 6 ]
  • Goes to midpoint, 3
  • 6 > 3 Therefore goes to the right of 3
  • Array is now [ 6 ]
  • 6 = 6 Therefore 6 is found and Algorithm terminates
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which search algorithm has a time complexity of O(n)?

A

Linear Search

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

Which sorting algorithm is the most time efficient ; Bubble or Merge

A

Merge Sort

Merge is O (n log n) Bubble has a best case O(1) and a worst of O(n^2)

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

Which sorting algorithm uses divide and conquer?

A

Merge Sort

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

Time Complexity of Bubble Sort?

A

O(1) - Best case
O(n^2) - Worst case

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

Time complexity of Merge Sort?

A

O ( n log n)

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

Sort into ascending using bubble sort :
4 3 5 7 6

A
  1. [ 4 3 5 7 6 ]
  2. [(3 4) 5 7 6]
  3. [3 4 5 (6 7)]
  4. [ 3 4 5 6 7 ]

brackets show the switches remember that it will go through fully after

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

Sort in alphabetical order using merge sort:
Tom Sue Jack Bill Ada

A
  • Separate into 3 and 2
  • Tom Sue Jack → Jack Sue Tom
  • Bill Ada → Ada Bill
  • Combine to get Ada Bill Jack Sue Tom
How well did you know this?
1
Not at all
2
3
4
5
Perfectly