Binary Search Algorithm in PHP

Binary Search algorithm has runtime complexity of O(log n) for worst case and average case, and O(1) for the best case. There is recursive and iterative implementation of Binary Search. I will write iterative implementation…

Quick Sort Algorithm in PHP

Quick Sort is the most widely used sorting algorithm. It is official sorting algorithm in PHP (sort). It has average case runtime O(n log n) and worst case O(n^2). If you want to understand how…

Merge Sort Algorithm in PHP

Merge sort guarantees O(n log n) runtime. It is usually compared with Quick Sort and is likely a second best sorting algorithm after Quick Sort in most cases. Quicksort is average case O(n log n),…

Selection Sort Algorithm in PHP

Even with similar complexity of O(n^2) as Bubble Sort, selection sort is preferred when memory writes are too expensive. If you want to understand how it works, jump to bottom of the page to see…

Bubble Sort Algorithm in PHP

Bubble sort algorithm has a runtime complexity of O(n2) and space complexity of O(1). Find below two implementations of Bubble Sort in PHP. If you want to understand how it works, jump to bottom of…

Interface for Value Object

UPDATE: With improvement in my ideas, experience and knowledge, I no longer agree with having an interface for a Value Object. I don’t write interface for Value Objects anymore. The most solid reason for this…