2010/03/14

C# week7_3


10/03/2010

Exception

try
{
---------
---------
}
catch(DividebyZero a)
{
---------
}
catch(Exception e)
{
---------
}
It will work.


 
try
{
---------
---------
}
catch(Exception e)
{
---------
}
catch(DividebyZero a)
{
---------
}
It won't work, because catch(DividebyZero a) class has never been executed, which is called 'unreachable code'. = error


 

Algorithms: a well-defined procedure to solve a problem


 

Sort Algorithm

  • Bubble sort (one by one, taking long time)
  • Exchange sort (similar to bubble sort, but slightly more efficient)
  • Selection sort (search and sort, one of the least efficient)


  • Insertion sort


    • two sub arrays
      • first sub array: sorted
      • second sub array: unsorted
    • first and efficient using with small arrays.


  • Quick sort
    • divide and conquer algorism
    • very efficient


  • Merge sort
    • two sorted arrays (MUST be SORTED FIRST)
    • more efficient but at the same time it is more complex


  • Bucket sort
    • counts array

 

Search Algorism



  • Liner search
    • best case: first element
    • worst case: last element
    • not efficient


  • Binary search
    • required a sorted array
    • array 0 to 9 (0+9)/2 = 4.5 find 4
    • (5+9)/2 = 7 find 7
    • (5+6)/2 = 5.5 find 5
    • (6+6)/2 = 6 find 6
    • more efficient

0 件のコメント:

コメントを投稿

UA-9417263-1