Searching and sorting algorithms Flashcards

1
Q

Methods for sorting algorithms

A
  • Bubble sort
  • Merge sort
  • Insertion sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Methods for searching algorithms

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

How does binary search work

A

Splits the data set in half and compares if the number is greater or smaller than the number they are finding, gets rid of half the list and splits it again comparing if it is greater than or smaller than until it has found the correct number

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

Advantages and disadvantages of a binary search

A
  • Much more efficient than a linear search
  • But the list must be ordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does a linear search work

A

Starts at the beginning of the data set and compares each number to the one it is searching for

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

Advantages and disadvantages of a linear seach

A
  • very simple
  • Can be very inefficient if the number is at the end of a long list
  • The data set does not have to be ordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does a bubble sort work

A

Starts at the beginning of the list and compares the number with the one next to it and makes a switch if it is larger.
it then moves to the second value and compares
It continues this until there is no more items to compare
After the first pass a second pass is completed to ensure it is all sorted

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

Advantages and disadvantages of a bubble sort

A
  • It is popular and easy to implement
  • Does not deal well with large lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does a merge sort work

A
  • It uses a method called divide and conquer
  • The list is repeatedly divided into two until all the items are separate
  • Pairs of elements are then compared, this process is repeated until the list is recompiled
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Advantages and disadvantages of a merge sort

A
  • reliable efficiency
  • Excellent choice for large datasets
  • Not the most space efficient algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does an insertion sort work

A
  • Compares values in turn
  • Starts on the second value and compares if it is bigger than the first value
  • If it is it moves onto the third value and compares if that is bigger than the second value
  • If one value is greater it will then be compared with all the previous values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Advantages and disadvantages of an insertion sort

A
  • Less complex and efficient as a merge sort
  • More efficient than a bubble sort
  • Works best with smaller data sets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly