Which sorting algorithms are fastest

Assignment Help C/C++ Programming
Reference no: EM131103306

Question 1: Consider the pseudo-code below. Which sort algorithm is it? Indentation in the pseudo-code represents blocks of code, so imagine curly brackets around every indent level. Hint: the algorithm will not look exactly the same as shown in the slides, so you may want to trace the "code" on a simple list, like [ 4 1 3 2 ], to determine which algorithm it is.

void sort(T *array, int n)
{
for loop from i = 1 up to and including n-1
for loop from j = i down to and including 1
if array[j-1] > array[j]
swap array[j-1] and array[j]
else
break }

a) Selection sort
b) Insertion sort
c) Bubble sort
d) Merge sort
e) Quick sort


Question 2: Which sorting algorithm repeatedly splits the array in half until each part of the array only has one element? a) Selection sort
b) Insertion sort
c) Bubble sort
d) Merge sort
e) Quick sort


Question 3: Which sorting algorithm loops over the array, picks the smallest one, and puts it in the first slot, then repeats on the sub-array starting with the second element?

a) Selection sort
b) Insertion sort
c) Bubble sort
d) Merge sort
e) Quick sort


Question 4: Which sorting algorithm relies on a partitioning step to put small values on the left and big values on the right? a) Selection sort
b) Insertion sort
c) Bubble sort
d) Merge sort
e) Quick sort


Question 5: Which sorting algorithms are fastest (in big-O notation) on random data? a) Selection sort
b) Insertion sort
c) Bubble sort
d) Merge sort
e) Quick sort


Question 6: Which two sorting algorithms are fastest (in big-O notation) on already-sorted data? a) Selection sort
b) Insertion sort
c) Bubble sort
d) Merge sort
e) Quick sort


Question 7: If you are sorting 1,000,000 elements and your computer can process 1,000,000 instructions per second, how much time does merge sort save compared to selection sort? a) None; selection sort is actually faster than merge sort.
b) None; they take about the same amount of time.
c) A few seconds.
d) A few minutes.
e) A few days.
f) Hundreds of years.


Question 8: Which of the following options are true of array lists? (Select all that apply). In this question and the next, consider "fast" to refer to constant time O(1)rather than to linear time O(n) or slower. a) Array list getters are fast at the beginning of the list.
b) Array list getters are fast at the end of the list.
c) Array list getters are fast in the middle of the list.
d) Array list insert and remove at the beginning of the list are fast.
e) Array list insert and remove at the end of the list are fast.
f) Array list insert and remove in the middle of the list are fast.
g) Array list numElements is fast.


Question 9: Which of the following options are true of linked lists? (Select all that apply). Consider a standard linked list with no tail pointer or previous pointers. a) Linked list getters are fast at the beginning of the list.
b) Linked list getters are fast at the end of the list.
c) Linked list getters are fast in the middle of the list.
d) Linked list insert and remove at the beginning of the list are fast.
e) Linked list insert and remove at the end of the list are fast.
f) Linked list insert and remove in the middle of the list are fast.
g) Linked list numElements is fast.


Question 10: Consider the following function that uses the abstract List class. Based on how the list is used, which implementation (array list or linked list) would be a better choice? C++

void f(List<string> &list)
{
list.insert(0, "Hello");
list.insert(1, "World");
list.insert(2, "!");
for(int i = 0; i < 1000000; i++)
cout << list.get(i % list.numElements()) << endl; }
a) Array list
b) Linked list
c) Either one is a good choice; neither will be significantly faster
d) Neither one, just instantiate the abstract list class


Question 11: Consider the following function that uses the abstract List class. Based on how the list is used, which implementation (array list or linked list) would be a better choice? C++

voidf(List<int>&list)
{
for(inti=0;i<1000000;i++)
list.insert(0,i);}
a) Array list
b) Linked list
c) Either one is a good choice; neither will be significantly faster
d) Neither one, just instantiate the abstract list class

Reference no: EM131103306

Questions Cloud

Potential legal repercussions : What are some the key areas that employers should avoid when interviewing you? What are some of the potential legal repercussions if an employer asks questions they should not?
Prepare a term paper on reproductive system : Prepare a term paper on Reproductive system. A works cited page must be included listing all of the sources used to prepare your term paper.
Quoting-paraphrasing and summarizing : Read the Quoting, Paraphrasing, and Summarizing article provided by Purdue's Online Writing Lab (OWL) and the Academic Misconduct Policy (policy 2.3.11), and answer the following questions in essay format.
Justify the rationale of this second approach : Justify the rationale of this second approach
Which sorting algorithms are fastest : Which sorting algorithm loops over the array, picks the smallest one, and puts it in the first slot, then repeats on the sub-array starting with the second element?
Explain differences in vocabulary development for children : Based on the information on vocabulary development in your course text and other readings, explain the differences in vocabulary development for children who are bilingual and considerations to keep in mind with regard to assessing vocabulary deve..
Euler characteristic of all connected closed surfaces : Determine the Euler characteristic of all connected closed surfaces
Describe the pathogen and the disease nervous system causes : Between 300-400 words describing the pathogen and the disease it causes. Be sure to include what type of pathogen it is, how the pathogen is transmitted, how it enters the body?
Define celebrity endorsements : What Federal Trade Commission (FTC) regulations define celebrity endorsements? What is the recommended designation a celebrity endorser should include on any tweets or posts via social media to disclose his or her relationship with a company whose..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Design a class called complex

Design a class called Complex. The class enables operations on so called complex numbers. These are numbers of the form realPart + imaginaryPart *i, where the i has the value

  Dimensional array of integers and fill it with data

Create a 2-by-3 two-dimensional array of integers and fill it with data. Loop through the array and locate the smallest value stored. Print out the smallest value as well as its row and column position in the array

  Details of the implementation environment

Present your results in the form of a research paper of more than ten pages in length. Illustrate data in tabulated and/or graphical form and give full details of the implementation environment.

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  Implement a single-arg constructor

Implement a single-arg constructor that sets the initial capacity of the array, with a default of 10, which also serves as the default (no-arg) constructor. The size of the array, unless it is created from an existing array, is initialized to 0.

  Write a program to track hourly employee arrival

A company hires you to write a program to track hourly employee arrival and departure times from work. In essence, you are tasked to make an online time clock - If the user enters an incorrect value more than 3 times, display a prompt that the prog..

  Construct the wait-for graph

P2 waits for 2 units of R1 and holds 1 unit of R2, P3 holds 2 units of R3 and waits for 1 unit of R4, P4 holds 2 units of R3 and waits for 1 unit of R4. Construct the wait-for graph. Does the system have a deadlock? Justify your answer

  Write a gui application that prints out hello

Write a GUI application that prints out "Hello!" in either: English, French, or Spanish. When the user selects another language, the greeting shown in the greeting area should change. Your GUI should look like the interface shown below

  What is realistic rendering in computer graphic

Differentiate between pillar boxing and the letter boxing. What is realistic rendering in computer graphic. Discuss the approach used in realistic rendering.

  Track of the ticket sales

Another thing is tht the program should give the user an option to see how many seats havebeen sold, seats available in each row, and seats available in thewhole theater.

  Describes the application of the s4 symmetry operation

(a) Using its x, y, and z coordinates, construct a 15 × 15 matrix that describes the application of the S4 symmetry operation to [PtCl4]^2-.(b) What is the character of this matrix?

  Your city''s parking violation

Your city's Parking Violation Bureau wants you to write a program to compute fines for parking violations.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd