“while” loop:
A while loop is a control flow statement whose basic purpose is to execute the block of statements repeatedly as long as the conditional statement is true.
- If the condition is false then it does not execute the block of statement.
Insertion sort
The algorithm is basically designed to organize and sort the array or list of elements in specific manner, that enables the system and user to get the final sorted array or a list of elements.
Generally, the insertion sort technique divides the list into two parts: sorted or unsorted list.
In the sorted list, the method assumes that one element of the list is already sorted and then it performs the operation on the unsorted list by inserting elements in its appropriate position in the sorted list.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- 1. ax + b = 0, y = aeˣ! a,b ≠ 0a,b are constants number entered by the user. Find (x,y) and determine the quadrant of thecartesian plane. Print (x,y) and write which quadrant (I,II,III or IV). (PYTHON) 2. Write a program that sorts a list in ascending order. Don’t use sort method.Ask user number of list elements (at least 10 elements)Enter all elements from keyboard and printed.Sort your list. (PYTHON)arrow_forwardAlter insertion sort below to sort a list of strings instead of numbers. It shouldn't return anything - it should sort the list "in place". The sorting should ignore case. For example "Zebra" should come after "apple", "maRker" should come after "marble", etc. Name this function string_sort. After calling this function, the list that was passed in should now contain the exact same strings it did before, but in sorted order. def insertion_sort(a_list): """ Sorts a_list in ascending order """ for index in range(1, len(a_list)): value = a_list[index] pos = index - 1 while pos >= 0 and a_list[pos] > value: a_list[pos + 1] = a_list[pos] pos -= 1 a_list[pos + 1] = valuearrow_forwardGiven the following list { 10,9,-2,1}, sort the list using selection sort and fill out the following table. static void selectionSort(double [] list) {// find minimum in the list [i....list.length-1]for (int i=0;i<list.length;i++) {double currentMin=list[i];int currentMinIndex=i;for (int j=i+1;j<list.length;j++) {if (currentMin>list[j]){currentMin=list[j];currentMinIndex=j;}}// j for// swap list[i] with list[currentMindIndex ifnecessary.if (currentMinIndex!=i) {list[currentMinIndex]=list[i];list[i]=currentMin;}// if}// for}arrow_forward
- A user is going to enter numbers one at a time, entering 'q' when finished. Put the numbers in a list, sort it in numerical order, and print out the list. Then print out the middle element of the list. (If the list has an even number of elements, print the one just after the middle.) Remember that a list 1st of numbers can be sorted numerically by calling 1st.sort(), and can be printed with print(1st). You can assume that every entry is either a valid integer or is the letter 'q'. Examples: If the input is 4 3 6 7 3 q The output is [3, 3, 4, 6, 7] 4 If input is 4 3 6 7 3 2 q The output is [2, 3, 3, 4, 6, 7] 4arrow_forwardAssume, you have been given two lists. Your task is to multiply the first element of the first list, to the last element of the second list and store them in another list. Then, again multiply the second element of the first list, to the second last element of the second list, and so on. If any of your lists is out of element, and another list has some elements remaining, then just append the remaining elements to your final list and print the list.================================================ Given lists 1:list_one = [1, 4, 7, 5]list_two = [6, 1, 3, 9] Sample Output 1:[9, 12, 7, 30] Explanation 01: Here, from list_one’s 1st element, 1 has been multiplied with the last element of list_two 9. So, the product 1X9 =9 has been added to the answer. Then, from list_one’s 2nd element, 4 has been multiplied with the 2nd the last element of list_two 3. So, the product 3X4 =12 has been added to the answer. And so on. ================================================Given lists 2:list_one =…arrow_forwardWrite a program that counts, in the given list of integers below, the number of occurrences of each integer. You must loop through the list to assign keys and values to the dictionary. Use must use another loop to print the dictionary values for the output. - list1 = [1,2,3,3,2,4,5,6,3,2,4,5,2,3,4,5,6,3] Example Output (It must look like this): 1 is in the list 1 time(s).2 is in the list 4 time(s).3 is in the list 5 time(s).4 is in the list 3 time(s).5 is in the list 3 time(s).6 is in the list 2 time(s).arrow_forward
- the list has the following items 17 9 11 30 8 20 35 7 5 45 3 28 Apply the quick sort on the above list by using the pivot is always the left item and find the following The list after a first partition callarrow_forwardWrite a python program to get two numbers from user. If both numbers are even add them andprint and if both numbers are odd multiply them and print and if one is even / one is odd subtractthem and print.Question22: Write a python program to take the values from below list and add it to new dictionary usingfor loop. Keys of dictionaries are 1,2,3,4. Print the new dictionary as well.Marks = [15,24,67,80]arrow_forwardWrite a version of the sequential search algorithm that can be used to search a sorted list. Write a program to test the sequential search algorithm. Use either the function bubbleSort or insertionSort to sort the list before the search. Your program should prompt the user to enter 10 digits and then prompt the user to enter a digit to search - if the list contains this digit, output its position to the console: x is found at position y If the digit is not contained in the list, output the following: x is not in the listarrow_forward
- A list is given an = {6,2,-4,13,7} Answer the following questions. a. What is n in an? b. List all the steps of sorting this list using insertion sort. c. What is the output of this search? And what does it indicate?arrow_forwardpython code. instructions are given within the quotation marks. 1) def get_misspelled_linear(dictionary, text): """ dictionary is a list of sorted words in the dictionary; you may assume all words in the dictionary are lower case and only contains a-z and apostrophe' text is a list of words from any given text. Use linear search to find the list of all misspelled words in text, a misspelled word is a word that is in the text but not in the dicionary. The comparison is case insensitive. For example if cat is in the dictionary, then CAT, cAt, cAT, cat and etc. are all considered to be valid word. Return the list of misspelled word. Your list of misspelled word must appear in the original order as they were in the text list and keep original form (upper/lower case) if dictionary has N words and text has K words, then the running time for this method will be O(NK) """ return [] 2) def get_misspelled_binary(dictionary, text): """ dictionary is a list of sorted words in the dictionary; you…arrow_forward1. What's in There? by CodeChum Admin Let's try defining the size of the list and create the contents of it on our own! And then, to give off a sense of excitement, let's try accessing the value of a list element in a random index position! Let's do this fast! Instructions: Create a variable that accepts a positive integer. Create an empty list. Then, using loops, add string values to your list using the input() function. The number of string values to be added are dependent on the inputted value on the first inputted integer. Create another variable that accepts a non-negative integer. The number must only range from 0 until the value of the first inputted integer. Using your understanding on accessing list elements, access and print out the list element having the index position of the second inputted integer. use java in programming languagearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning