Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This question focuses on Part 4 ( repetition ) , Part 5 ( components ) and Part 6 ( sorting ) . The teacher runs
This question focuses on Part repetition Part components and Part sorting The teacher runs an afterschool computing club and stores the names of children who belong to this club in a list, which at present is unsorted. She is considering ways to sort the list and is interested in a sorting algorithm she has recently heard about and which is new to her. The algorithm is called exchange sort, and she explains it like this. In the first pass through the list you compare the name at position with that at position : if they are out of order then you swap them. Then you compare the name at position with that at position : if they are out of order then you swap them, and so on for the names at positions etc. You continue in this way until the name at position has been compared with the name at all other positions and swapped whenever necessary. When the first pass is complete the name that ends up at position will be the first in alphabetical order. The second pass is similar, except that you begin with the name at position comparing it with the names at positions etc. When pass two is complete the names at and will be the first and second in alphabetical order. In the third pass you compare the name at position with those at positions etc. When pass three is complete the names at and will be the first, second and third in alphabetical order. Continuing in this way we will eventually compare the name in the nexttolast position with that in the last position, swapping them if necessary, and at that point the entire list will be sorted. This might sound a bit like bubble sort at first but if you look at the pairs that are compared in the first pass you can see that the pattern of comparisons is quite different, as illustrated in Figure DescriptionsFigure An OUBuild speech bubble containing the question 'What is times Back to Figure Figure A piece of paper, labelled Original word, is shown, containing the following characters printed in a row. metta. Below the piece of paper is a row of clouds containing text. The first cloud is to the left of the piece of paper and contains the text Nenv word so far: Subsequent clouds are each aligned with a character on the piece of paper above. The cloud below contains the text New word so far: The cloud below e contains the text New word so far: 'mme'. The cloud below t contains the text New word so far: 'mmett'. The cloud below a contains the text New word so far: 'mmetta'. The cloud below contains the text Neww word so far: 'mmettall'. Back to Figure Figure Bubble sort versus exchange sort A representation of bubble sort and exchange sort are shown. At the top of the picture there is a label saying 'Bubble sort' on the lefthand side. On the righthand side there is a label stating Pass and underneath the label in a vertical line are the numbers and to represent separate passes of the algorithm. Next to each number are dots spread evenly out horizontally across the page to represent each element to be compared. Between each dot is a curved line to show the comparison between each pair of elements. There are dashed lines underneath the horizontal line. At the bottom of the picture there is a label saying 'Exchange sort' on the lefthand side. On the righthand side there is a label stating Pass and underneath the label in a vertical line are the numbers and to represent separate passes of thealgorithm. Next to each number are dots spread evenly out horizontally across the page to represent each element to be compared. On the horizontal line marked there are lines all starting from the first element; each line is linked to a different element, so there is a line between the first element and the second, then a line between the first element and the third, a line between the first element and the fourth, a line between the first element and the fifth and a line between the first element and the sixth. On the horizontal line marked there are lines all starting from the second element; each line is linked to a different element. There is no line joining the first element. There is a line between the second element and the third, a line between the second element and the fourth, a line between the second element and the fifth and a line between the second element and the sixth. On the horizontal line marked there are lines all starting from the third element; each line is linked to a different element. There are no lines joining the first or second elements. There is a line between the third element and the fourth, a line between the third element and the fifth and a line between the third element and the sixth. There are dashed lines underneath the horizontal line.
This question focuses on Part repetition Part components and Part sorting
The teacher runs an afterschool computing club and stores the names of children who belong to this club in a list, which at
present is unsorted. She is considering ways to sort the list and is interested in a sorting algorithm she has recently heard about
and which is new to her. The algorithm is called exchange sort, and she explains it like this.
In the first pass through the list you compare the name at position with that at position : if they are out of order then you
swap them. Then you compare the name at position with that at position : if they are out of order then you swap them, and
so on for the names at positions etc. You continue in this way until the name at position has been compared with the
name at all other positions and swapped whenever necessary. When the first pass is complete the name that ends up at
position will be the first in alphabetical order.
The second pass is similar, except that you begin with the name at position comparing it with the names at positions etc.
When pass two is complete the names at and will be the first and second in alphabetical order.
In the third pass you compare the name at position with those at positions etc. When pass three is complete the names
at and will be the first, second and third in alphabetical order.
Continuing in this way we will eventually compare the name in the nexttolast position with that in the last position, swapping
them if necessary, and at that point the entire list will be sorted.
This might sound a bit like bubble sort at first but if you look at the pairs that are compared in the first pass you can see that the
pattern of comparisons is quite different, as illustrated in Figure
DescriptionsFigure
An OUBuild speech bubble containing the question 'What is times
Back to Figure
Figure
A piece of paper, labelled Original word, is shown, containing the following characters printed in a row. metta. Below the piece of paper
is a row of clouds containing text. The first cloud is to the left of the piece of paper and contains the text Nenv word so far: Subsequent
clouds are each aligned with a character on the piece of paper above. The cloud below contains the text New word so far: The
cloud below e contains the text New word so far: 'mme'. The cloud below t contains the text New word so far: 'mmett'. The cloud below a
contains the text New word so far: 'mmetta'. The cloud below contains the text Neww word so far: 'mmettall'.
Back to Figure
Figure Bubble sort versus exchange sort
A representation of bubble sort and exchange sort are shown. At the top of the picture there is a label saying 'Bubble sort' on
the lefthand side. On the righthand side there is a label stating Pass and underneath the label in a vertical line are the
numbers and to represent separate passes of the algorithm. Next to each number are dots spread evenly out
horizontally across the page to represent each element to be compared. Between each dot is a curved line to show the
comparison between each pair of elements. There are dashed lines underneath the horizontal line.
At the bottom of the picture there is a label saying 'Exchange sort' on the lefthand side. On the righthand side there is a label
stating Pass and underneath the label in a vertical line are the numbers and to represent separate passes of thealgorithm. Next to each number are dots spread evenly out horizontally across the page to represent each element to be
compared. On the horizontal line marked there are lines all starting from the first element; each line is linked to a different
element, so there is a line between the first element and the second, then a line between the first element and the third, a line
between the first element and the fourth, a line between the first element and the fifth and a line between the first element and
the sixth.
On the horizontal line marked there are lines all starting from the second element; each line is linked to a different element.
There is no line joining the first element. There is a line between the second element and the third, a line between the second
element and the fourth, a line between the second element and the fifth and a line between the second element and the sixth.
On the horizontal line marked there are lines all starting from the third element; each line is linked to a different element.
There are no lines joining the first or second elements. There is a line between the third element and the fourth, a line between
the third element and the fifth and a line between the third element and the sixth. There are dashed lines underneath the
horizontal line.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started