Showing posts with label Softwarestuffs. Show all posts
Showing posts with label Softwarestuffs. Show all posts

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.

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:





Sunday, November 2, 2014

What i read and what i understood?

A warm welcome to everyone who is reading my blog.
Today this post is going to introduce all to Software Quality Assurance.

Step 1: What is Software?
             Software is a group of individual modules that are put together after integration testing is done by the development team. Software is something that cannot be touched or tasted. It is what the business people call as "intangible".




Step 2: What is Quality Assurance and why it is important?
             Every commodity manufactured in the industries have some attribute called as Quality. The sales of a particular product in the market depends on this "quality" of the product. For FMCG, this quality has got a particular validity period starting from the Date Of Manufacture till the Date Of Expiry (within which the product has to be consumed, its quality starts degrading after this period).
             Similar to other products and FMCG software also has got what we call as quality. But, unlike, what we have discussed above, Software Quality willl not degrade with time. May be a better version of Software with far enhanced features can be introduced in the market, but this in no way affects the quality of the Software that is already introduced.
              It is important to understand and use Quality Assurance in a Software, so that it can stand the test- of - time, and it can also be made upward - compatible* . Let us discuss this term in the future posts about software quality. For making the maintenance work of a software lot simpler, in the Software Development Life Cycle it has to made sure at each and every stage that Quality Software  that also met the customer requirements is delivered to the customer on time.

** Mistakes found here and there in this post are most welcome to be pointed out and rectified.