Sabado, Disyembre 10, 2011

Benigno "Ninoy" Aquino




Benigno “Ninoy” Aquino

            Maybe you saw a face of a person in our 500 peso bill. I would never ask if you know that person already because I know that you know him. He is the much known Benigno Aquino or simply “Ninoy”, he was proclaimed as a hero of our country for fighting the Marcos government and because of that he got himself into danger and on the date August 21, 1983, he was assassinate at the airport (NAIA) by Ronaldo Galman and soon he was killed by the soldiers who escort Ninoy from the airport. And until now this case is still unclosed but the Filipino people accused President Marcos which resulted to EDSA revolution. In this blog I am going to talk all about a hero on mid 70s and 80s.

            Ninoy Aquino was born on November 27, 1932 at the province of Tarlac, to a prominent family. He was a grandson of a General and a son of a Philippine Senator. The name Ninoy Aquino stood early at the age of 17, he was sent by the Manila Times newspaper to report from the war between North and South Korea which was joined by the China and America.

            At the age of 22 he became the youngest mayor in his home-town Concepcion. After six years he became the Governor of Tarlac. In 1967 Aquino once again made a history for being the youngest elected senator of the Philippines. Meanwhile he married Corazon Cojuanco, with whom he eventually raised five children.

            With his brilliant mind and great ambition, he became the leading candidate for the presidency when President Marcos has decided to leave the palace after completing the maximum of two terms on 1973. Aquino’s ambition to be a president was postponed when Marcos decided to declare the state of emergency in which military authorities are given temporary rule or “Martial Law. At the same time Marcos dissolved the constitution, claiming supreme power and jailing his political opponents, including Aquino. Aquino was charged with murder, subversion, and illegal possession of firearms. Although he denied the charges, Aquino was found guilty and was convicted by a military tribunal, or military court, and spent over seven years in prison. When he was prisoned, the government tries to bring down the morale and ability to think by losing his appetite. In 1980 he was allowed to undergo an operation in the United States for a heart bypass operation. He returned to the Philippine on 1983. Upon arriving in the Manila airport he was shot and killed. Marcos and the military stated that a lone gunman who had been hired by the Communist Party had carried out the assassination and no military personnel were involved in that particular incident.After that incident, Marcos lost the trust of his people; the Philippine economy also fell apart. By 1985 the nation was in political and economic chaos, with Marcos under attack by the press and by the strengthened political opposition, which did well in elections.In December 1985 the court proclaimed that General Ver and the others charged with Aquino's murder were not guilty. Marcos promptly returned Ver to his former position. Popular unrest with Marcos's rule grew steadily, however. Within weeks a political movement formed around Aquino's widow, Corazon. She was elected president of the Philippines in 1986, unseating Marcos.
            Years after Benigno “Ninoy” Aquino and Corazon “Cory” Aquino’s son Benigno “Noynoy” Aquino III wins the presidency election on May 2010 and proclaimed as a president of the Republic of the Philippines on June 2010.

REFERENCES:


---June  Rey A. Cortez

Biyernes, Disyembre 9, 2011

Quick sort algorithm versus Bubble sort algorithm



Bubble sort Vs Quick sort
Bago tayo pumunta sa main event alamin muna natin ang bawat isang algorithm una Bubble sort.
Isa sa pinaka basic na sorting algorithm ang bubble sort? It is used in practice and its main application is to make an introduction to the sorting algorithms. Bubble sort belongs to O(n2) sorting algorithms, which makes it quite inefficient for sorting large data volumes. Bubble sort is stable and adaptive
Isa sa pinaka basic na idea about dito ay ginagamit ito sa pamamagitan ng pag kukumpara sa bawat laman ng array isa-isa at pag katapos nito ay uulitin nito ang unang step kung saan mag sisimula ulit cya sa umpisa hangang sa matapos nito ang sorting.
Code:
// Example Program in C++
  // to sort an array
  // using bubble sort

  #include<iostream.h>

  void main(void)
  {
   int temp, i, j;
   int ar[10];

   cout<<"enter elements of array:\n";
   for(i=0; i<10; i++)
     cin>>ar[i];

   // sorting is done here
   for(i=0;i<10;i++)
     for(j=0; j<(10-1); j++)
       if (ar[j]>ar[j+1])
         {
          temp=ar[j];
          ar[j]=ar[j+1];
          ar[j+1]=temp;
         }
   // till here
 
   for(i=0; i<10; i++)
     cout<<endl<<ar[i];
 
   cout<<endl;
  }

Try ninyong gumamit ng program nito at makikita mu sa pag sisimulate mu ng mga code na isa isa nitong ikinukumpara ang  laman ng bawat array hangang sa  ito ay matapos. The best case of bubble sort is the ascending order of the number dahil direct nitong nalalaman kung na sort a ang mga laman ng array ngunit lahat ay may kahinaan and descending order ng number ng array ay lubhang nakaka apekto sa pag sosort ng algorithm na ito kaya lubhang mabagal ang pag sort nito kaysa sa ibang sorting algorithm.
Kung panu to nanggyayari e2 ang mga larawan at example

















































Quick sort naman tayo
            Ang quick sort algorithm ay isa sa pinaka mabilis na algorithm. Quicksort is a relatively simple sorting algorithm using the divide-and-conquer recursive procedure. It is the quickest comparison-based sorting algorithm in practice with an average running time.

          Mas madalas gamitin ang quick sort kaysa sa bubble sort kasi mas efficient ang quick sort algorithm dahil sa massive sorting nito.

panu nga ba gumagana ang quick sort?

Quicksort, like mergesort, is a divide-and-conquer recursive algorithm. The basic divide-and-conquer process for sorting a subarray S[p..r] is summarized in the following three easy steps: 

Divide: Partition S[p..r] into two subarrays S[p..q-1] and S[q+1..r] such that each element of S[p..q-1] is less than or equal to S[q], which is, in turn, less than or equal to each element of S[q+1..r]. Compute the index q as part of this partitioning procedure 

Conquer: Sort the two subarrays S[p...q-1] and S[q+1..r] by recursive calls to quicksort. 

Combine: Since the subarrays are sorted in place, no work is needed to combing them: the entire array S is now sorted.




QUICKSORT(S, P, r)
1 If p < r
2        then q <- PARTITION(S, p, r)
3                QUICKSORT(S, p, q-1)
4                QUICKSORT(S, q+1, r)

note: to sort the whole array S, the initial parameters would be: QUICKSORT(S, 1, length[A]) 


PARTITION(S, p, r)
1 x <- S[r]
2 i <- p-1
3 for j <- p to r-1
4        do if S[j] <= x
5                then i <- i+1
6                         swap S[i] <-> S[j]
7 swap S[i+1] <-> S[r]
8 return i+1


Quicksort's running time depends on the result of the partitioning routine - whether it's balanced or unbalanced. This is determined by the pivot element used for partitioning. If the result of the partition is unbalanced, quicksort can run as slowly as insertion sort; if it's balanced, the algorithm runs asymptotically as fast as merge sort. That is why picking the "best" pivot is a crucial design decision. 
The Wrong Way: the popular way of choosing the pivot is to use the first element; this is acceptable only if the input is random, but if the input is presorted, or in the reverse order, then the first elements provides a bad, unbalanced, partition. All the elements go either into S[p...q-1] or S[q+1..r]. If the input is presorted and as the first element is chosen consistently throughout the recursive calls, quicksort has taken quadratic time to do nothing at all. 

The Safe Way: the safe way to choose a pivot is to simply pick one randomly; it is unlikely that a random pivot would consistently provide us with a bad partition throughout the course of the sort. 

Median-of-Three Way: best case partitioning would occur if PARTITION produces two subproblems of almost equal size - one of size [n/2] and the other of size [n/2]-1. In order to achieve this partition, the pivot would have to be the median of the entire input; unfortunately this is hard to calculate and would consume much of the time, slowing down the algorithm considerably. A decent estimate can be obtained by choosing three elements randomly and using the median of these three as the pivot.

























































code:



#include <stdio.h>

#include <stdlib.h>

void swap(int *x,int *y)

{

   int temp;

   temp = *x;

   *x = *y;
   *y = temp;

}

int choose_pivot(int i,int j )

{

   return((i+j) /2);

}


void quicksort(int list[],int m,int n)

{

   int key,i,j,k;

   if( m < n)

   {

      k = choose_pivot(m,n);

      swap(&list[m],&list[k]);

      key = list[m];

      i = m+1;

      j = n;

      while(i <= j)

      {

         while((i <= n) && (list[i] <= key))

                i++;

         while((j >= m) && (list[j] > key))

                j--;

         if( i < j)

                swap(&list[i],&list[j]);

      }

      // swap two elements

      swap(&list[m],&list[j]);

      // recursively sort the lesser list

      quicksort(list,m,j-1);

      quicksort(list,j+1,n);

   }

}

void printlist(int list[],int n)

{

   int i;

   for(i=0;i<n;i++)

      printf("%d\t",list[i]);

}


void main()

{

   const int MAX_ELEMENTS = 10;

   int list[MAX_ELEMENTS];


   int i = 0;

    

   // generate random numbers and fill them to the list

   for(i = 0; i < MAX_ELEMENTS; i++ ){

       list[i] = rand();

   }

   printf("The list before sorting is:\n");

   printlist(list,MAX_ELEMENTS);

    

   // sort the list using quicksort

   quicksort(list,0,MAX_ELEMENTS-1);


   // print the result

   printf("The list after sorting using quicksort algorithm:\n");

   printlist(list,MAX_ELEMENTS);

}



And the Result iS!!!

Quick Sort Algorithm Wins!!!!



- quick sort is better than the bubble sort because of possibility na ang set ng array ay kadalasan ay hindi na ka sort agad kaya ang 
suggestion ko ay mas magandang gamitin ang quick sort.

-Adrian Paul Q. Liveta
-200910042

Reference:
http://www.algolist.net/Algorithms/Sorting/Bubble_sort
http://learning-computer-programming.blogspot.com/2007/06/sorting-array-using-bubble-sort.html
http://www.devx.com/vb2themax/Tip/18972
http://warp.povusers.org/grrr/bubblesort_eng.html
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/quickSort.htm
http://www.cprogramming.com/tutorial/computersciencetheory/quicksort.html
http://www.devx.com/vb2themax/Article/19900
http://warp.povusers.org/SortComparison/
http://www.cprogramming.com/tutorial/computersciencetheory/quicksort.html