All of us learned how to multiply two numbers when we were kids. In case we have forgotten (😄), let’s look at how to multiply two numbers 19 and 95.
For a new user, the Linux environment is not as user-friendly as Windows. It would take some time to become familiar with the terminal and terminal commands. I remember myself struggling to even traverse through the directories and doing a google search for everything.
Here is a list of some basic Linux commands that would be useful for beginners.
A. To Create a File
touch file_name
For example, if we want to create a text file named mytext, then: touch mytext.txt
B. To Edit a File
nano file_name
After editing the file, use ctrl + x
to save the changes…
Introduction to Cache Memory
Majority of the modern-day computers have three levels of cache memories namely L1, L2, and L3 caches. Often, L1 and L2 caches reside on-chip while L3 cache resides off-chip. These cache memories play an important role in creating the illusion of having a fast main memory. But, why do they have to create such an illusion?
There has always been a significant gap between the performance of the CPU and the main memory, and as a result, the main memory has become a performance bottleneck. The rate at which CPU processes data is much higher than…
In the first two parts of the Bentley optimization series, we discussed the optimization rules related to Data Structures and Logics. This is the last part of this series where we will explore the remaining two categories: optimization rules related to Loops and Functions.
The idea of hoisting is to avoid recomputing the loop-invariant code inside the loop during each iteration. For example, let's have a look at the following code.
#include <math.h>
void scale(double *x, double *y, int n){
for(int i=0; i< n; i++){
y[i] = x[i] * exp(sqrt(M_PI/2));
}
}
The value of the expression exp(sqrt(M_PI/2)) is a…
In the first article of the Bentley Optimization Rules series, we listed down four categories of optimization rules namely, rules related to (1)Data Structures, (2)Logics, (3)Loops, and (4)Functions, and discussed the rules related to data structures in detail. This article is the second part of this series where we will be discussing the optimization rules related to Logics.
The idea of constant folding and propagation is to perform all the computations based on constants during compilation rather than during runtime. For example, look at the following code sample.
In the above example, the values of all variables are constants…
In his book “Writing Efficient Programs” published in 1982, Jon Louis Bentley outlined several rules for optimizing the code. In this article, we will discuss a new set of Bentley Rules adapted from his original work which focus on reducing the work (which is the total number of operations that need to be performed).
We can divide these rules into four categories: rules related to data structures, loops, logic, and functions.
The idea of packing is to store more than one data value in a machine word. For example, consider the date “18 September 2020”. If we store this date…
Matrix multiplication is a piece of cake for anybody in the field of Computer Science. How difficult can it be 😏? It is just a matter of creating 2D arrays, populating it with data, and finally a nested loop. You would be amazed to hear that how you implement the matrix multiplication has a significant impact on the elapsed time.
You can compile and run it using the following commands.
gcc -o matrix MatrixMultiplication.c
./martix
This is how the majority of us implement matrix multiplication. What changes can we make? Can we change the order of the nested loops…
Binary trees can be used to represent abstract data types such as dictionaries and ordered lists. However, when we insert elements in order, there is a high tendency that we end up with a degenerate data structure that performs poorly (eg. inserting 2,3,4,5,6,7,8 in order to a binary tree). That’s why we often use balanced tree structures that rearrange the tree structure as operations are carried out. Skip lists can be used as alternatives to balanced trees (they might even perform well depending on the constraints). …
I have been doing a lot of implementations in C language for my research over the past two years. I chose C over other languages because of the general notion that C code runs faster compared to other popular programming languages such as Java and Python. However, I myself did not do any experiments to confirm that claim even though I was always curious about how fast C is (or is C actually the fastest). Finally, I decided to run some experiments to compare the performance of C, Java, and Python. …
Hash tables are an effective way to implement dictionaries. Before diving straight to the topic of hash tables, having a grasp of the background/context would help us understand the concepts related to the hash table better.
A dictionary is an abstract data type used to store key-value pairs.
A simple dictionary → {key_1:value_1, key_2:value_2, ……., key_n:value_n}
Each key is associated with a single value. Let us build our entire discussion using a simple example.
Assume that you are the owner of a shop that sells all types of fruits and vegetables, and you want to create a list consisting of…
A Computer Science Research Student who loves to do Research, Write and Travel