Computational Thinking 2-Sorting algorithims Flashcards

(7 cards)

1
Q

Uses

Sorting algorithim

A

Used to rearrange a given array or list elements according to a comparison operator on the elements.

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

Uses

Comparision operator

A

Used to decide the new order of element in the respective data structure.

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

Define

Merge sort

A

A merge sort is a complex sorting algorithm, but it is also a highly efficient one.

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

How does it work

Merge sort

A
  1. A merge sort uses a technique called divide and conquer.
  2. The list is repeatedly divided into two until all the elements are separated individually.
  3. Now each pairs of elements are compared, placed into order and combined.
  4. As each pair of lists is merged, they are merged in order.
  5. The process is then repeated until the list is recompiled as a whole.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does it work

Bubble sort

A
  1. Start at the beginning of the list.
  2. Compare the first value in the list with the next one up. If the first value is bigger, swap the positions of the two values.
  3. Move to the second value in the list. Again, compare this value with the next and swap if the value is bigger.
  4. Keep going until the there are no more items to compare.
  5. Go back to the start of the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Advantages/Disadvantages

Insertion sort

A

An insertion sort is less complex and efficient than a merge sort, but more efficient than a bubble sort.

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

How does it work

Insertion sort

A

An insertion sort compares values in turn, starting with the second value in the list.
If this value is greater than the value to the left of it, no changes are made.
Otherwise this value is repeatedly moved left until it meets a value that is less than it.
The sort process then starts again with the next value.
This continues until the end of the list is reached.

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