Vivek S.

Graduate from BITS Pilani, Pilani Campus; SDE at Edgeverve Systems

Tutor Satisfaction Guarantee

Physics

TutorMe

Question:

Why and how does a cricket ball swing in mid air?

Vivek S.

Answer:

This can be attributed to Bernoulli' Principle. Bernoulli's Principle states that for an ideal fluid (low speed air is a good approximation), with no work being performed on it, an increase in velocity occurs simultaneously with decrease in pressure or a change in the fluid's gravitational potential energy. A cricket ball has typically a rough side and a shiny side, after few overs of play. When a bowler throws balls with vertical seam, the rough side slows down the air due to friction whereas the smoother side allows the air to pass by at a greater speed. According to Bernoulli's principle, greater the air speed, lesser the pressure. So there is a pressure differential that pushes the ball in the direction of the smoother side.(Since, fluids move from high pressure to low pressure). Hence, we see the famous mid air swing from Bowlers all over the world.

Computer Science (General)

TutorMe

Question:

Find the nth largest element in an array of unsorted elements.

Vivek S.

Answer:

There are several ways to solve this question.For all the below algorithms, we will use the following array A={ 5, 2, 7 , 9 , 1, 8 } with length m=6 and n =2 1. Find the largest element in array by searching linearly and remove it from array. Do it n times. The last removed element is the answer. Complexity = O(m*n) In our example, 9 is removed first. Then, 8. 8 is the answer. 2. Sort the array A and return A[m-n]. Complexity = O(mlog(m))..better than solution 1. In our example, after sorting A= {1, 2, 5, 7, 8, 9} so, answer is A[6-2]=A[4]=8 3. My most favorite solution, born out of the idea that 'to get nth largest element, we don't need the whole array to be sorted. In fact, sorting the whole array is completely unnecessary if we only need one element from it. We only need elements before nth greatest element to be lesser than it irrespective of it's order' Here's the algorithm: Select the last number in array. Now traverse the whole array counting all elements greater than the last number and arranging elements finally such that elements less than last element are to its left and elements greater than it are to its right.( There are more subtleties involved in actually coding the algorithm, or writing the complete pseudo code for it. Here I am just giving very introductory idea) if total count=n-1, this last element is the answer. if total count>n-1, repeat the procedure for element to its right. Update n accordingly if total count<n-1, repeat the procedure for element to its left. Update n accordingly In our example, After first iteration...A={5, 2, 1, 7 , 8 , 9} Since, count==1 which is n-1. Hence the last element=8 is the answer This is the famous quickselect algorithm. Complexity : Avg case = O(m). Worst case(O(n*n)

Statistics

TutorMe

Question:

Suppose, a function random5() generates random integers from 1 to 5 with equal probability. Create a function random7() which generates random integers from 1 to 7 with equal probability.

Vivek S.

Answer:

For a lot of people, the first instinct is to say, random7() = random5() * 7/5. But is this correct? Let's see... for all possible outputs of random5()....(i.e. 1,2,3,4,5), the outputs of random7() will be : 1.4 2.8 4.2 5.6 7 Clearly it will only generate 5 different types of output with equal probabilty, but random7() should 7 different outputs from 1 to 7. Therefore, this definition of random7() is incorrect. We just have to focus on getting all integers from 1 to 7,or maybe a multiple of 7 (since, we saw above, a multiple of 7 random generator will generate only 7 different output.) Notice below the different outputs generated: random5()* 5 ={ 5,10,15,20,25 }....A random5() = { 1,2,3,4,5 } ...............B If we add A and B, A+B = { all integers from 6 to 30} ^^^This is because, say an output of A is 5, and output of B is 1, so A+B is 6. Similarly for each combination of sums from A and B, we will get A+B = { all integers from 6 to 30}..This is possile only because random5() generates this integer with equal probaiblity. Notice that we are making two separate calls to random5(), hence we get two different values for A and B. So, if we do A+B-5, we get {all integers from 1 to 25} Now we have all information required for generating 1 to 7. Look below: random7() { A =random5() * 5 B=random5() if(A+B-5 > 21) random7(); else return (A+B-5)%7 + 1 } Here, if A+B-5 is less than 22(i.e 1 to 21), we can simply take modulus,as this will give integers 1 to 7 with equal probability(after adding 1). If A+B-5 is greater than 21, we will discard the value we have and again call random7(). This ensures we get each integer from 1 to 7 with equal probability. As you may have noticed, this is a recursive solution.

Send a message explaining your

needs and Vivek will reply soon.

needs and Vivek will reply soon.

Contact Vivek

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.