Pseudocode, and Performance Analysis

Pseudocode

Algorithm is a set of instructions written before the actual code is produced. A code is not the identical representation of the algorithm. It comes in the form of instructions which indeed resembles a programming language. It is known as the pseudocode. For an example let’s look at the pseudocode of linear search:

Algorithm linearSearch(A, n, t) 
// A is an array of size n, and t is the key to find
{
      for i:= 0 to n-1 do {
            if(A[i] := t)then
                  break;
      }
      if(i>n)then
         return -1;
      else
         return i;
}

The above pseudocode shows that a target value (t) is searched through an array (A) of size n.

Performance Analysis

The designed algorithm should be able to answer few questions, such as,

  • Does it solve the problem?
  • Cost of the solution in terms of time, and space.

In this discussion I will solely emphasize on the time, and space complexity.

Time Complexity

We can define time complexity of an algorithm is so many different ways, but in a few words, it is determined by the steps it takes to compute the function. In the above example we see that there is one iteration cycle to search through an array of size n. If we represent this in a form of asymptotic notation, it is O(n) the time complexity of this algorithm. It means that, for a data set of size n, it will iterate n times.

Space Complexity

Space complexity depends on the amount of space an algorithm needs to accomplish the computation. If an algorithm needs a fixed amount of memory to compute a task then the space complexity of that algorithm is constant, Sp = O(1). On the other hand, ignoring the constant variables we find that, the input size is n in the above mentioned pseudocode. And the algorithm is iterating till the last value of n; therefore, the space complexity of this algorithm is, Sp = O(n).

Now, if we want to make it a precise calculation then we have to take the constant parts into consideration. Each variable needs 2 bytes space in the memory. After calculating both constant, and auxiliary parts we get,

2*n bytes for the array A[] 
2 bytes for the variable i
2 bytes for the return keyword
Therefore, it will take (2n + 4) bytes memory for the algorithm to 
complete its execution.

 

Git Cheat Sheet

A set of selected git commands which are used almost on a daily basis. The commands are taken from the github official documentation.

Note: [] = only the content without [] ; “[]” = content inside “”

Configuration:


 

> git config –global user.name “[name]”
> git config –global user.email “[email address]”

Local Repository Creation:


> git init [project-name]
> git clone [url]

Before & During the push:


> git add [file]
> git commit -m “message”

Grouping:


> git branch
> git branch [branch-name]
> git checkout [branch-name]
> git merge [branch]
> git branch -d [branch-name]  // deleting a branch

Review History:


> git log

Redo Commits:


> git reset [commit]   // commit no. from the git log
> git reset –hard [commit]

Save Fragments:


> git stash
> git stash drop

Synchronization:


> git push [alias] [branch]  // pushes the changes from local to the remote repository
> git pull  // updates the local repository
> git merge [bookmark]/[branch]

Suppress Tracking:


.gitignore file holds the following command to avoid temporary files, and paths:

*.log
build/
temp-*
lists of all ignored files: git ls-files –other –ignored –exclude-standard
 my git profile: my git

reference: github cheat sheet

Welcome Message

“Architecture before Artifact”

Hi, welcome to my blog. I am  a software developer, and a data science enthusiast. This is my experience, and knowledge sharing blog on programming, software development, and so on. To be clear, I am blogging to remember the stuff that I need for my job, and if anyone is eventually helped by it, then he is welcome.

My book on software engineering has been released lately. It is named, “SOA into Micro service and integration of the changes”, ISBN: 978-3-330-00366-8