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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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