J
Joseph A.
Hi, I have to take a prelim exam for my work dealing with c++. I am
VERY RUSTY so I need some help. They gave me a study sheet to prepare
for the exams, and I've done most of it but cannot figure out how to do
the following. I just need help, thank you very much.
1. Write a function in C++ called secMaxElement that takes an input a
vector<double>& and returns the second largest in the array. How fast
is your algorithm (in big O notation). What if we wanted the 5th
largest element, or the 15th largest, or more generally the kth largest
(i.e. if we made k an argument to maxElem). Don't write any code but
explain how you would solve the more general problem. How fast is your
algorithm now?
2. Write a C++ function that takes as input a double and returns its
square root (you may not use any standard library math functions of
course). There is more than one way to go here - just pick one. Write
this as a complete program (that includes a main) that takes the double
as an input at the command line.
VERY RUSTY so I need some help. They gave me a study sheet to prepare
for the exams, and I've done most of it but cannot figure out how to do
the following. I just need help, thank you very much.
1. Write a function in C++ called secMaxElement that takes an input a
vector<double>& and returns the second largest in the array. How fast
is your algorithm (in big O notation). What if we wanted the 5th
largest element, or the 15th largest, or more generally the kth largest
(i.e. if we made k an argument to maxElem). Don't write any code but
explain how you would solve the more general problem. How fast is your
algorithm now?
2. Write a C++ function that takes as input a double and returns its
square root (you may not use any standard library math functions of
course). There is more than one way to go here - just pick one. Write
this as a complete program (that includes a main) that takes the double
as an input at the command line.