TutorMe homepage

SIGN IN

Start Free Trial

Will K.

Developer at Carleton College

Tutor Satisfaction Guarantee

Python Programming

TutorMe

Question:

Given a list (called array) of true and false values, provide a snippet of Python code that sorts the list so that every false value precedes a true value in $$O(n)$$ time. Assume that the array has at least 1 value in it.

Will K.

Answer:

i = 0 j = len(array) - 1 while i != j: if array[i] and not(array[j]): temp = array[i] array[i] = array[j] array[j] = temp elif array[i]: j = j - 1 elif not(array[j]): i = i + 1 else: i = i + 1

Java Programming

TutorMe

Question:

Given a array of true and false values, provide a snippet of java code that sorts the array so that every false value precedes a true value in $$O(n)$$ time. Assume that the array has at least 1 value in it.

Will K.

Answer:

int i = 0; int j = array.length - 1; boolean temp; while (i != j) { if (array[i] && !array[j]) { temp = array[i]; array[i] = array[j]; array[j] = temp; } else if (array[i]) { j = j - 1; } else { i = i + 1; } } The above code utilizes a while loop, checking pairs of values beginning at the highest value and the lowest value and swapping them until $$i = j$$, at which point all the values have been swapped. This occurs in $$O(n)$$ time because every time the loop runs through, one operation is performed and at least one member of the array is placed into a sorted position.

Calculus

TutorMe

Question:

Knowing that the derivative of $$ln(x)$$ is $$\frac{1}{x}$$, show the following: $(\frac{d}{dx}e^x = e^x$)

Will K.

Answer:

Let us begin by calculating the derivative of $$ln(e^x)$$ with respect to x using what we know about logarithms. We begin by moving the exponent in front of the logarithm using the logarithm power rule $$log_b(a^m) = m*log_b(a)$$. This gives us $$x*ln(e)$$. Since the natural logarithm of e is 1, we are left with simply the derivative with respect to $$x$$ of $$x$$. This works out to be 1. Here's our result right now: $(\frac{d}{dx}(ln(e^x)) = 1$) So now we know that the derivative of $$ln(e^x)$$ with respect to x is 1, but we still haven't figured out what the derivative of $$e^x$$ is. We can also use the chain rule to solve this problem. Remember that the chain rule states that if $$y(x) = f(g(x))$$ then $$y'(x) = g'(x)*f'(g(x))$$. Thus, the derivative of $$ln(e^x)$$, in addition to being equivalent to 1, must also be equivalent to the derivative of $$e^x$$ multiplied by $$1/e^x$$. This might seem sudden to you, so let's unpack it further. In our use of the chain rule, $$f(x) = ln(x)$$ and $$g(x) = e^x$$. Thus, $$f(g(x)) = ln(e^x)$$, which is what we want to calculate the derivative of. By the chain rule, the derivative of this is $$g'(x)*f'(g(x))$$ -- that is, the derivative of $$e^x$$ with respect to $$x$$ multiplied by the derivative of $$ln(e^x)$$ with respect to $$e^x$$. We know that the derivative of the natural logarithm with respect to a quantity is equivalent to 1 over the quantity, so $$f'(g(x)) = 1/g(x) = 1/e^x$$. So we know our full derivative, remembering the result we got in the first section, is the following: $(\frac{d}{dx}(ln(e^x)) = \frac{d}{dx}(e^x) * \frac{1}{e^x} = 1$) Remember that we're trying to find the derivative of $$e^x$$ with respect to $$x$$. So let's set $$\frac{d}{dx}e^x = u$$, and try to solve for $$u$$ in the above equation. $(\frac{d}{dx}(ln(e^x)) = u * \frac{1}{e^x} = 1$) Let's try solving that last section for $$u$$: $(u = e^x$) And since $$\frac{d}{dx}e^x = u$$: $(\frac{d}{dx}e^x = e^x$)

Send a message explaining your

needs and Will will reply soon.

needs and Will will reply soon.

Contact Will

Ready now? Request a lesson.

Start Session

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 Session" 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.

Made in California

© 2018 TutorMe.com, Inc.