Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
c++
![Sorting
This handout explains three quadratic sorting algorithms. Each explanation assumes we are sorting an array of size n in
ascending order from position position [0] through [n-1]. (Technically, we should say "non-decreasing" rather than
"ascending", since we could have duplicates.)
Bubble Sort
As was demonstrated in class, the main idea of bubble sort is as follows.
■ Make n-1 passes through the array, numbered i=n-1, n-2, etc. down to 1
On pass i, we consider the part of the array 0 through i
We walk through that part of the array, looking at each pair of adjacent elements, and swapping them if
they are out of order.
■
▪ We also can keep track of whether any swaps happen during each pass. If we make a pass that has NO
swaps at all, we can stop, because we know the array is already sorted.
Some things we know about bubble sort:
▪ After pass i, we know that the element in position i through the end of the array (n-1) is in proper place in the
array. (This was explained in lecture.)
■ Corrolary 1: After pass 1, we know that elements 1 through n-1 are sorted and in their correct place in the
array.
■
Corrolary 2: After pass 1, we know the entire array is sorted, because it is not possible for element [0] to
be out of place if every other element is in place.
Given this, here are two example "worked problems" for bubble sort.
The part in bold is what YOU would write if given the problem.
initial
60 50 40 30 20
values
i=4 50 40 30 20 60
i=3 40 30 20 50 60
i=2
30 20 40 50 60
i=1 20 30 40 50 60
initial
values
10 40 30
60 50
i=4
10
50 60
50 60
i=3
10 30 40
i=2 DONE: no swaps on previous pass](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fbbff2935-77bb-4550-bfd1-d595e6271f30%2Fd4cdc9cf-6a65-4dd7-8c9d-e492cdbf5f0d%2Fqwb1e78_processed.png&w=3840&q=75)
Transcribed Image Text:Sorting
This handout explains three quadratic sorting algorithms. Each explanation assumes we are sorting an array of size n in
ascending order from position position [0] through [n-1]. (Technically, we should say "non-decreasing" rather than
"ascending", since we could have duplicates.)
Bubble Sort
As was demonstrated in class, the main idea of bubble sort is as follows.
■ Make n-1 passes through the array, numbered i=n-1, n-2, etc. down to 1
On pass i, we consider the part of the array 0 through i
We walk through that part of the array, looking at each pair of adjacent elements, and swapping them if
they are out of order.
■
▪ We also can keep track of whether any swaps happen during each pass. If we make a pass that has NO
swaps at all, we can stop, because we know the array is already sorted.
Some things we know about bubble sort:
▪ After pass i, we know that the element in position i through the end of the array (n-1) is in proper place in the
array. (This was explained in lecture.)
■ Corrolary 1: After pass 1, we know that elements 1 through n-1 are sorted and in their correct place in the
array.
■
Corrolary 2: After pass 1, we know the entire array is sorted, because it is not possible for element [0] to
be out of place if every other element is in place.
Given this, here are two example "worked problems" for bubble sort.
The part in bold is what YOU would write if given the problem.
initial
60 50 40 30 20
values
i=4 50 40 30 20 60
i=3 40 30 20 50 60
i=2
30 20 40 50 60
i=1 20 30 40 50 60
initial
values
10 40 30
60 50
i=4
10
50 60
50 60
i=3
10 30 40
i=2 DONE: no swaps on previous pass
![3
Show the steps of insertion sort following the example of the solved problems on the handout for the algorithm and
the format of your answer.
3.1
3.2
initial values 8 5 3 10 2
i=0
i=1
i=2
i=3
i = 4
initial values 40
i=0
i=1
i=2
i=3
i = 4
42 -3 10 0](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fbbff2935-77bb-4550-bfd1-d595e6271f30%2Fd4cdc9cf-6a65-4dd7-8c9d-e492cdbf5f0d%2F2ejt9a_processed.jpeg&w=3840&q=75)
Transcribed Image Text:3
Show the steps of insertion sort following the example of the solved problems on the handout for the algorithm and
the format of your answer.
3.1
3.2
initial values 8 5 3 10 2
i=0
i=1
i=2
i=3
i = 4
initial values 40
i=0
i=1
i=2
i=3
i = 4
42 -3 10 0
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY