Monday, November 3, 2014

Exchanging Sort Algorithms

  1. Buble Sort

    In buble sort iterate over the list and change the first with the second if first is greater then second exchange them with third if second greater and move to end like this changing the elements with the next if greater.After you reach end start over until you make no change in a pass.

    Buble Sort first pass

    8 4 3 1 7 6 2

    4 8 3 1 7 6 2

    4 3 8 1 7 6 2

    4 3 1 8 7 6 2

    4 3 1 7 8 6 2

    4 3 1 7 6 8 2

    4 3 1 7 6 2 8

    As we can see the large number at the begining(8) moved to end very quickly but the small number(2) at the end moved only 1 place in 1 pass

    Small number at the end are turtles

    Large number at the begining rabbits

  2. Coctail Sort is also known as bidirectional buble sort coctail shaker sort or skaker sort it is a variation of buble sort which sorts from both directions in each pass which eliminates turtle problem because turtles from one side are rabits of the other side.

  3. Comb sort is another buble sort variation, it improves buble sort by introducing a gap between swapped elements in buble sort this gap is 1 .In comb sort this gap help turtles move faster and after each pass gap is decremented undil gap becomes 1 and algorithm becomes a buble sort algorithm.The gap is calculated by dividing the lenght of the list by shrink factor(generally 1.3 ,calculated empirically)

Gnome sort is a very easy exchanging algorithm it is also called stupid sort it does not use nested loops it swaps the elements until the left element is smaller than the right.

Let s try it on our sample list

8 4 3 1 7 6 2

4 8 3 1 7 6 2

4 3 8 1 7 6 2

3 4 8 1 7 6 2

3 4 1 8 7 6 2

3 1 4 8 7 6 2

1 3 4 8 7 6 2

1 3 4 7 8 6 2

1 3 4 7 6 8 2

1 3 4 6 7 8 2

1 3 4 6 7 2 8

1 3 4 6 2 7 8

1 3 4 2 6 7 8

1 3 2 4 6 7 8

1 2 3 4 6 7 8

Sunday, November 2, 2014

Sorting Algorithms

A sorting algorithm puts elements in a list to a certain order.

After sorting the output is a permutation of the input and the output is in nondecreasing order(must not be in increasing order, it may contain same items)

*Partitioning

*Merging

*Selection

*Insertion

*Exchanging

Partitioning is choosing a pivot element and placing elements with values less than the pivot to left and elements with greater values to right.

Merging is dividing the list to 1 unit elements so it is ordered and then merging until there is only one list

Selection generate another list then select from there

Insertion slide all by one to insert in the needed place

Exchanging copy to temp then change the values.

Thursday, September 25, 2014

XamlObjectWriterException

Cannot create unknown type '{clr-namespace:Server.Business.Logic.Workflows.StateMachines.Activities}EnterState'.

Happens because can’t find assembly

1 List<Assembly> ass = new List<Assembly>(); 2 Assembly asm = AppDomain.CurrentDomain.Load("Server.Business.Logic"); 3 foreach (AssemblyName refAsmName in asm.GetReferencedAssemblies()) 4 { 5 ass.Add(AppDomain.CurrentDomain.Load(refAsmName)); 6 } 7 8 ass.Add(asm);

does’ not work

1 xx.LocalAssembly = asm; 2 3 XamlReader reader = ActivityXamlServices.CreateBuilderReader(new XamlXmlReader(ofd.FileName, xx));

does work

Saturday, May 31, 2014

Kendo set

module.addDynamicViewModel('model', {
        url: '@Url.Action("Oku","Ara", new { area = "Personel" })',
        type: 'GET'
    }, {
        'model': {
            set: function (key, value) {
                console.log(key + '=' + value);

                kendo.data.ObservableObject.fn.set.call(this, key, value);
            }
        }
    }
);

Saturday, July 27, 2013

Regex

Regex.Match Method (String) ilk kopyayı bulur

 

Regex.Match ("any calor c3olor colour you like", @"colou?r")  colour u bulur ? olabilir de olmayabilirde 0 veya 1

 

Match m1 = Regex.Match ("One color? There are two colours in my head!", @"colou?rs?");
Match m2 = m1.NextMatch();

Excepiton

bool isAttached = Debugger.IsAttached;
         if (!isAttached)
         {
             Application.ThreadException += new ThreadExceptionEventHandler(Program.Application_ThreadException);
         }
         try
         {
             Program.Go(args);
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             Program.ProcessException(exception);
         }

BST Binary Search Tree

Solundaki dallar sadece kendinden küçük olanlar sağındakiler büyük olanlar.Sağındaki ve solundaki alt ağaçlarda bir bst olmalı.Duplice node olamaz.

 

AYM3J

Tree search

Delete 1

Delete 3

Delete 4

Linked list

Linked list de her item bir sonrakine pointer tutuyor random access bütün itemları tek tek geçmeyi gerektiriyor çok hızlı ekleme silem yapılabiliyor.Ortaya eklemek daha kolay bütün liste yeniden oluşturulmuyor.

Reg ex

Regular expression

| alternatif mavi | mave  mavi veya mave

mavi madi   ma(v|d)i mavi veya madi

gr[ea]y grey or gray

gra*vy => grvy graaaaavy n tane a 0 d aolabilir 100 de

* 0 tane veya n tane

+ 1 veya n tane

? 0 veya 1 tane

Class vs object

Obje ile class arası fark = class plan obje ise o planı uyguladığın zaman eline geçen şey.Mimarlıktaki gibi class plan bina object.

Pratikte instance ı oluşturulmadan classı kullanmak mümkün static method ile.