Sorting algorithms Flashcards

(9 cards)

1
Q

Explain a characteristic of merge sort

A

Efficient so works well for large data sets

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

Detail how merge sort works.

A

The data set is repeatedly split in half until each item is in its own list. Items in adjacent lists are compared and placed into a new list in order. Compare adjacent lists again, from the bottom up, creating new ordered lists, until there is only 1 list left.

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

How do you identify merge sort code?

A

It’s bloody massive and there is no for loop

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

Describe the characteristics of an insertion sort.

A

Not the most efficient; useful for small data sets and inserting items into an already sorted list.

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

Detail how an insertion sort works.

A

Insert the first item into a new list. Insert the next item; compare it to the first item, and swap if needed. Each new item is compared to the item below it and swapped if needed until no swaps are needed.

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

How do you identify insertion sort code?

A

While loop inside the for loop

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

Describe the characteristics of bubble sort

A

The least efficient method, but very easy to implement. Good for small data sets.

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

Detail the steps of bubble sort.

A

Compare the first, and swap if needed. Compare items 2 and 3 and swap if needed, and 3 and 4, and so on. When you get to the end, go back to start and go through the process again. Once you go all the way through the list with no swaps, the sort is done.

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

How do you identify bubble sort code?

A

Has a ‘swapped’ variable. For loop is within the while loop.

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