Thursday, November 27, 2014

Relationships of these days

If two people are happy together, just leave them alone.
But this is not the case that happened in my life. In my situation, there were some spoilers of my relationship, and the most worst thing is that the male person involved in the relationship is easily brain-washed by these spoilers.
The relationship breaks.
I think that is why our traditional Indian society was highly dependent on arranged marriages. Women, like me, these days are interested in living the life to the fullest of their wish, whatever it may be.
The same above situation happened in my life in Singapore and i found myself emotionally devastated. Then on , I started working on my EQ and Android.
Ahem...Ahem...ofcourse, u r right. Y r u reading it again? Yes, I have mentioned two irrelevant features simply in a single statement to confuse everyone.
But yes, its true, I started to work on my EQ.

Opportunity will knock the door only once. But in my case, opportunity came like a giant snake like the one shown in "The New Alcatraz". It broke my door into pieces, gulped me fast and I was inside its belly in no time.

Suddenly, someone came with a knife and killed this Alcatraz, and I came out of this oportunity, but i found myself in a strange country called Singapore.This opportunity which came in the form of Alcatraz, left me stranded in the streets of Singapore with a bunch of people like me on the roads.

Then...............
My Mum: Papa ! Papa! Wake up!!! Collegeku poriya illaiya? Time aachu paar...
Me: (Yawning) Pooooooooooogureeeeeeeaaaaaaaan ma.

All the dreams suddenly disappeared from my mind and i went to brush my teeth.
Good night people!
Have beautiful nightmares!!

Saturday, November 22, 2014

Wednesday, November 12, 2014

Sorting Part--6 HeapSort REFERNCE PANIMALAR ENGINEERING COLLEGE NOTES

HEAP SORT

In heap sort the array is interpreted as a complete binary tree. This method has two phases.

Phase 1 : Binary heap is constructed.
Phase 2 : Deletemin or Deletemax routine is performed for sorting.

Phase 1: Two properties of a binary heap namely structure property and heap order property are achieved.

Phase 2: The array elements are sorted using deletemin operation, which gives the elements arranged in descending order.

the array elements are sorted using deletemax operation, which gives the elements arranged in ascending order.

Algorithm

#define leftchild(i) (2*(i)+1)

void PercDown (ElementType A[], int N)
{
int child;
ElementType tmp;
for ( tmp = A[i]; leftchild (i){
child = leftchild(i);
if(child!=N-1 && A[child+1] > A[child])
child++;
if(tmpA[i]=A[child];
else
break;
}
A[i]=temp;
}

void HeapSort (ElementType A[], int N)
{
int I;
for(i=N/2;i>=0;i--)
PercDown(A,i,N);
for(i=N-1;i>0;i--)
{
Swap(&A[0], &A[i]);
PercDown(A,0,i);
}
}

Analysis of Heap Sort

Worst Case Analysis              - O(N log N)
Best Case Analysis                 - O(N log N)
Average Case Analysis           - O(N log N)

Advantages of Heap Sort

It is efficient for sorting large number of elements.
It has the advantage of Worst Case O(N log N) running time.

Limitations

It is not a stable sort.
It requires more processing time.

Example:

Input : 25, 73, 10, 95, 68, 82, 22, 60

Step 1: Build Heap routine execution to derive a MaxHeap structure




Step 2: Delete Max routine to derive a sorted list :


Tuesday, November 11, 2014

SOME SIMPLE SOURCE CODES THAT I DEVELOPED IN C#.NET AFTER REFERRING FEW BOOKS FEEL FREE TO POINT OUT ERRORS IF ANY

SOURCE CODE #1
using System;
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello C#");
        }
    }

OUTPUT OF SOURCE CODE #1



SOURCE CODE #2:
using System;
namespace ConsoleApplication2
{
    public class Fraction
    {
        public Fraction(int numerator, int denominator)
        {
            this.numerator = numerator;
            this.denominator = denominator;
        }
        public void Add(Fraction rhs)   
        {
            if(rhs.denominator != this.denominator)
            {
                throw new ArgumentException("Denominators must match");
            }
            //return new Fraction(this.numerator+rhs.numerator, this.denominator);
            Console.WriteLine("The sum of the two fractions is " + (this.numerator + rhs.numerator) + " / " + this.denominator);
        }
        public override string ToString()
        {
            return numerator + "/" + denominator;
        }
        private int numerator;
        private int denominator;
        public static void Main (String []args)
        {
            Fraction frac = new Fraction(2,3);
            Fraction frac1 = new Fraction(4,3);
            frac1.Add(frac);
        }
    }
}

OUTPUT FOR SOURCE CODE #2:




Monday, November 10, 2014

Quick Sort (Part- 4)

REFERENCE : PANIMALAR ENGINEERING COLLEGE NOTES
Quick Sort:
Quick sort is one of the most efficient internal sorting technique. It possess a very good average behavior among all the sorting techniques. It is also called as partitioning sort which uses divide and conquer techniques.
                The quick sort works by partitioning the array A[1], A[2]. . . A[N] by picking some key value in the array as a pivot element.Pivot element is used to rearrange the elements in a array. Pivot element can be the first element of an array and the rest of the elements are moved so that elements on left side of the pivot are lesser than the pivot, whereas those on the right sie are greater than the pivot. Now the pivot element is placed in the correct position. Now the quick sort procedure is applied for left array and right array in a recursive manner.

void qsort (int A[ ] , int left, int right)
{
int i,j, temp, pivot;
if(left{
pivot = left;
i = left + 1;
j = right;
while(i{
while(A[pivot]>=A[j])
i++;
while(A[pivot]j--;
if(i{
temp=A[j];
A[i]=A[j];
A[j]=temp;
}
}
temp = A[pivot];
A[pivot] = A[j];
A[j]=temp;
qsort(A,left,j-1);
qsort(A,j+1,right);
}
}

Example: Consider an unsorted array as follows40         20         70          14          60           61            97          30Here pivot = 40

40      20      70      14      60      61      97      30

40      20      70      14      60      61      97      30


40      20      30      14      60      61      97      70

Pass 1:

14      20      30      40      60      61      97      70

Now the pivot element reached its correct position. The elements lesser than pivot {14     20       30} is considered as left sub array. The elements than the pivot { 60     61     97     70} is considered as right sub array. Then the Qsort procedure is applied recursively for both these arrays.

Analysis of Quick Sort

Worst Case Analysis                 - O(N2)
Best Case Analysis                   - O (N log N)
Average Case Analysis              - O (N log N)

Advantages of Quick Sort

It is faster than other O(N log N) algorithms.
It has better cache performance.

Limitations

It requires extra memory space.
It requires more processing time.

Merge Sort Part- 3 REFERENCE : PANIMALAR ENGINEERING COLLEGE NOTES

The most common algorithm used is the merge sort. This algorithm follows divide and conquer strategy. In dividing phase the problem is divided into smaller problem and solved recursively.In conquering phase, the partitioned array is merged together recursively. Merge sort is applied to the first half and second half of the array. This gives two sorted halves which can then be recursively merged together using the merging algorithm.
The basic merging algorithm takes two input arrays A and B and an output array C. The first element of A array and B array are compared, then the smaller element is stored in the output array C and the corresponding pointer is increment. When either input array is exhausted the remainder of the other array is copied to an output array C.

void MSort (ElementType A[ ] , ElementType TmpArray[ ] , int left, int right)
{
int center;
if(left{
center = (left + right) / 2;
msort(A, TmpArray, left,center);
msort(A,TmpArray, center+1,right);
merge(A, TmpArray, left, center+1, right);
}
}

void merge(int A[ ], int TmpArray[ ], int lpos, int rpos, int rightend)
{
int i, num, leftend, tmpos;
leftend = rpos - 1;
tmpos = lpos;
num = rightend - lpos + 1;
while(lpos<=leftend) &&(rpos<=rightend)
if(A[lpos]<=A[rpos])
TmpArray[tmpos++]=A[lpos++];
else
TmpArray[tmpos++]=A[rpos++];
while(lpos<=leftend)
TmpArray[tmpos++]=A[lpos++];
while(rpos<=rightend)
TmpArray[tmpos++] = A[rpos++];
for(i=0;i<=num; i++, rightend--)
A[rightend]=TmpArray[rightend];
}

void MergeSort(ElementType A[ ], int N)
{
ElementType TmpArray[MAX];
MSort (A,TmpArray,0,N-1)
}

The merge sort algorithm is therefore easy to describe. If N-1, there is only one element to sort and the answer is at hand. Otherwise, recursively merge sort the first half and second half. This gives two sorted halves, which can then be merged together using merging algorithm.

For example to sort the eight element array 24, 23, 26, 1, 2, 27, 38, 15. We recursively sort the first four and the last four elements, obtaining 1, 13, 14, 26, 2, 15, 27, 38. Then we merge the two halves as above, obtaining the final list 1, 2, 13, 15, 24, 26, 27, 38.


Analysis of Merge Sort

                   Worst Case Analysis       --  O(NlogN)
                    Best Case Analysis         -- O(NlogN)
                    Average Case Analysis   -- O(NlogN)

Advantages of Merge Sort
It is efficient for sorting large number of elements.
It is simple than Heap sort.
It has better cache performance.
It has the advantages of worst case O(NlogN) running time.

Limitations

It requires more memory space.
It requires more processing time.

Saturday, November 8, 2014

Data Structures ---- Sorting (Part - 2 Shell Sort)

Shell Sort

reference: PANIMALAR ENGINEERING COLLEGE NOTES
                 Shell sort was invented by Donald Shell. It improves upon bubble sort and insertion sort by moving out of order elements more than one position at a time.
                 In this sort the whole array is first fragment into K segments, where K is preferably a prime number. After first pass, the whole array is partially sorted. In the next pass, the value of K is reduced which increases the size of the segment and reduces the number of segments.
                 The next K value is chosen as relatively prime to its previous value. The process is repeated until k=1 at which the array is sorted. The insertion sort is applied to each segment, so each successive segment is partially sorted.The shell sort is also called as Diminishing Increment Sort, because the value of K decreases continuously.

Algorithm

void ShellSort (ElementType A[ ], int N)
{
int i,j,Increment;
ElementType temp;
for(Increment = N/2; Increment>0; Increment = Increment/2)
for(i=Increment;i{
temp=A[i];
for(j=i;j>=Increment;j=j-Increment)
if(tempA[j] = A[j- Increment];
else
break;
A[j] = temp;
}
}

Example

Consider an Unsorted array

81      94       11         96        12       35        17        95        28         58

Here N = 10, the first Pass as K = 5 (10/2)


After First Pass

35        17          11           28           12            81             94            95           96           58

In second pass, K is reduced to 3


After Second Pass

28        12         11           35           17                81               58            95             96            94

In third pass, K is reduced to 1


The final sorted array is

11           12          17          28          35            58            81           94            95           96

Analysis of Shell Sort

Worst Case Analysis                          - O(N2)
Best Case Analysis                             - O(N log N)
Average Case Analysis                       - O(N2)

Advantages of Shell Sort

It is one of the fastest algorithm for sorting small number of elements.

It requires relatively small amounts of memory.

(contd)

Friday, November 7, 2014

Data Structures --- Sorting (PART-1 INTRO + INSERTION SORT) REFERENCE: PANIMALAR ENGINEERING COLLEGE NOTES

A sorting algorithm is an algorithm that puts element of a list in a certain order (ascending or descending).

Sorting Algorithm are often classified by :

  • Computational complexity (worst, Average, Best cases) in the term of size of the list n.
                                             Best case     : O(nlogn)
                                              Worst case  : O(n2)
                                             Average case : O(n)

  • Memory utilizations
  • Number of comparisons
  • Method applied like Insertion, exchange, selection, merging etc.
Sorting techniques are categorized into

                                               Internal Sorting
                                               External Sorting
Internal Sorting takes place in the main memory of a computer

Example : Insertion sort, Bubble sort, Shell sort, Quick sort, Heap sort, Merge sort, Radix(Bucket) sort.

External Sorting takes place in the secondary memory of a computer.

Example: Multiway Merge, Poluphase Merge, Replacement Selection, 2-way Merge

INSERTION SORT

Insertion sorts work by taking elements from the list one by one and inserting them into their current position into a new sorted list. Insertion sort consists of N-1 passes, where N is the number of elements to be sorted.

In the insertion sort the element in the position P is saved in tmp and all larger elements prior to position P are moved one spot to the right. The tmp is placed in the correct spot.

Algorithm

void InsertionSort (ElementType A[], int B)
{
int j,P;
ElementType tmp;
for(P=i;P
{
Tmp = A[P];
for(j = P; j>0 && A[j-1]>temp; j--)
A[j] = A[j-1];
A[j] = temp;
}
}

Example

Consider an unsorted array as follows:

34    8   64    51     32      21                                      where (N = 6)


Original
34
8
64
51
32
21
Positions Moved
Pass = 1
8
34
64
51
32
21
1
Pass = 2
8
34
64
51
32
21
0
Pass = 3
8
34
51
64
32
21
1
Pass = 4
8
32
34
51
64
21
3
Pass = 5
8
21
32
34
51
64
4

The final Sorted array : 8     21        32        34        51        64       

Analysis of Insertion Sort

Worst Case Analysis               -- O(N2)
Best Case Analysis                 -- O(N)
Average Case Analysis           -- O(N2)

Limitations of Insertion Sort

It is relatively efficient for small lists and mostly sorted lists.

It is expensive because of shifting all following elements one by one.
                                                                                                                                         (Contd.....)

Twitter -- My Favorite Microblogging Site

Ahem! Ahem!
Hello All!
Today I am not going to bore my readers by posting Source codes, because i am upto something that is a complete new technology for me.
So, once I master it, I will be posting stuffs related to that technology.
 Till then, my readers have to put up with my same old posting style.

Recently, I have found out Twitter to be a very useful site to share thoughts and to connect with people. It is a perfect place for networking, connecting with friends, sharing ideas etc.

Tagging is more cool in twitter. I love Hashtags and the way they all help me in putting across something in my mind, in short, abstract and to-the-point words!
Long live Hashtags!!!

Just follow me on twitter, @hemasweety
Feeling awesome :) :)
Looking forward to expand my twitter network.

Thursday, November 6, 2014

SOME VERY SIMPLE AND BASIC JAVA SOURCE CODES THAT I DEVELOPED. FEEL FREE TO POINT OUT ERRORS IF ANY.(PART-3)

SOURCE CODE #8
//A Simple java program to find the number of characters present in a String.
import java.util.*;
import java.io.*;
public class NumberOfCharactersInAString
{
public static void main(String args[]) throws IOException
{
int chara;
System.out.println("Enter a String");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
for(chara=0; chara {}
System.out.println("The total number of characters present in the String is " + chara);
}

}

OUTPUT FOR SOURCE CODE #8
Enter a String
Hemapriyagopal
The total number of characters present in the String is 14

SOURCE CODE #9
//How to input a string from the monitor and print the reverse of the string on the screen
import java.io.*;
public class StringReverse {
public static void main(String args[]) throws IOException
{
String name;
String revname;
System.out.println("Enter a string");
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
name = br.readLine();
revname = new StringBuilder(name).reverse().toString();

System.out.println("The reversed string is " + revname);
}
}

OUTPUT FOR SOURCE CODE #9
Enter a string
Hemapriyagopal
The reversed string is lapogayirpameH

OUTPUT-2
Enter a string
as df
The reversed string is fd sa

SOME VERY SIMPLE AND BASIC JAVA SOURCE CODES THAT I DEVELOPED. FEEL FREE TO POINT OUT ERRORS IF ANY.(PART-2)

SOURCE CODE #6
//A SIMPLE JAVA PROGRAM THAT EXPLAINS HIERARCHIAL INHERITANCE
/* HERE InheritanceOne is the base calss, Truck, Airplane & Boat are all derived classes.
 * constructor is used in all the classes.
 * The keyword "extends" is used to show that Inheritance concept is used here.
 * Every method prints a simple line on the screen.
 * The output shows the flow of control throughtout the source code.
 * I hope this explains the concept of hierarchial inheritance very well.
 * Author - Hemapriya Gopal
 */

public class InheritanceOne
{
 float position;
 float speed;
 float fuellevel;
 public InheritanceOne()
 {
        System.out.println("Inside the constructor of the base class");
 }
 public void move()
 {
        System.out.println("Inside the InheritanceOne class move() method ");
 }
 public void addPassenger()
 {
        System.out.println("Inside the InheritanceOne class addPassenger() method ");
 }
 public void displayPosition()
 {
        System.out.println("The position of the vehicle is 45' NE ");
 }
 public void displaySpeed()
 {
        System.out.println("The vehicle is moving at the speed of 60km/hr ");
 }
 public void displayFuellevel()
 {
        System.out.println("The fuel tank in the vehicle is half-full");
 }
 public static void main(String args[])
 {
        InheritanceOne io = new InheritanceOne();
        io.move();
        io.addPassenger();
        Airplane a = new Airplane();
        a.operateUnderCarriage();
        a.displayFuellevel();
        Truck t = new Truck();
        t.getTyrePressure();
        t.displaySpeed();
        Boat b = new Boat();
        b.displayPosition();
        b.dock();
 }
/* InheritanceOne()
{
       System.out.println("Inside the destructor of the base class");
}
*/
}
class Airplane extends InheritanceOne
{
       float heightfromGround;
       public Airplane()
       {
              //super();
              System.out.println("Inside the constructor of the derived class Airplane");
       }
       public void operateUnderCarriage()
       {
              System.out.println("Inside the derived class Airplane in the method operateUndercarriage");
       }
}
class Truck extends InheritanceOne
{
       public void getTyrePressure()
       {
              System.out.println("Inside the method getTyrePressure() of the class Truck");
       }
       public Truck()
       {
              System.out.println("Inside the constructor of the derived class Truck");
       }
}
class Boat extends InheritanceOne
{
       public void dock()
       {
              System.out.println("Inside the method dock() of the derived class Boat");
       }
       public Boat()
       {
              System.out.println("Inside the constructor of the derived class Boat");
       }
}

HIERARCHIAL INHERITANCE


OUTPUT:
Inside the constructor of the base class
Inside the InheritanceOne class move() method
Inside the InheritanceOne class addPassenger() method
Inside the constructor of the base class
Inside the constructor of the derived class Airplane
Inside the derived class Airplane in the method operateUndercarriage
The fuel tank in the vehicle is half-full
Inside the constructor of the base class
Inside the constructor of the derived class Truck
Inside the method getTyrePressure() of the class Truck
The vehicle is moving at the speed of 60km/hr
Inside the constructor of the base class
Inside the constructor of the derived class Boat
The position of the vehicle is 45' NE
Inside the method dock() of the derived class Boat


SOURCE CODE #7

/*A very simple program implementing all the basic concepts of javax.swing
 * Reference - 1.The Complete Refernce 5th Edition --Herbert Schildt
 *          2.NUS - ISS S.E Notes for OOP
 *         3.http://www.wattpad.com/6660884-java-swing-gui-development-chapter-two-your-first
 * Author - Hemapriya Gopal
 */
import java.awt.*;
import javax.swing.*;
public class SwingHelloWorldForPractice
{
       public void FrameOne()
       {
              JFrame frame = new JFrame ("Hello World Application");
              frame.setSize(270,70);
              frame.setLayout(new FlowLayout());
             
              JLabel label = new JLabel ("Hello world");
              JButton button = new JButton ("OK");
              frame.add(label);
              frame.add(button);
             
              frame.setVisible(true);
       }
       public void OddOrEvenUsingGUI()
       {
              String num = JOptionPane.showInputDialog (null,"Enter a number");
              int num1=Integer.parseInt(num);
              if(num1==0)
              {
                     JOptionPane.showMessageDialog (null, "The number entered is zero");
              }
              else if(num1 %2 ==0)
              {
                     JOptionPane.showMessageDialog(null, "The number entered is an even number");
              }
              else
              {
                     JOptionPane.showMessageDialog(null, "The number entered is a odd number");
              }
       }
       public void HelloWorldGUI()
       {
              JOptionPane.showMessageDialog(null,"Hello World!", "Hello",JOptionPane.PLAIN_MESSAGE);
       }
public static void main(String args[])
{
       SwingHelloWorldForPractice shwfp = new SwingHelloWorldForPractice();
       shwfp.HelloWorldGUI();
       shwfp.OddOrEvenUsingGUI();
       shwfp.FrameOne();   
}}

OUTPUT: