Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Shrikant S.
Computer Science Undergraduate at BITS Pilani
Tutor Satisfaction Guarantee
Machine Learning
TutorMe
Question:

Why is it that Random Forest has a better performance in general as compared to a single Decision Tree?

Shrikant S.
Answer:

Random Forest is a special case of ensemble classifier where all the classifiers are Decision Trees. A point to be noted here is that ensemble classifiers show performance improvements majorly when the classifiers are unstable. Decision trees are unstable classifiers in the sense that a very minor change in training data can drastically alter a Decision Tree. Random Forest uses a number of Decision Trees and reports the class that is classified the highest number of times by the trees making the forest. However, the trick lies in the fact that the trees in the forest are created by random sampling of data. So each tree is different from the other as explained earlier regarding the instability of decision trees. Hence, each tree captures a different kind of relationship among the input data. And the relationships that feature the most within the randomly sampled data have a higher weightage in the final output. Hence, it is also possible at times to get more nuanced relationships which wouldn't be identified by a single decision tree. Also, decision trees are prone to overfitting. However, since each tree in a random forest is built using a different set of data, the averaging effect of considering many trees to get the final output also tends to reduce the chances of the model suffering from overfitting.

Computer Science (General)
TutorMe
Question:

Why are Computer Science algorithms always judged on the basis of their worst case time complexity?

Shrikant S.
Answer:

The prevalent thought that algorithms are judged on the basis of their worst case time complexities is not entirely true. Each algorithm's time complexity can be categorised into three types: best case, average case, worst case. Now these complexities do depend on the structure and flow of the algorithm. But they also sometimes depend on the arrangement in which the data is input to the algorithm. Many a times, you may find that the worst case and the average case complexities are the same. It may also be possible that another algorithm might have different average and worst case complexities. And this would be the case for solving the same problem with different arrangement of input data. However, most of the times, we assume that we don't have any information about the kind of data that is input, and hence we are not able to deterministically decide whether choosing average case complexity would be of benefit. Our reporting may go way off the mark if the input data makes the time complexity more higher. Hence, we report the worst case time complexity to be on the safer side of calculations.

C Programming
TutorMe
Question:

In C programming, while writing a function to add a node to a linked list, why do we pass a pointer to the head pointer of the list instead of just the pointer to the head as an argument?

Shrikant S.
Answer:

To understand this, you must first understand what pass by value and pass by reference means with respect to arguments to a function. By definition, in C, arguments are always passed by value to a function. This means that each function has its own temporary memory in the RAM where a temporary variable is created and then deleted at the end of function execution. So if you call a dummy function as follows: void dummy(int a) { a = a + 2; printf("%d\n", a); } int main() { int x = 2; dummy(x); printf("%d\n", x); return 0; } The output for this code would be: 4 2 The compiler creates a temporary variable 'a' for the period of execution of dummy() function and assigns it a value of 2 at function call. All manipulations to 'a' take place locally and are valid only inside the function execution. After the function execution is complete, it deletes the space allocated to the temporary variable 'a'. Hence, when we print the value in 'x' after calling dummy() on 'x', it prints 2 instead of 4 since the value 2 was assigned to temporary variable without actually changing the value stored in 'x'. Hence, when you want to retain the changes to a variable inside a function, you pass a pointer to the variable as a work around to the feature of passing by value. Take the following code by example: void dummy2(int *a) { *a = *a + 2; printf("%d\n", *a); } int main() { int x = 2; dummy(&x); printf("%d\n", x); return 0; } The output for this code would be: 4 4 What happens is that the address of 'x' is stored in the temporary variable 'a'. Now, we manipulate the value at the address of 'a' and not the value in 'a'. Hence, this manipulation is reflected in the memory location pointed to by 'a' which is actually the memory location of 'x'. Thus, the changes in x will be reflected even after the execution of the function completes. We use this smart technique to add a node to the head of a linked list. Hence, we pass a pointer to the pointer instead of passing just the pointer straightaway since the address stored in the head pointer gets changed to the address of the new node and hence must be reflected even after the execution of the function to add a node.

Send a message explaining your
needs and Shrikant will reply soon.
Contact Shrikant
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.