Monthly Archives: August 2015

Sorting Algorithm : Insertion Sort

From this two video I tried to re learn and implement the algorithm with pseudo code.


Implemented Code in C:

2015-08-07 13_30_30-C__Users_User_Desktop_insertionsort.exe

Here ary[] means array 🙂


Harvard CS50 course:

GeeksForGeeks Algo Implement(Not Worked Yet):
Practice Problem:

CLRS Theory:

Simple Implementation of Insertion Sorting(Idea Sanfoundry):

It is helpful:

Time complexity of Insertion Sort:

  • Worst case complexity : O(n^2)
  • Best case complexity :    O(n)
  • Average case complextiy:  O(n^2)Reference:

How to calculate complexity there is a example available at the upper video “Lecture 7”

and there are some links

Here a good presentation about this sorting


For descending order I took help from:
Here they change the comparison value for descending at while loop condition

Another good website:

Time complexity of insertion sort when there are O(n) inversions?

For some theory revise this video is good:

URI Online Judge Solution | 1041 Coordinates of a Point

Here is the logic,  1041

If x!=0 and y==0 then it will be in the y asix and
If y!=0 and x==0 then it will be in the x axis

that means you have to understand if what the value is equivalent to 0 then it will be in that axis

And one thing = means assignment operator if x=y then if x=5 then y=5

and == means comparison operator if x==y then if x==4 and y==5 then x!=y so it will be false

and if x=5 and y=5 then x==y and it is true



and like this can do



Here in this code you have to think about the flow which normally starts from the 0 and the compiler starts punctuating the code from Zero 0.

logic flow can be start from 0 then can be happen through greater than or equal

It’s better to do in C/C++ main format

Bash For Loops



we can check at the end that loop is not working by this



Another examples can be c like styles:

Bash IF Else with for loop break and continue  have to practice later time 🙂


Here is the video all for loop explained beautifully


Bash Programming : Say user hello !

Take a name from user and say hello user! 😀


Bash Programming : Check typed name is a valid $USER or not

I tried it hardly….Here you have to maintain the syntax

echo expr ""Hello Name

and this conditional

if [ “foo” = “foo” ]; then
echo expression evaluated as true

or the same things can be written as

if[ “foo” = “foo” ]
echo expr "Hello !"

if..then..else in bash

if [ “zaki” = “live” ]
echo expr "True !"
else echo
expr “False!”

conditional with variables
if [ "$t1" = "t2" ]
expr “True”
expr “False”`
fi #you have to end with this if you started with if



Bash Programming : Multiplication

Here I tried this on ubuntu

To create the file

code type in the terminal:

save the file and close editing mode:

change the permission of this file:

to show the output


Bash Programming : Addition

Here I tried this on ubuntu

To create the file

code type in the terminal:

don’t give space after or before equal sign

save the file and close editing mode:

change the permission of this file:

to show the output

Shortcut method for addition or any other:
create a file with cat then type code from the below in one line

here 1 2 and 3 is variable is taking input from user and also giving teh output so we sue $ before them….it is the shortcut method

then just type

and you will get the addition of this variables