CSC2401 Algorithms and Data Structures Assignment

Assignment Help Other Subject
Reference no: EM132592557

CSC2401 Algorithms and Data Structures - University of Southern Queensland

Question 1

Task 2.1 demonstrates how to create a recursive function factorial(int n).
Task 2.6 demonstrates how to perform Tail Optimization to the recursive function square(int n) and transform it to a tail recursive function.
We can follow the example and apply Tail Optimization to change factorial(int n) to a tail recursive function.

Write a C++ program which
• Prompts user to input an integer n smaller than 10;
Please enter an integer n less than 10:

• Uses a Tail Recursive version of factorial(int n) to calculate factorial n;
• Outputs (e.g. n= 7) before terminating the program:
Factorial 7 = 5040

Submit your C++ program as <StudentID>Q1.cpp.

Question 2 - Merge Sort Pseudocode:
void merge_sort(vector<int>& a, int from, int to){ if (from == to) return;
int mid = (from + to) / 2; merge_sort(a, from, mid); merge_sort(a, mid + 1, to); merge(a, from, mid, to);
}
C++ code:
void merge(vector<int>& a, int from, int mid, int to){ int n = to - from + 1;
vector<int> b(n); int i1 = from; int i2 = mid + 1; int j = 0;
while (i1 <= mid && i2 <= to) { if (a[i1] < a[i2]) {
b[j] = a[i1]; i1++;
} else {
b[j] = a[i2]; i2++;
} j++;
}
while (i1 <= mid) { b[j] = a[i1]; i1++;
j++;
}
while (i2 <= to) { b[j] = a[i2]; i2++;
j++;
}
for (j = 0; j < n; j++) { a[from + j] = b[j];
}
}

Analyze Merge sort listed above and express its time complexity in Big O notation. You have to show your working and reasoning.
Submit your answer as <StudentID>Q2.pdf.

Question 3
Task 3C.5 uses Linear Search to perform searching. Task 3C.6 uses Binary Search to perform searching. Write a C++ program which
• Prompts user to input an integer n larger than 100 and less than nmax = 1,000,000 as shown below
Please enter an n (100 < n < 1,000,000):

• Generates a vector V of n random integers between 1 and imax =100,000,000;
• (nmax and imax may have to be adjusted according to the capability of your PC.)
• Calculate int T:
o X =((V.at(n/4) + V.at(n/2) + V.at(3n/4))) mod n
o T = V.at(X)
o Example:
o n = 1,000,000
o imax = 100,000,000
o V.at(n/4) = V.at(250,000) = 123,456
o V.at(n/2) = V.at(500,000) = 987,654,321
o V.at(3n/4) = V.at(750,000) = 67,584,220
o X = (123,456 + 987,654,321 + 67,584,220 ) mod 1,000,000
= 361,997
o T = V.at(361,997)
• Use the random number (determined at run time) at position X of the vector as the value T for searching i.e. T = V.at(X); (we cannot use V.at(X-1) in case X
=0).
• Search the same vector for T using Linear Search, and Binary Search;
• Time the two searches;
• Repeat with the same n a number of time to get an average time.
• Repeat with six different values of n;
• Show the search result in two tables, one for each search;
• Plot the two tables in one graph using n as x-axis and time as y-axis similar to the graphs shown below:


• You have to provide proper labelling and units for the graph

a) Submit your program as <StudentID>Q3.cpp
b) Submit your graph as <StudentID>Q3.pdf

Attachment:- Algorithms and Data Structures.rar

Reference no: EM132592557

Questions Cloud

Research disease of the reproductive system : Research a disease of the reproductive system,. Chapter 25-hereditary diseases is an excellent reference.
Discuss the effect on the journal entry for flynn at lease : Discuss the effect on the journal entry for Flynn at lease commencement, assuming initial direct costs of $2,000 are incurred by Flynn to negotiate
Optimal markups and prices under third-degree : You are the manager of a monopoly that sells a product to two groups of consumers in different parts of the country.
Discuss specific ways each policy promotes family resilience : Use the two-family constellations identified above and identify specific policies that exist in the United States that either promote or deter resilience.
CSC2401 Algorithms and Data Structures Assignment : CSC2401 Algorithms and Data Structures Assignment Help and Solution, University of Southern Queensland - Assessment Writing Service - Analyze Merge sort
How much did the company pay for a dividend in the past year : The company is growing at a constant rate of 4% per year and the expected rate of return is 14%. How much did the company pay for a dividend in the past year?
Clinical signs of diseases in nails : You will be investigating skin disorders and the clinical signs of diseases in nails. describe how the structure of the skin is affected by the disorder.
Explain aversives should be used in the treatment of sib : Explain whether you believe aversives should be used in the treatment of SIB. Justify your rationale by explaining ethical issues regarding the use.
What should be the current price of the stock : Sketchy Tech Corp is expected to grow 5%, Given that investors require a 12% required rate of return, what should be the current price of the stock?

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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