Wednesday, January 19, 2011

MathCom_Algorithm & Orders of Growth of Mathematic for Computing

Algorithm is the sequences step of dfference processing to solve the problems clearly .
Algorithm Characteristics :
Some important general features of algorithms :
  • Input : Information or  data that comes in. 
  • Output : Information or data that goes out.
  • Definiteness : Algorithm is precisely defined.
  • Correctness : Outputs correctly relate to inputs.
  • Finiteness : Won't take forever to describe or run.
  • Effectiveness : Individual steps are all do-able.
  • Generality : Works for many possible inputs.
  • Efficiency : Takes little time & memory to run.
=======================================================
Pseudocode Language :
    1.variable := expression   ==> a := b + 1
    2.{comment}                   ==> {for calculate เป็นภาษาอะไรก็ตาม}   
    3.begin statements end   ==> begin a:=2 end
    4.if condition then          ==> if b>3 then
           statements [else                  b=b+3  else
           statements]                          b=b-2
    [else ......] ไม่เขียนก็ได้
    5.for variable := initial value to final value ==> for a := 1 to
       statements                                                          b = b+a
    6.while condition                                     ==> while a < 4
       statements                                                           write I love mathematic
    7.return expression                                 ==> return a      {copy value of a to the function above}
    =======================================================
    Search Algorithm
        1.Linear Search
         {An}=A1,A2,A3,A4.........An;
          We want to find location of x which =Ai ==> i = ?
          How to :
         //-------------------------------------------------------
          procedure linear search
          i := 1 {the initial location of sequences}
          while (i <= n & x != Ai)
                   i := i+1
          if i <= n then location := i
          else locationon := 0
          return location
          //-------------------------------------------------------
        2.Binary Search
        {An}=A1,A2,A3,A4.........An;
          We want to find location of x which =Ai ==> i = ?
          How to :
         //-------------------------------------------------------
          procedure binary search
          i := 1 {the initial location of sequences}
          j := n {the lastest location of sequences}
          while i<j 
                begin 
                   m := lowest ((i+j)/2)     {Ex: lowest of 2.3=2 ; 2.9=2}
                if x > Am then i := m+1 else j := m
          else 
          if x=Ai then location := i else location := 0
          return location
    =======================================================
    Time Complexity
         1.time which use for work 
         2.memory space 
         3.f(n) is the function of time working , n the data of time
         4.Operator :
                  _Assignment ( := )
                  _Comparison ( = , != , < , > , <= , >= )
                  _Arithmetic operation (+ , - , * , / )
                  _Logical operations ( and , or , not )
    =======================================================
    Orders of Growth
          *Big-O (Concept of Orders of Growth)
              f(n)=O(g) {mean f(n) is smaller then g(n)}
              n^a+/-n^(a-1)..........=O(n^a)
           *Big-O (Growth of Function)
             f =O(g) <=> f € O(g)  {f belong to O(g)}
             method of Big-O
                   |f(n)| <= c×|g(n)| , n >= k ; c,k € N ===> f(n) € O(g(n))
                   k is the highest intersection point of f(n) & g(n)
           *Big-O (Useful Rules) 
                1.if   f1(n)=O(g1(n)) & f2(n)=O(g2(n))  ====> (f1+f2)(n) =O(max(g1(n),g2(n))       
                2.if   f1(n)=O(g(n)) & f2(n)=O(g(n))      ====> (f1+f2)(n) =O(g(n))
                3.if   f1(n)=O(g1(n)) & f2(n)=O(g2(n))  ====> (f1×f2)(n) =O(g1(n)×g2(n)) 
                    **Function comparison :  n € N
                    n^a >= n^b ; a > b
                    n×log(n) >= log(n!) 
                    n² >= n×log(n)
                    
                    
                  
          

    No comments:

    Post a Comment