The sequence 2, 4, 1, 3, 5 has three inversions (2,1), (4,1), (4,3). Using C++ Code an O(nlog(n)) algorithm to count the number of inversions. Use the Merge sort Algorithm, and use the template below: (Use the file below that to test)
countInv.cpp -------------------------------------------------------------------------------------------------------------------------------
#include <vector>
#include <algorithm>
using namespace std;
int mergeInv(vector<int>& nums, vector<int>&
left, vector<int>& right) {
// Your code here
}
int countInv(vector<int>&nums) {
// Your code here
}
CountInv_test.cpp -------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <vector>
using namespace std;
int countInv(vector<int>& numvec);
int main()
{
int n;
vector<int> numvec{4, 5, 6, 1, 2, 3};
n = countInv(numvec);
cout << "Number of inversions " << n << endl; //
Should be 9
numvec = {1, 2, 3, 4, 5, 6};
n = countInv(numvec);
cout << "Number of inversions " << n << endl; //
Should be 0
numvec = {6, 5, 4, 3, 2, 1};
n = countInv(numvec);
cout << "Number of inversions " << n << endl; //
Should be 15
numvec = {0, 0, 0, 0, 0, 0};
n = countInv(numvec);
cout << "Number of inversions " << n << endl;; //
Should be 0
}
In: Computer Science
The sequence 2, 4, 1, 3, 5 has three inversions (2,1), (4,1), (4,3). Using C++ Code an O(nlog(n)) algorithm to count the number of inversions. Use the Merge sort Algorithm, and use the template below: (Use the file below that to test)
countInv.cpp -------------------------------------------------------------------------------------------------------------------------------
#include <vector>
#include <algorithm>
using namespace std;
int mergeInv(vector<int>& nums, vector<int>&
left, vector<int>& right) {
// Your code here
}
int countInv(vector<int>&nums) {
// Your code here
}
CountInv_test.cpp -------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <vector>
using namespace std;
int countInv(vector<int>& numvec);
int main()
{
int n;
vector<int> numvec{4, 5, 6, 1, 2, 3};
n = countInv(numvec);
cout << "Number of inversions " << n << endl; //
Should be 9
numvec = {1, 2, 3, 4, 5, 6};
n = countInv(numvec);
cout << "Number of inversions " << n << endl; //
Should be 0
numvec = {6, 5, 4, 3, 2, 1};
n = countInv(numvec);
cout << "Number of inversions " << n << endl; //
Should be 15
numvec = {0, 0, 0, 0, 0, 0};
n = countInv(numvec);
cout << "Number of inversions " << n << endl;; //
Should be 0
}
In: Computer Science
Investment A:
Year: 0 1 2 3 4 5
Cash flow: -$14,000 $6,000 $6,000 $6,000 $6,000 $6,000
Investment B:
Year: 0 1 2 3 4 5
Cash flow: -$15,000 $7,000 $7,000 $7,000 $7,000 $7,000
Investment C:
Year: 0 1 2 3 4 5
Cash flow: -$18,000 $12,000 $4,000 $4,000 $4,000 $4,000
The cash flows for three projects are shown above. The cost of
capital is 7.5%. If an investor decided to take projects with a
payback period two years or less, which of these projects would he
take?
Select one:
A. Investment A
B. Investment B
C. Investment C
D. none of these investments
In: Finance
For the following exercises, calculate u ⋅ v.
Given v = 〈−3, 4⟩ draw v, 2v, and 1/2 v.
In: Math
1. Supplementary motor cortex
2. Premotor cortex
3. Basal ganglia
4. Cerebellum
5. Parietal area of the cerebral cortex
6. Spinothalamic pathway
7. Corticospinal tract
8. Dorsal root ganglion
9. Dorsal Column pathway
Q1. Which structure or region is damaged in patients with
Parkinson’s disease?
Answer 1Choose...1.2.3.4.5.6.7.8.9.
Q2. Which structure or region includes the cell bodies of sensory
neurons?
Answer 2Choose...1.2.3.4.5.6.7.8.9.
Q3. Which structure or region conveys information from the brain to
the spinal cord?
Answer 3Choose...1.2.3.4.5.6.7.8.9.
Q4. Which structure or region is damaged in patients with
Huntington’s disease?
Answer 4Choose...1.2.3.4.5.6.7.8.9.
Q5. Which structure or region that is not part of the cerebral
cortex is involved in initiating complex movements?
Answer 5Choose...1.2.3.4.5.6.7.8.9.
Q6. Which structure or region handles information from pain
receptors?1.2.3.4.5.6.7.8.9.
In: Biology
Calculate Payback period, Net Present Value and Benefit Cost Ratio
| Period | 0 | 1 | 2 | 3 | 4 | 5 |
| Year | 2,019 | 2020 | 2021 | 2022 | 2023 | 2024 |
| Cash Flows | -30,000 | 11,000 x .8929 = 9821.9 | 14,000 x .7972 = 11,160.8 | 10,000 x .7118= 7,118 | 7,000 x .6335 = 4434.5 | 12,000 x .5674 = 6808.8 |
In: Finance
| x | 0 | 1 | 2 | 3 | 4 |
| P(X) | 0.45 | 0.3 | 0.2 | 0.04 | 0.01 |
(a) Find and interpret the expected value of X
(b)Find the variance of X
(c)Find the probability that a person has 1 sibling given that they have less than 3 siblings.
(d)Find the probability that a person has at least 1 sibling OR less than 2 siblings
In: Statistics and Probability
A three-digit number is formed from nine numbers (1, 2, 3, 4, 5, 6, 7, 8 & 9). No number can be repeated. How many different three-digit numbers are possible if 1 and 2 will not be chosen together? a. 462 b. 210 c. 672 d. 336
In: Statistics and Probability
|
Consider the following time series data.
Calculate the measures of forecast error using the naive (most recent value) method and the average of historical data (to 2 decimals).
|
Top of Form
Consider the following time series data.
|
Month |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
Value |
23 |
14 |
19 |
10 |
18 |
23 |
26 |
Round your answers to two decimal places.
a. Compute MSE using the most recent value as the forecast for the next period.
Mean squared error is ?
What is the forecast for month 8 ?
b. Compute MSE using the average of all data available as the forecast for the next period.
Mean squared error is ?
What is the forecast for month 8 ?
In: Statistics and Probability
Consider the following time series.
| t | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| yt | 125 | 108 | 102 | 99 | 94 | 92 | 86 |
| (b) | Use simple linear regression analysis to find the parameters for the line that minimizes MSE for this time series. |
| If required, round your answers to two decimal places. | |
| y-intercept, b0 = | |
| Slope, b1 = | |
| MSE = | |
| (c) | What is the forecast for t = 8? |
| If required, round your answer to one decimal place. | |
In: Statistics and Probability