Question

In: Computer Science

Question III: Programming\flowcharts\algorithms Sort the following list from the smallest to the largest using the bubble...

Question III: Programming\flowcharts\algorithms

  1. Sort the following list from the smallest to the largest using the bubble sort algorithm (show all passes) [4 points]

20

10

30

5

0

  1. Write a python program that asks the user to enter the number of seconds. The program will print the whole hours, whole minutes and remaining seconds. For example: if the user entered the number of seconds as 3663 then the output will be: 1 hour(s), 1 minute(s), 3 second(s). [5 points]

Note: You do not need to add comments

  1. Draw a flowchart (use loops) that gets a positive integer number from the user (num) and prints the first 3 multiples of num. [6 points]

For example: if the user entered 3 then the output will be:

3

6

9

Note: multiples of 3 are: 1 x 3= 3, 2 x 3=6, 3 x 3=9, etc.

Solutions

Expert Solution

Sorting List:

CODE:

a=[20,10,30,50]

for i in range(len(a)):
for j in range(len(a)-i-1):
if a[j]>a[j+1]:
temp=a[j] #swap adjacent elements if condition meets
a[j]=a[j+1]
a[j+1]=temp
print(a)

Screenshots:

Python program that find hours,minutes and seconds

CODE:

#Reading input from user
t=int(input("Enter seconds::"))
#Find no.of hours
hours=int(t/3600)
t=t%3600
#Find no.of minutes
minutes=int(t/60)
t=t%60
#Find no.of seconds
seconds=t

print(str(hours)+" hour(s),"+str(minutes)+" minute(s),"+str(seconds)+" second(s)")

Screenshots:

Flow chart for first three multiples of a number


Related Solutions

Write two algorithms to find both the smallest and largest numbers in a list of n...
Write two algorithms to find both the smallest and largest numbers in a list of n numbers. In first algorithm, you simply write one loop to find the minimum and maximum. So there will be 2(n - 1) comparisons. In second algorithm, you try to find a method that does at most 1.5n comparisons of array items. Determine the largest list size (i.e., n) that Algorithm 1 can process and still compute the answer within 60 seconds. Report how long...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Rank the algorithms from slowest to fastest. . Bubble Sort Linear Search Binary Search Shellsort
Rank the algorithms from slowest to fastest. . Bubble Sort Linear Search Binary Search Shellsort
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the...
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the process step-by-step, and find the time complexity in Big-O notation for each method. For sorting, use ascending order. 49, 7, 60, 44, 18, 105
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from...
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from the current directory a list of intergers (10 numbers to be exact), and the sort them, and print them to the screen. You can use redirection to read data from a given file through standard input, as opposed to reading the data from the file with the read API (similar to Lab #1). You can assume the input data will only have 10 numbers...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers by repeatedly calling a “swap” subroutine. The original unsorted list of integers should be received from the keyboard input. Your program should first prompt the user “Please input an integer for the number of elements:”. After the user enters a number and return, your program outputs message “Now input each element and then a return:”. For example, if the user enters 5 as the...
1. List each body habitus from smallest to largest and describe each (1 point).
1. List each body habitus from smallest to largest and describe each (1 point).
Which of the following sorting algorithms are stable: insertion sort, selection sort, merge sort and quick...
Which of the following sorting algorithms are stable: insertion sort, selection sort, merge sort and quick sort? Give a simple scheme that makes any sorting algorithm stable. How much additional time and space does your scheme entail?
The programming language is C. In its simplest algorithm, the bubble sort technique compares each two...
The programming language is C. In its simplest algorithm, the bubble sort technique compares each two adjacent elements of an array of size “N” and exchanges their values if they are out of order. The process of comparing and exchanging is repeated for N array passes. For sorting array elements in ascending order, the smaller values “bubble” to the top of the array (toward element 0), while the larger values sink to the bottom of the array. Assuming that: double...
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople...
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople on a commission basis.  The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period.  For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21.  Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points.  There...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT