I had Ubuntu 12.04 and Windows 7 running in my system and Ubuntu 12.04 got Crashed .I tried debugging it but couldnt succeed.

I decided to do a fresh install of latest version of Ubuntu and that was Ubuntu 14.04. I created a live USB and installed it in my system .

Installation was quick and easy. But , since i created a new Ubuntu install rather than overridding the existing one , Only 9 GB of space was left with me in the system Where ubuntu 14.04 got installed.

I had access to Ubuntu 12.04 Files as a separate drive, which i doesnt needed. I was looking for some application like Disk Management in windows which would help me to resize my partitions and i edned up with Gparted.

It looked pretty complex stuff for me to delete the partition and free up the space . Luckily , dual boot helped me to do it via Disk Management utitility in windows. I had free space ready with me .

Follow the steps below

1. Open Gparted and authorize it.
2. Right click on the partition which you want to increase
3. Select Resize/Move
4. Enter correct value in New size (It should be less then total unallocated space)
5. Click on start button to complete the action.

I was trying to resize my ubuntu 14.04 partion space using Gparted , where i deleted a partition which had my previous ubuntu install.

Unfortunately, the grub was loading from that partition and after my restart the computer went to the promt with grub rescue menu.

If you face the simillar situation , you can recover your OS grub loader as below.

This link was really helpful for me to boot my ubuntu installation .
http://askubuntu.com/questions/493826/grub-rescue-problem-after-deleting-ubuntu-partitionhttp://askubuntu.com/questions/493826/grub-rescue-problem-after-deleting-ubuntu-partition

Follow the steps given by Amr Amyan.

For me the commands were

set root=(hd0,msdos6)
set prefix=(hd0,msdos6)/boot/grub
insmod normal
normal

where msmod6 is the partition where ubuntu resides. That can be found by ls command .
Try ls(hd0,msdosX) and hit enter. you should be a valid partition . (ext2 partition)

But its not the end. You have just booted up the OS. When you restart you will be back to your grub rescue menu.

So here we have 2 options.

1. Using Live CD or Live USB
2. Using Existing Ubuntu

Since my Ubuntu 14.04 got booted up , i installed boot-repair from terminal by following these commands

sudo add-apt-repository ppa:kranich/cubuntu
sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair

Once its done , open boot repair and select “Recommended Repair” Menu . System will recover Grub and give you a link as well.
NOte down the link and restart your computer.

Bingo !!!!

Even after boot repair you are not getting the boot menu, paste the link to the corresponding email id. Ubuntu support team will help you out !!!.

For developing applications in Django, i needed a good IDE for writing code in python and Pycharm is the IDE that works like a charm.

I downloaded the pycharm tar ball package from here.

Download Pycharm from here

and extract the package as

tar xvf Pycharm*.tar.gz

You got the package untarred but, we gotta check one more stuff.

Pycharm will look for JAVA HOME . Check if java is installed .

java -version

if not , install it with

sudo apt-get install default-jre

And run the pycharm.sh script from bin folder.

Am completely new to python and Django . Today i made an attempt of installing Django in my ubuntu 14.04 system.

The OS is fresh installed, just did 4 days back . Django is going to be my first package installation.

I went with the Official Documentation given below

Official Documentation for Django Installation

As given in the link , there are 3 major steps.

1. Check if python is already installed in your computer.

I did by typing

python –version in my terminal and i got answer as Python 2.7.6.

Hence, i proceeded to step 2 .

2. Remove any previous versions of Django if installed.

sudo rm -rf /usr/lib/python2.7/dist-packages/django

You have to run this command to remove the previous version. Change the python version accordingly in the command

If you skip this step you might be getting an error as given below

OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/django'

I tried installing Django Directly using pip which gave me this error . And i visited the following URL for the solution.

Solution for OS Error

3. Install Django.

In ubuntu 14.04 LTS i didnt have pip installed in prior. Hence i had to install that first. That can be done by

sudo apt-get install python-pip

and then you can install Django by typing this command

sudo pip install Django==1.8.1

Django installed successfully.

To verify open the python prompt by typing python in the terminal and use the following commands to see Django version

>>> import django
>>> print(django.get_version())

insertionSortCard

Best example of insertion sort is sorting deck of cards. .. As you see in the figure, say we have 2,4,5 10 and 7 clubs in our hand and we have to sort it .
As we know, we will take 7 clubs and place it between 5 and 10 clubs. Hence, for each card we need to swap the cards before it and place the key card in place .

 

Before the analysis , lets have a look at pseudo code of insertion sort. For input array A

 


INSERTION-SORT(A)

for j <-- 2 to length [A]

do key <-- A[j]

i <-- j - 1

while i > 0 and A[i] > key

do A[i + i] <-- A[i]

i <-- i - 1

A[i + 1] <-- key

&nbsp;

 

I tried implementing the same in C++. Here is the code

 

 

#include <iostream>

using namespace std;

int main()
{
int arr[] = {5,2,4,6,1,3};
int arrSize =  sizeof(arr)/sizeof(arr[0]);
int key;
int i;
for(int j=1; j<arrSize; j++)
{
        key = arr[j];
        i = j - 1;
        while(i >= 0 && arr[i] > key)
        {
                arr[i+1] = arr[i];
                i = i - 1;
        }   

        arr[i+1] = key;

}

for(int i=0; i<arrSize; i++)
cout << arr[i] << " " << endl;
return 0;
}

Output is :

insertionSortOutput

Before we start our analysis of the insertion sort, we will see how many times each statement runs.

 


INSERTION-SORT(A)

for j <-- 2 to length [A] ----------------------------  runs n times

do key <-- A[j] --------------------------------------  runs n-1 times

i <-- j - 1     --------------------------------------  runs n-1 times
                                                       n
while i > 0 and A[i] > key --------------------------- ∑ tj
                                                       j=2
                                                       n
do A[i + i] <-- A[i]  -------------------------------- ∑ tj - 1
                                                       j=2

                                                       n
i <-- i - 1 ------------------------------------------ ∑ tj - 1
                                                       j=2
A[i + 1] <-- key ------------------------------------- n-1

&nbsp;

Now, lets get into the analysis part.
Okay, In each statement , we do some operations as well i.e – increment, decrement, counter — all those are considered to be constants. Hence we name constants from c1 to c7
And also, tj is the function which does while loop operation .
If the input is already sorted, there would be no in-swapping takes place. i.e. While loop will never be executed. Since while loop is inside FOR loop which runs from 2 to n , we enclose it with sigma j = 2 to n.
Hence the equation would be
What could be the Best case ?? — A sorted input
and what could be the worst case input . — Input sequence in reverse order.

 

These 3 screenshots will explain how insertion sort is O(n) in best case and O(n square) in worst case. 

 

 

BestCase

insertion_sort

worst case

 

This you tube video will be helpful to understand the same

https://www.youtube.com/watch?v=yXwFrc5GS6A — click the view the video 

 

Learning Year – 2014 !!!!

Posted: December 31, 2014 in Uncategorized

Started of the year with lot of resolutions ….. 

 

resolution

Speed Cubing

rubiks

In Feb, i entered into a new world called speedcubing. Never heard it before. Never solved a rubik cube before. Feb 18, 2014 was a start. Initially, i just started off with “how to solve rubik cube” video in you tube. When i started practicing it , things started to be serious and fun as well.
badmephisto.com- took me from 8 minutes to 28 seconds. Thanks and salute to badmephisto.

 

How to Solve Rubik’s Cube Blindfolded

blindfold

 

 Everytime, when i see a blindfolded solve in internet , it always looked like a magic. I thought , i would never make it. But, this link made me understand that i was wrong. Memos, formulas and other stuff .. Ufff.. Nov 18, 2014 i got my first rubik blindfold solve.

Coursera 

mooc

 

One of the interesting medium to learn about softwares and related stuff is coursera. Enrolled in many courses , but didnt finish even one with certificate :P.
however, it was a very good learning experience . R programming was new to me. STarted with the basics of data analytics and also some python stuff.

 

Jquery

jquery

Everytime when i take javascript , i could not move more than 5 pages in book . Jquery changed that interest. Started watching my favorite programmer – Alex’s video in youtube for jquery and completed till 40/200. It was a wonderful start for basics and was very helpful while programming front end stuffs.

 

Project Euler Problems

 

projecteuler

 In early december, moved back to that old black console (c++) and started solving problems on project euler. Initially , the problems were easier and simillar. But, when i moved on things were getting complex and there were lot of Project Euler Problemsthinking and learning involved. Got more ideas on sieves, searching, sorting, dynamics and other stuff. solved 50 problems on it and ranked less than 500 in india out of 8k odd people.

 

Creating Android App

  android

 

Is that very difficult to create an android app ? Wanted an alarm and remainder app in my own way. And i designed it with online help.

 Learn German

 

germasn

 

 

 Duolingo made it as a routine and learnt it for 30 days . Few words in German got set into my mind .

Chess Cube 

chesscube

One more addictive website.. chesscube.. Hmmm.. what to say.. Restricted myself to one game a day.. Very interesting to play with unknown persons. But, it eats lot of time. Also, went thro some videos of Akobian (French Defense, Ruy Lopez) just to maintain my cubits in chesscube. and also used chess android app level 4. 4/12 was too low .. but i wanted to play level 4 until i gain good confidence on it.

Blogging  

blog

And at last, blogging.. Couldn’t post much.. Thats gonna be my new year resolution. Will try to share as much as i can . !!!

 

newyear

Happy Learning !!!

On an occasion i had a file with words listed one by one and i wanted to sort the file in lexicographic order. Since i work in linux machines , its just 1 command . `cat filename | sort ` to sort it in lexicographic order. But i wanted to do it in c++.  I tried googling for suggestions and found out that radix and bucket sort would help me out. And then i tried implementing the concept of Radix MSD to arrive the result. Sharing the code. I have added inline comments in the program. Hope it helps  (Note: i just wanted to arrive with the solution.. Not much concerned about efficiency of the program :-))

#include <iostream>
#include <map>
#include <vector>
#include <fstream>

using namespace std;

int main()
{

	vector<string> words;

	map<char,vector<string> > bucket;
	map<char,vector<string> > ::iterator it;
	bucket.clear();
	vector<string> tempVec;

	// initializing map with null vector and empty for variable length string
	bucket[' '] = tempVec;
	char ch;
	//for(int i=97; i<123; i++)
	for(int i=65; i<91; i++)
	{
		ch = i;
		bucket[ch] = tempVec;
	}

	words.push_back("jump");
	words.push_back("sit");
	words.push_back("carry");
	words.push_back("run");
	words.push_back("site");
	words.push_back("runner");


	/*cout << "init" << endl;
	  for(int k=0; k<words.size(); k++)
	  cout << words[k] << "  ";
	  cout << endl;*/

	// finding the maximum character
	int max = 0;
	for(int i=0; i<words.size(); i++)
	{
		max = (max > words[i].length())?max:words[i].length();
	}

	// loop from max char till first char 
	for(int i=max-1; i>=0; i--)
	{
		//cout << "Running for Phase " << i << endl;
		// loop through the entire vector
		for(int j=0; j<words.size(); j++)
		{
			string word = words[j];
			int temp_len = word.length();
			// there may be possibility that word boundary is less than max
			if(temp_len < i)
			{
				// push into the "" bucket
				//cout << "Pushing " << word << " into bucket " << "[empty]" << endl;
				bucket[' '].push_back(word);
			}
			else
			{
				// index exists .. Hence check the char
				char temp_char;
				temp_char = word[i];

				// insert into map with temp_char, word
				bucket[temp_char].push_back(word);	
				//cout << "Pushing " << word << " into bucket " << temp_char << endl;

			}


		}
		// end of this loop, all the words are inserted into corresponding buckets
		// clear the input vector -- because we are going to change the order
		words.clear();

		// iterate through the keys and write the order into input vector
		for(it=bucket.begin(); it!=bucket.end(); it++)
		{
			tempVec = it->second;
			for(int k=0; k<tempVec.size(); k++)
				words.push_back(tempVec[k]);

			tempVec.clear();
		}

		/*cout << "After bucket insertion words are  " << endl;
		  for(int k=0; k<words.size(); k++)
		  cout << words[k] << "  ";
		  cout << endl;
		 */


		// now we have the correct order of the phase .. hence clear the bucket
		tempVec.clear();
		for(it=bucket.begin(); it!=bucket.end(); it++)
		{
			it->second.clear();
		}

		//cout << endl;


	}
	cout << "Answer is " << endl;
	for(int k=0; k<words.size(); k++)
		cout << words[k] << endl;


	return 0;
}

[ALGORITHM]
1. Read the words and push into vector
2. find the max value by iterating the vector and finding length of all words
3. Iterate from max to 0
4. take each words first letter and push into corresponding bucket
5. Iterate through the buckets and save it as input word list order
6. After 0th Iteration , input vector will have the result.

[EXPLANATION]

step – 1
words pushed into vector

jump, sit, carry, run, site , runner

step – 2

finding the maximum length string
it would be runner – 6

step – 3

Iterating from index 5 to 0

ITERATION – 5 :
Note : if the word length is less than index , we need to push in empty bucket(‘ ‘)

‘ ‘ – jump,sit,carry,run,site
r – runner

Hence, array order will be – jump, sit, carry, run, site

ITERATION – 4 :

4th index of the words carry and runner are [y] and [e]

‘ ‘ – jump, sit, run, site
e – runner
y – carry

Hence, array order will be – jump, sit, run, site, runner, carry

ITERATION – 3 :

3rd index for the words jump, carry, site, runner [p],[r],[e],[n]

‘ ‘ – sit, run
e – site
n – runner
p – jump
r – carry

Hence array would be sit, run, site, runner, jump, carry

ITERATION – 2 :

2nd index for the words sit, run , site, runner, jump, carry are [t],[n],[t],[n],[m], [r]

m – jump
n – run, runner
r – carry
t – sit, site

Hence array would be jump, run, runner, carry, sit, site

ITERATION – 1

1st index for the words jump, run, runner, carry, sit, site are [u],[u],[u],[a],[i],[i]
a – carry
i – sit , site
u – jump, run, runner

Hence array would be , carry, sit, site , jump, run, runner

ITERATION – 0

0th index of the words are [c], [s], [s], [j], [r], [r]

c – carry
s – sit, site
j – jump
r – run, runner

Hence OUPUT : carry, sit , site , jump, run, runner