Enable contrast version

Tutor profile: Derek W.

Inactive
Derek W.
Ph.D. in CS - University Lecturer on C, C++, Math, and Comp Sci
Tutor Satisfaction Guarantee

Questions

Subject: Computer Science (General)

TutorMe
Question:

What are the running times of some common sorting algorithms?

Inactive
Derek W.
Answer:

Sorting techniques run in relation to how much data is given to them. Typically we wish to sort n pieces of data, which could be 100 names or 50 grades or two years worth of daily profits. Usually such data is stored in an array and then that array is sorted and utilized elsewhere or output. To sort data, though, we must do some number of comparisons (to see if one piece of data is "larger" than another) and swaps (exchanging the data between two locations in the array). The best case scenario for many sorts is that the array is already sorted, and thus we can quickly verify this in many algorithms by doing n-1 or O(n) comparisons. Typically we seek to reduce the maximum time for the worst case, though. Traditional sorting methods such as and insertion sort, selection sort, bubble sort all have a worst case time of O(n^2), meaning it's possible for data to be arranged such that it will take approximately n^2 (time a constant) operations to complete. Although more complicated in implementation, quicksort and merge sort both have a worst case time of O(n log n) which is considerably better, although the best case for these (i.e. the array is already sorted) is surprisingly worse than insertion and bubble sort!

Subject: C++ Programming

TutorMe
Question:

How do you pass a variable by reference and how is that different from passing it by value?

Inactive
Derek W.
Answer:

When you "send" variables to a function you can do it in one of two ways. Passing it by value indicates that a second variable is created within the function and the value is copied to that new variable. Whatever happens with that variable in the function will not permanently modify the value when the function is over. Passing a variable by reference is to pass the reference itself, a pointer, to the function. Whatever changes are made to the variable are retained with the function is over. To pass by reference, include & before your variable identifier in the function definition. Do note that your variables do not have to be named the same, whether passing by value or reference Passing by value example: void val(int x) { x = x + 5; } int main() { int y = 5; val(y); // value of y here is 5 | Passing by reference example: void ref(int &x) { x = x + 5; } int main() { int y = 5; val(y); // value of y here is 10 }

Subject: C Programming

TutorMe
Question:

How do I raise a number to a power in C programming?

Inactive
Derek W.
Answer:

Although we often see shorthand like 2^3 or 2 ** 3 both indicating 2 to the power of 3 = 8, we cannot use this notation in C programming. The proper way to raise a number to a power is to use the pow function in the math.h header. To do this, make sure to have #include <math.h> as one of your preprocessor directives, and then use pow(x, y) to determine the power of x to the y power. The function takes and returns double values, so while providing integer values for x and y is fine, you may need to typecast the result if you want it to be an integer.

Contact tutor

Send a message explaining your
needs and Derek will reply soon.
Contact Derek

Request lesson

Ready now? Request a lesson.
Start Lesson

FAQs

What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Lesson" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.