Posted on Leave a comment

Quicksort Algorithm – Cesar’s Tech Insights – Medium

“What is Quicksort?” This is another question you’ll face in almost every tech job interview. Quicksort it is probably the most used sorting algorithm because it’s easy to implement on average, gives high efficiency for large-data applications, it can be optimized for different needs and it’s relatively flexible on it’s input data.

Quicksort is a logarithmic-time algorithm, in other words, it has a Big O notation of O(log n)-(more about Big O Notation)- and depending on the way you implement it, it can be up to 2x or even 3x faster than Merge Sort or Heap Sort. Do note that the O(log n) speed is a best-case/average time, in worst case scenarios it can be O(n2) depending on the implementation.

Let’s explore one implementation of Quicksort using JavaScript (ECMA6):

const quickSort = list => {
  if (list.length < 2) 
    return list;  let pivot = list[0];
  let left  = []; 
  let right = [];  for (let i = 1, total = list.length; i < total; i++){
    if (list[i] < pivot)
      left.push(list[i]);
    else
      right.push(list[i]);
  }  return [
    ...quickSort(left), 
    pivot, 
    ...quickSort(right)
  ];
};

Quicksort uses recursiondivide-and-conquer and comparison-sort. It works by partitioning an array into two sub-arrays and then recursively sorting those arrays independently. To make it clear, let’s put this in 3 main steps:

  • Choose the pivot (reference value).
  • Divide the rest of the array in two, placing everything smaller than the pivot on the left and greater than the pivot on the right.
  • Recursively apply the previous steps to the sub-arrays if they have more than 1 element.

In the following chart you can see our example algorithm in action; pivots are green, left arrays are red, and right ones are blue.

quickSort( [6,3,8,4,5,2,9,33,12,64]) = [2, 3, 4, 5, 6, 8, 9, 12, 33, 64]

Another great advantage of Quicksort is that it can be implemented using task parallelism, so, with some tweaking of the code it can be used to get a great performance boost in multi-core processing or even better, GPU processing for extreme performance.

Although JavaScript is a single-threaded language, if your application requires a lot of power, you can enable parallel high-performance GPU processing via WebCL or use NodeJS and a library called node-cuda, the latter allows you to use NVIDIA CUDA™ -although you need an NVIDIA CUDA-enabled GPU-, but with hundreds of compatible models, you probably can get some science out of your current gaming computer!

Source: Quicksort Algorithm – Cesar’s Tech Insights – Medium

Posted on Leave a comment

.NET Design Patterns in C# and VB.NET – Gang of Four (GOF) – doFactory.com

Design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects.

The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral (for a complete list see below).

To give you a head start, the C# source code for each pattern is provided in 2 forms: structural and real-world. Structural code uses type names as defined in the pattern definition and UML diagrams. Real-world code provides real-world programming situations where you may use these patterns.

A third form, .NET optimized, demonstrates design patterns that fully exploit built-in .NET 4.5 features, such as, generics, attributes, delegates, reflection, and more. These and much more are available in our .NET Design Pattern Framework 4.5. You can see the Singleton page for a .NET 4.5 Optimized example.

Source: .NET Design Patterns in C# and VB.NET – Gang of Four (GOF) – doFactory.com

Posted on Leave a comment

c# – LDAP – Retrieve a list of all attributes/values? – Stack Overflow

foreach (string propName in props.PropertyNames) { if (entry.Properties[propName].Value != null) { Console.WriteLine(propName + ” = ” + entry.Properties[propName].Value.ToString()); } else { Console.WriteLine(propName + ” = NULL”); } }

Source: c# – LDAP – Retrieve a list of all attributes/values? – Stack Overflow

Posted on Leave a comment

Scaffold Identity in ASP.NET Core projects | Microsoft Docs

Scaffold Identity in ASP.NET Core projects 10/23/2018 12 minutes to read +1 By Rick Anderson ASP.NET Core 2.1 and later provides ASP.NET Core Identity as a Razor Class Library. Applications that include Identity can apply the scaffolder to selectively add the source code contained in the Identity Razor Class Library (RCL). You might want to generate source code so you can modify the code and change the behavior. For example, you could instruct the scaffolder to generate the code used in registrati

Source: Scaffold Identity in ASP.NET Core projects | Microsoft Docs