1i - Second Smallest   Take an unknown number, larger than two, of positive integers as input. Assume that the first number is always smaller than the second, all numbers are unique and the input consists of at least three integers. Print the second smallest integer. Example: Please enter some numbers: 10 12 2 5 15 The second smallest number is: 5 Put your program in second_smallest.py. Use line.split(" ") to split the numbers in the input.   1j - Bubblesort   Bubble sort is a sorting algorithm: when given a list, for example [4,2,6,8], it will sort the list to become sorted, [2,4,6,8]. Bubble sort works by walking through the list, comparing adjacent elements, and swapping them if they are in the wrong order. The process of walking through the list is repeated until we have traversed the entire list and no elements were swapped (this means that all adjacent elements are in the right order, and hence the list is sorted). Example run, let's see how this works on the numbers "5 1 4 2 8": First pass ( 5 1 4 2 8 ) → ( 1 5 4 2 8 ) Here, the algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 4 2 8 ) → ( 1 4 5 2 8 ) Swap since 5 > 4 ( 1 4 5 2 8 ) → ( 1 4 2 5 8 ) Swap since 5 > 2 ( 1 4 2 5 8 ) → ( 1 4 2 5 8 ) Now, since these elements are already in order (8 > 5), the algorithm does not swap them. Second pass ( 1 4 2 5 8 ) → ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) → ( 1 2 4 5 8 ), Swap since 4 > 2 ( 1 2 4 5 8 ) → ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) → ( 1 2 4 5 8 ) Third pass Now, the array is already sorted, but the algorithm does not know if it is completed. The algorithm needs one additional whole pass without any swap to know it is sorted. Implement the above algorithm.  Example: Please enter some numbers: 123 45 78 6 5 48 38 98 [5, 6, 38, 45, 48, 78, 98, 123]

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  • Please do this in Python Programming and provide screenshot
  • The output should be exact same like in the examples.
  • If the output in the example is in 2 decimals, then it should be like that. 

 

1i - Second Smallest

 

Take an unknown number, larger than two, of positive integers as input. Assume that the first
number is always smaller than the second, all numbers are unique and the
input consists of at least three integers. Print the second smallest integer.

Example:

Please enter some numbers: 10 12 2 5 15
The second smallest number is: 5

Put your program in second_smallest.py. Use line.split(" ") to split the numbers in the input.

 

1j - Bubblesort

 

Bubble sort is a sorting algorithm: when given a list, for example [4,2,6,8], it will sort the list to become sorted, [2,4,6,8]. Bubble sort works by walking through the list, comparing adjacent elements, and swapping them if they are in the wrong order. The process of walking through the list is repeated until we have traversed the entire list and no elements were swapped (this means that all adjacent elements are in the right order, and hence the list is sorted).

Example run, let's see how this works on the numbers "5 1 4 2 8":

First pass

5 1 4 2 8 ) → ( 1 5 4 2 8 ) Here, the algorithm compares the first two elements, and swaps since 5 > 1.

( 1 5 4 2 8 ) → ( 1 4 5 2 8 ) Swap since 5 > 4

( 1 4 5 2 8 ) → ( 1 4 2 5 8 ) Swap since 5 > 2

( 1 4 2 5 8 ) → ( 1 4 2 5 8 ) Now, since these elements are already in order (8 > 5), the algorithm does not swap them.

Second pass

1 4 2 5 8 ) → ( 1 4 2 5 8 )

( 1 4 2 5 8 ) → ( 1 2 4 5 8 ), Swap since 4 > 2

( 1 2 4 5 8 ) → ( 1 2 4 5 8 )

( 1 2 4 5 8 ) → ( 1 2 4 5 8 )

Third pass

Now, the array is already sorted, but the algorithm does not know if it is completed. The algorithm needs one additional whole pass without any swap to know it is sorted.

Implement the above algorithm. 

Example:

Please enter some numbers: 123 45 78 6 5 48 38 98
[5, 6, 38, 45, 48, 78, 98, 123]

 

Please put your program in bubble_sort.py

Bubble sort is actually a quite inefficient way of sorting: it takes a lot of steps compared to other algorithms such as mergesort.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education