Algorithm

Binary Search Algorithm using by C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace BinarySearch
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] array = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  13.             Array.Sort(array);
  14.             Binarysearch(array, array.Length, 10);
  15.         }
  16.         private static void Binarysearch(int[] array, int size, int value)
  17.         {
  18.             int firstIndex = 0;
  19.             int lastIndex = size – 1;
  20.             while (firstIndex <= lastIndex)
  21.             {
  22.                 int midIndex = (firstIndex + lastIndex) / 2;
  23.                 if (array[midIndex] == value)
  24.                 {
  25.                     Console.WriteLine(“Found”);
  26.                     Console.ReadKey();
  27.                 }
  28.                 else if (array[midIndex] > value)
  29.                 {
  30.                     lastIndex = midIndex – 1;
  31.                 }
  32.                 else if (array[midIndex] < value)
  33.                 {
  34.                     firstIndex = midIndex + 1;
  35.                 }
  36.             }
  37.             Console.WriteLine(“Not found”);
  38.             Console.ReadKey();
  39.         }
  40.     }
  41. }
Advertisements
Categories: Algorithm | Leave a comment

Introduction to Algorithms by Thomas H.Cormen (pdf)

I think that it is best book to learn algorithm. Click the link to download.

http://www.mediafire.com/download/hiappl6z148ii8x/clrs.pdf

Categories: Algorithm | Leave a comment

Matlab Code of Numerical Analysis

https://drive.google.com/open?id=0B2Sufpw5T6EvM3VpQVlSSjYtV3c

Categories: Algorithm | Leave a comment

Create a free website or blog at WordPress.com.