Assume you are implementing an application where a large set of data elements is kept in a sorted list. If an important issue is speed of the sorting algorithm, which of the following algorithms would be preferred? a. Merge Sort b. Bubble Sort C. Selection Sort d. Insertion Sort
Q: currnetMin currnetMinlndex The list
A: Here we drive and run the code in figure then fill the table.…
Q: Write a program to test the sequential search algorithm that you wrote of this chapter. Use either…
A: Program code: //include the required header files#include<iostream>using namespace…
Q: You're given a set of sorting algorithms: quickSort, insertionSort, bubbleSort. Write a C++ code…
A: #include <iostream> #include <fstream> #include <cstdlib> #include <ctime>…
Q: Realize direct insertion sort, half insertion sort, bubble sort, quick sort, select sort, heap sort…
A: Bubble sort: Bubble sort repeatedly compares and swaps(if needed) adjacent elements in every pass.…
Q: Merge Sort
A: According to the question we have the list of the following list of 16 keys:18, 40, 16, 82, 64, 67,…
Q: In a loop, fill an array for up to 50 even numbers and a set for up to 50 odd numbers. Use the…
A: Since you have asked multiple questions in a single request, as per the policy, we will be answering…
Q: A. Always liberate space in the computer memory B. Needs an express liberation of space by the…
A: 29.Interrupt driven input output leads to 30.The hardware instruction cycle is 31.A problem is said…
Q: Assume you have a sorted list of integers. And you add a random integer to the end of the list.…
A: Sorting Algorithms: the way of presenting(organizing) the given data(array/list) in a particular…
Q: Two arrays list1 and list2 are strictly identical if they have the same length and list1[i] is equal…
A: Program: // C++ version 14 # include <iostream>using namespace std;// boolean functionbool…
Q: email address, birthday, etc. Write a program that first takes as input an integer N that represents…
A: Code: import java.util.Scanner; class Main{ public static String getPhoneNumber(String[]…
Q: Two arrays list1 and list2 are identical if they have the same contents. Write a function that…
A: Two arrays list1 and list2 are identical if they have the same contents. Write a function that…
Q: In Section 10.11.1, you used selection sort to sort a list. The selection-sort function repeatedly…
A: Given: you used selection sort to sort a list. The selection-sort function repeatedly finds the…
Q: You can shuffle a list using random.shuffle(lst). Write your own function without using…
A: PROGRAM CODE: import random // import the random library def shuffle(lst):…
Q: You were tasked to do programs that will illustrate the use of lists implemented using an array. One…
A: “Since you have posted a question with multiple sub-parts, we will solve first subpart for you. To…
Q: Assume that you have a student list of this class which list consists of only student names. Your…
A: I have taken 10 student names assuming each length is less than 10 characters as shown below. I used…
Q: 4. Use a for loop and the list append method to generate the powers of 2 to produce the following…
A: I have given an answer in step 2.
Q: Create a function: -that takes a list and an integer v, -and returns the number of occurrences of v…
A: Have a look at the below code. I have put comments wherever required for better understanding. Code…
Q: Hello, I am having a bit of trouble completing this assignment. I am trying to do it in Python…
A: To write a program in Python, this program will: This program will display a message to the user to…
Q: Write the C++ code of queue which is performed multiple task which are given below and performed all…
A: Lets see the solution.
Q: JAVA PROGRAM Pretend Write a program that reads integers from the user and stores them in a list.…
A: Introduction of the Program: The Java Program takes the integer input from the user and adds all…
Q: c++ For this problem, you will need to sort a list of whitespace separated integers using three…
A: Actually, sorting is the arrange the elements in order(ascending or descending).
Q: Write a sort function that uses the bubble-sort algorithm. The bubble-sort algorithm makes several…
A: BUBBLE SORT Bubble sort is the simplest algorithm that works by continuously swapping the adjacent…
Q: int foo(listL,int s) if (L.empty() ) return 0; if(s<L.size () ) { int t; L.retrieve (s,t); return…
A: Question: This code used to?
Q: Write a program that sorts a list in ascending order. Don’t use sort method. Ask user number of list…
A: Please find the answer below
Q: you may not use any of the following: dictionaries or dictionary methods try-except break and…
A: This can be done using the simple logic we can do this in O(n) time by simple traversal We know we…
Q: Python function getData(fname:str)->ndarray that inputs data from a file into a list, then converts…
A: Python function getData(fname:str)->ndarray that inputs data from a file into a list, then…
Q: Bubble sort, selection sort and insertion sort are all O(n2) sorting procedures in the worst case.…
A: The correct answer is discussed in the next step
Q: This program in python that requires two functions. In the main function: create an empty list. use…
A: Program Instructions:Import random module and use randint() function to generate random numbers.Use…
Q: Assume the list is sorted by one of the comparison sorts. And after some iterations the list…
A: The given array after few steps of sorting is 6 2 10 7 9 8 13 15 Here the option (A) is wrong since…
Q: C++ language. Using the coding prepared below, add and create the Undo last pop, Display undo list…
A: #include<iostream>#include<iomanip>#include<ctype.h> using namespace std; char…
Q: o sorted array-based lists into one sorted array-based list. The function takes two arrays as…
A: Step 1: Here is the completed code for this problem. Comments are included, go through it, learn…
Q: Assuming that data is a correctly created list, then the fact that lists are mutable means that the…
A: Since the python follows the zero indexing rule, there must be at least 10 elements inside the list…
Q: Bubble Sort HouseholdSize.py 2 HouseholdSize.py - This program uses a bubble sort to arrange…
A: Python code: householdSizes = [] numSizes = 0 total = 0.0 mean = 0.0 median = 0.0…
Q: Search of Strings 1. Write a version of the selection sort algorithm presented in the unit, which is…
A: #include <iostream>#include <vector>using namespace std; void…
Q: Write a program that takes an integer list as input and sorts the list into descending order using…
A: Note: The correct code and output attached below. If you have any further query please let me know…
Q: 28. You are given a name arranged in bibliography (reverse) format. This line of names is then read…
A: Input : Putro, Hanson Output: Hanson Putro Answer- the code should be- name= input().split()…
Q: Answer one of the following A) What is the list? List the basic operation performed on the list.…
A: Q. 1 Lists are sequence containers that allow non-contiguous memory allocation. It is also known as…
Q: Write the following function that returns the location of the largest element in a two-dimensional…
A: According to the Question below the Solution: Output:
Q: Assume that you have a student list of this class which list consists of only student names. Your…
A: In step 2 you will get the C code and in step 3 you can see the output. I have used 2-dimensional…
Q: 1. If the above list was sorted using Selection sort, which two elements would be swapped first? 2…
A: As per guidelines I can answer only first question. I hope you will understand. Thank You. Given…
Q: Create a program that would accept 10 strings from the user (each string has a maximum of 10…
A: In this program, the user inputs 10 strings and therefore these are further sorted in a…
Q: Imagine you want to use insertion sort for sorting a deck of cards, where the suits are ordered…
A: InsertionSort(A) - Insertion sort function takes input as an array A of deck of cards and returns…
Q: You are given the following functions (assume imports have been properly made): def…
A: The solution for the above given question is given below:
Q: Write a program to find the number of comparison using sequentialSearch and binarySearch algorithms…
A: While doing programming in any programming language, you need to use various variables to store…
Q: KEYWORDS: array, for, nested loops. LAB EXERCISE: Program 1: Write a program for implementation of…
A: Take input array, left, right & x START LOOP – while(left greater than or equal to right) mid =…
Q: KEYWORDS: array, for, nested loops. LAB EXERCISE: Program 1: Write a program for implementation of…
A: According to the Question below the Complete Program: Program Output:
Q: that gets a a paramet ate from that list. At the end return the new list. Do not use dictionary…
A: Main logic: - i = 0 while i < len(a): j = i + 1 while j < len(a): if…
java
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- ing Your goal is to modify your Assignment 6 program to allow the user to pick up a random item and display a sorted list of the contents of the knap sack. Note: If you use the built in C++, the most you can make on this assignment is 4 out of 10. You are expected to right your own sort based on one of the algorithms covered in class. Your program should have the following: • The name of the program should be Assignment 6. • 3 comment lines (description of the program, author, and date). • Modify your Assignment 5 program to do the following: o Display a menu (use a switch statement to implement the menu) of actions ▪ Attack: • For now, just display that the user chose to attack ▪ Pick up Item: • Randomly add one of 6 items to an array named knapSack o You get to choose the item names • Display which item the user picked up ▪ Add an option to the main switch statement: Display Knap Sack contents • The contents of the knap sack must be sorted Make the code easy…c++ For this problem, you will need to sort a list of whitespace separated integers using three different sort algorithms (described here: http://theoryapp.com/selection-insertion-and-bubble-sort/ and https://en.wikipedia.org/wiki/Insertion_sort). Your program will output the state of the initial list of numbers and also after each swap for each of the three sorting algorithms (selection, insertion, and bubble). Note: You want to use the version of insertion sort from Wikipedia. Do not perform swaps if they don't change the vector. Inputs: 8 8 4 1 7 5 9 3 2 1 6 3 8 4 2 9 4 2 5Modify the following program to read dictionary items from a file and write the inverted dictionary to a file: characters = {'Bugs':['Rabbit', 1940, 'boy'], 'Garfield': ['Cat', 1978, 'boy'], 'Tweety': ['Bird', 1942, 'girl'], 'Sandy': ['Squirrel', 1999, 'female']} print("Printing the original dictionary") print(characters) print("") def invert_dict(characters): inverse = dict() for key in characters: val = characters[key] for list_item in val: if list_item not in inverse: inverse[list_item] = [key] else: inverse[list_item].append(key) return inverse my_invert = invert_dict(characters) print("Printing the inverted dictionary") print(my_invert) Include the following: 1) The input file for your original dictionary (with at least six items).2) The Python program to read from a file, invert the dictionary, and write to a different file.3) The output file for your inverted dictionary.…
- Capital Quiz use pythonThe Capital Quiz ProblemWrite a program that creates a dictionary containing the U.S. states as keys, and their capitals asvalues. (Use the Internet to get a list of the states and their capitals.) The program should thenrandomly quiz the user by displaying the name of a state and asking the user to enter that state’s574capital. The program should keep a count of the number of correct and incorrect responses. (Asan alternative to the U.S. states, the program can use the names of countries and their capitalsQuestion1: define two lists of numbers (arrays) and ask the user to give the size of each, and then ask the user to fill the list(according to a size that he gave), then compare two arrays and determine whether they are equal? Note: two arrays are equal if all elements are equal. (Array not vector )In Python, grades_dict = {'Wally': [87,96,70], 'Eva': [100,87,90], 'Sam': [94,77,90], 'Katie': [100,81,82], 'Bob': [83, 65, 85]} Ask user to enter the names of the rows, i.e., indices. You can use: len(grades) to get the number of rows of the DataFrame. In addition, using the sort_index() method, ask user whether they wish to sort by rows or by columns and whether to sort in ascending or descending order (do not use any if-else statements)
- your goal is to modify your assignment 6 program to allow the user to pick up a random item and display a sorted list of the contents of the knap sack. note: if you use the built in c++, the most you can make on this assignment is 4 out of 10. you are expected to right your own sort based on one of the algorithms covered in class. your program should have the following: • the name of the program should be assignment 6. • 3 comment lines (description of the program, author, and date). • modify your assignment 5 program to do the following: o display a menu (use a switch statement to implement the menu) of actions ▪ attack: • for now, just display that the user chose to attack ▪ pick up item: • randomly add one of 6 items to an array named knapsack o you get to choose the item names • display which item the user picked up ▪ add an option to the main switch statement: display knap sack contents • the contents of the knap sack must be sorted The knapsack items are bananas, lays,…In C program language, You are to read 10 numbers from a data file into an array named List. Create another 10 element array named Reverse that is to contain the same items as List but in reverse order. For example, the first element in List will be placed in the last position of Reverse, the second element in List will be placed in the second-to-last position in Reverse, etc. After Reverse has been created, output the contents of both arrays.1. Write a game of rock paper scissors, one of the choices will be from the user and the other from the computer (use random) Print results for each game.Play the games in a row until you exit the game. Explain each step as comment.Game rules:Rock crushes scissors, you win.Paper covers rock, you win.Scissors cut paper, you win. 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. 3. Write a code for craps game. Craps is a dice game in which the players make wagers on the outcome of the roll, or a series of rolls, of a pair of dice.The rules of the dice game craps are as follows:You roll two dice. Each die has six faces, which contain one, two, three, four, five and six spots, respectively. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, you win and play is…
- True or False For each statement below, indicate whether you think it is True or False If you have an array with no “holes”, the append function performs at O(1) Inserting an element at the front and shifting all elements performs significantly worse than appending an element at the end of the list For the insert function, if the array is empty, there are no comparison operations that need to be performed and you can immediately add the new element Binary search can be used on an unsorted array to significantly improve its performance from O(n) to O(1)True or False For each statement below, indicate whether you think it is True or False If you have an array with no “holes”, the append function performs at O(1) Inserting an element at the front and shifting all elements performs significantly worse than appending an element at the end of the list For the insert function, if the array is empty, there are no comparison operations that need to be performed and you can immediately add the new element Binary search can be used on an unsorted array to significantly improve its performance from O(n) to O(1) Because the update algorithm depends on using linear search, its performance is O(1) in the worst case scenario True If you search for and delete an element in an unsorted array and then shift the rest of the elements to fill the hole, the worst case performance is O(n) If you search for and delete an element in an unsorted array and then move the last element to fill the hole, the worst case performance is O(n)The question is in bold the other parts juts helps explain concepts . Write a function insertionsort(somelist) that applies the insertion sort algorithm. (You should use the pop and insert commands) Insertion sort works as follows remove the first element from the original list (mylist) and add it to a new list sortedlist. Then repeat, at each stage removing the first element (call it x) from mylist and adding it to sortedlist. The challenge is that it needs to be added at the correct position, which means scanning through sortedlist for the first element bigger than x and inserting x just before that point, or if there is no such element then inserting x at the end. We recollect two useful list commands you should use in this code: • x = mylist.pop(0) which lets x be the entry at index 0 of mylist while also removing that entry from mylist. (Generally x = mylist.pop(j) works in the obvious way.) • sortedlist.insert(i,x) which changes sortedlist by inserting x into it at index i (with…