Sort Algorithm KO

0.0(0)
studied byStudied by 3 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/28

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

29 Terms

1
New cards
Merge sort
________ is a recursive function, that calls itself.
2
New cards
Pairs of sublists
________ are combined into an ordered list containing all items in the two sublists.
3
New cards
Merge Sort Merge sort
________ is a type of divide and conquer algorithm.
4
New cards
Example Sort the following sequence in ascending order using bubble sort
5,3,4,1,2
5
New cards
Compare 5 and 3
swap
6
New cards
Compare 5 and 4
swap
7
New cards
Compare 5 and 1
swap
8
New cards
Compare 5 and 2
swap; end of pass 1
9
New cards
Compare 3 and 4
no swap
10
New cards
Compare 4 and 1
swap
11
New cards
Compare 4 and 2
swap
12
New cards
Compare 4 and 5
no swap; end of pass 2
13
New cards
Compare 3 and 1
swap
14
New cards
Compare 3 and 2
swap
15
New cards
Compare 3 and 4
no swap
16
New cards
Compare 4 and 5
no swap; end of pass 3
17
New cards
There are two steps
divide and combine Merge sort works by dividing the unsorted list sublists
18
New cards
Step 1
Divide
19
New cards
Keep dividing until there is only 1 item in each list Step2
Combine
20
New cards
What are the two kinds of sorting algorithms?
Merge sort and Bubble sort
21
New cards
What is the purpose of a sorting algorithm?
The purpose of sorting algorithms is to order an unordered list.
Item can be ordered alphabetically or by number.
22
New cards
Summarise the bubble sort algorithm
• Bubble sort steps through a list and compares pairs of adjacent
numbers.The numbers are swapped if they are in the wrong
order. For an ascending list if the left number is bigger than the
right number the items are swapped otherwise the numbers are
not swapped.
• The algorithm repeatedly passes through the list until no more swaps are needed.
23
New cards
Summarise the merge sort algorithm
• Merge sort is a type of divide and conquer algorithm.
• There are two steps: divide and combine
• Merge sort works by dividing the unsorted list sublists. It
does this until there is 1 item in each list.
• Pairs of sublists are combined into an ordered list. The algorithm continues until there is only 1 ordered list remaining.
24
New cards
What is the advantage of a bubble sort? (1)
It is a very simple and robust algorithm
25
New cards
What is the disadvantage of a bubble sort?
Can be slow particularly for long lists. As the number of items increases the time taken for the algorithm to run increases.
26
New cards
What is the advantage of a merge sort?
Much faster than bubble sort especially when the number of elements are large.
27
New cards
What is the disadvantage of a merge sort?
It is a bit more complex to understand
Step 1: Divide
Step 2: Combine
28
New cards
merge sort
knowt flashcard image
29
New cards
bubble sort
knowt flashcard image