Sunday, July 31, 2016

C++: what is the difference between passing a reference and passing a pointer to a function?

Both are same in the kind of functionality they provide, they allow you to modify a variable of calling function.

Pointers store variable location and need special operators to access the content. References, on the other hand, also point to the same location but with a symbolic variable ('alias' of the original symbolic variable).

When we call a function with the original variable, a new copy of the variable is created and passed to the function. The references are introduced exactly to bypass the copy stage and pass the symbolic variable directly to the function.


The reason for the existence of references is that they are slightly more user friendly than the pointers. We can have normal expressions (without '*') and yet have pointer functionality.

References are even used when we do not want pointer functionality, i.e., we do not want to to change the variable in the called function. This is done by declaring the reference variable 'const'. The advantage is to avoid copy of the large objects.  

Thursday, July 28, 2016

While delivering presentation: how do I look at Notes?

Answer: Look at your notes in a deliberate manner and let the students know that you are consulting them.

After you finish a slide, look at your notes in a deliberate manner, don't glance surreptitiously at the notes as if you're trying to make it seem that you're not looking at or consulting notes.

It may seem long to you, but student's do not mind it. In fact, they get a breather to grasp the things explained at the previous slide.

Friday, July 15, 2016

Algorithm Analysis: How to calculate coefficients of asymptotic notation?


An algorithm with running time $f(n)$ is said to be $\theta(g(n))$ if the following holds:

$c_1g(n) \leq f(n) \leq c_2g(n)$ for all $n>n_0$ and some value of $c_1$ and $c_2$.

For example, $f(n)=\frac{n^2}{2}-3n$ is $\theta(n^n)$.

To prove this, we need to find at least one set of values for $n_0, c_1$ and $c_2$ that satisfies above inequality. Below is a simple procedure to do that:
  1. To calculate $c_1$, obtain a value of n for which $f(n)$ is positive and solve left side inequality with that value of $n$.
    • $n_0=7$ and $c_1\leq1/14$
  2.  To calculate $c_2$, just put $n=1$ and solve the right side inequality.
    • $n_0=1$ and $c_2=1/2$
The basic idea is to make sure that $c_1$ and $c_2$ are positive.




How to add LaTex (math symbols) on blogger.com?

To write equations on blogger.com using LaTex, you need to add a java script to the template. Follow the steps below to add the script.
  1. Click on the Blog (not Post) you want to add equations to.
  2. Find "Template" on right side panel and click it.
  3. Click on "Edit HTML".
  4. Search for <head> and paste the following text just below <head>:
  5. Save it and add latex math code in-between two dollar signs ($\$$latex$\$$) as follows:
    • Einstein's most famous equation is $\$E=mc^2\$$
  6. It will appear as: 
    • Einstein's most famous equation is $E=mc^2$