Sorts, Searches and Algorithms Flashcards
1
Q
Which Is More Efficient - Merge Sort OR Bubble Sort?
A
Merge Sort
2
Q
What are the basic steps of Merge Sort?
A
- Divide the unsorted list into ‘n’ sub-lists each containing one element
- Repeatedly merge two sub-lists at a time to produce new sorted sub-lists until there is only one sub-list remaining. This is the sorted list.
3
Q
What are the basic steps of Bubble Sort?
A
- Each item in a list is compared to the next one to it, and if it is greater, they swap places
- At the end of one pass through the list, the largest item is at the end of the list
- This is repeated until the items are sorted
4
Q
What happens in a Linear Search?
A
Each Item in the list is checked in order.
5
Q
What happens in a Binary Search?
A
An ordered list is divided in 2 with each comparison.
6
Q
How do you carry out a Linear Search?
A
- Check the first value
a) If it is the value you are looking for, then you are finished
b) If it is not the value you are looking for, move and check the next value. Repeat until you have checked all the elements and not found the value you are looking for.
7
Q
How do you carry out a Binary Search?
A
- The list must be in order
- Examine the middle item
a) If you report ‘found’, and position
b) If the item is less than the middle item, binary search the lower half
c) If the item is more than the middle item, search upper half
d) If the item is not found, report ‘item not found’
8
Q
What is an Algorithm?
A
A set of instructions for solving a problem or completing a task