Ask C/C++ Expert


Home >> C/C++

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 &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&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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91856693
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As