Umut DoganSoftware Developer - Consultant
https://www.umutdogan.com/
Wed, 31 Oct 2018 19:37:27 +0000Wed, 31 Oct 2018 19:37:27 +0000Jekyll v3.7.4Algorithms<p>In mathematics and computer science, an algorithm is an unambiguous specification of how to solve a class of problems. Algorithms can perform calculation, data processing and automated reasoning tasks.</p>
<p>As an effective method, an algorithm can be expressed within a finite amount of space and time and in a well-defined formal language for calculating a function. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing “output” and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.</p>
<p>The concept of algorithm has existed for centuries. Greek mathematicians used algorithms in, for example, the sieve of Eratosthenes for finding prime numbers and the Euclidean algorithm for finding the greatest common divisor of two numbers.</p>
<p>The word algorithm itself derives from the 9th Century mathematician Muḥammad ibn Mūsā al-Khwārizmī. A partial formalization of what would become the modern concept of algorithm began with attempts to solve the Entscheidungsproblem (decision problem) posed by David Hilbert in 1928. Later formalizations were framed as attempts to define “effective calculability” or “effective method”. Those formalizations included the Gödel–Herbrand–Kleene recursive functions of 1930, 1934 and 1935, Alonzo Church’s lambda calculus of 1936, Emil Post’s Formulation 1 of 1936, and Alan Turing’s Turing machines of 1936–37 and 1939.</p>
<p align="center">
<a href="https://xkcd.com/26/" target="_blank"><img src="../../images/2018-10-31-algorithms.jpg" alt="Fourier" title="Fourier" /></a>
</p>
<h2 id="design">Design</h2>
<p>Algorithm design refers to a method or mathematical process for problem solving and engineering algorithms. The design of algorithms is part of many solution theories of operation research, such as dynamic programming and divide-and-conquer. Techniques for designing and implementing algorithm designs are also called algorithm design patterns, such as the template method pattern and decorator pattern.</p>
<p>One of the most important aspects of algorithm design is creating an algorithm that has an efficient run-time, also known as its Big O.</p>
<p>Typical steps in development of algorithms:</p>
<ol>
<li>Problem definition</li>
<li>Development of a model</li>
<li>Specification of algorithm</li>
<li>Designing an algorithm</li>
<li>Checking the correctness of algorithm</li>
<li>Analysis of algorithm</li>
<li>Implementation of algorithm</li>
<li>Program testing</li>
<li>Documentation preparation</li>
</ol>
<h2 id="example">Example</h2>
<p>One of the simplest algorithms is to find the largest number in a list of numbers of random order. Finding the solution requires looking at every number in the list. From this follows a simple algorithm, which can be stated in a high-level description English prose, as:</p>
<p>High-level description:</p>
<ol>
<li>If there are no numbers in the set then there is no highest number.</li>
<li>Assume the first number in the set is the largest number in the set.</li>
<li>For each remaining number in the set: if this number is larger than the current largest number, consider this number to be the largest number in the set.</li>
<li>When there are no numbers left in the set to iterate over, consider the current largest number to be the largest number of the set.</li>
</ol>
<h2 id="algorithmic-analysis">Algorithmic Analysis</h2>
<p>It is frequently important to know how much of a particular resource (such as time or storage) is theoretically required for a given algorithm. Methods have been developed for the analysis of algorithms to obtain such quantitative answers (estimates).</p>
<h2 id="classification">Classification</h2>
<p>There are various ways to classify algorithms:</p>
<h3 id="by-implementation">By implementation</h3>
<ol>
<li>Recursion</li>
<li>Logical</li>
<li>Serial, parallel or distributed</li>
<li>Deterministic or non-deterministic</li>
<li>Exact or approximate</li>
<li>Quantum algorithm</li>
</ol>
<h3 id="by-design-paradigm">By design paradigm</h3>
<ol>
<li>Brute-force or exhaustive search</li>
<li>Divide and conquer</li>
<li>Search and enumeration</li>
<li>Randomized algorithm</li>
<li>Reduction of complexity</li>
<li>Back tracking</li>
</ol>
<h3 id="optimization-problems">Optimization problems</h3>
<ol>
<li>Linear programming</li>
<li>Dynamic programming</li>
<li>The greedy method</li>
<li>The heuristic method</li>
</ol>
<h3 id="by-field-of-study">By field of study</h3>
<p>Every field of science has its own problems and needs efficient algorithms. Related problems in one field are often studied together. Some example classes are search algorithms, sorting algorithms, merge algorithms, numerical algorithms, graph algorithms, string algorithms, computational geometric algorithms, combinatorial algorithms, medical algorithms, machine learning, cryptography, data compression algorithms and parsing techniques.</p>
<h3 id="by-complexity">By complexity</h3>
<p>Algorithms can be classified by the amount of time they need to complete compared to their input size:</p>
<ol>
<li>Constant time</li>
<li>Linear time</li>
<li>Logarithmic time</li>
<li>Polynomial time</li>
<li>Exponential time</li>
</ol>
<h6 id="references">References:</h6>
<ol>
<li><a href="https://en.wikipedia.org/wiki/Algorithm">https://en.wikipedia.org/wiki/Algorithm</a></li>
<li><a href="https://www.geeksforgeeks.org/fundamentals-of-algorithms">https://www.geeksforgeeks.org/fundamentals-of-algorithms</a></li>
</ol>
<h6 id="books">Books:</h6>
<ul>
<li><a href="https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844">Introduction to Algorithms, 3rd Edition (The MIT Press)</a></li>
<li><a href="https://www.amazon.com/Algorithms-4th-Robert-Sedgewick/dp/032157351X">Algorithms (4th Edition)</a></li>
<li><a href="https://www.amazon.com/Data-Structures-Algorithms-Java-6th-ebook/dp/B00JDRQF8C">Data Structures and Algorithms in Java, 6th Edition</a></li>
</ul>
Tue, 30 Oct 2018 22:00:23 +0000
https://www.umutdogan.com/2018/algorithms/
https://www.umutdogan.com/2018/algorithms/algorithmsalgorithmsSoftware Design Patterns<p>Design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.</p>
<p>If you are new to programming, probably you won’t hear or use “design pattern” concept a lot for the first couple months/years. But after some time, when you start to write more meaningful programs, you’ll definitely need to use some tested and proven design patterns in your code. Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.</p>
<p align="center">
<img src="../../images/2018-07-05-software-design-patterns.jpg" alt="Design Patterns Are Still Useful" title="Design Patterns Are Still Useful" />
</p>
<p>Design patterns gained popularity in computer science after the book Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994 by the so-called “Gang of Four” (Gamma et al.), which is frequently abbreviated as “GoF”. This important book describes various development techniques and pitfalls in addition to providing twenty-three object-oriented programming design patterns. The four authors were Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.</p>
<p>In the case of object-oriented programming, design patterns are generally aimed at solving the problems of object generation and interaction, rather than the larger scale problems of overall software architecture. They give generalized solutions in the form of templates that may be applied to real-world problems.</p>
<p>Design patterns were originally grouped into the categories: creational patterns, structural patterns, and behavioral patterns, and described using the concepts of delegation, aggregation, and consultation.</p>
<h2 id="creational-design-patterns">Creational design patterns</h2>
<p>These design patterns are all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.</p>
<ul>
<li><strong>Abstract Factory</strong>: Creates an instance of several families of classes</li>
<li><strong>Builder</strong>: Separates object construction from its representation</li>
<li><strong>Factory Method</strong>: Creates an instance of several derived classes</li>
<li><strong>Object Pool</strong>: Avoid expensive acquisition and release of resources by recycling objects that are no longer in use</li>
<li><strong>Prototype</strong>: A fully initialized instance to be copied or cloned</li>
<li><strong>Singleton</strong>: A class of which only a single instance can exist</li>
</ul>
<h2 id="structural-design-patterns">Structural design patterns</h2>
<p>These design patterns are all about Class and Object composition. Structural class-creation patterns use inheritance to compose interfaces. Structural object-patterns define ways to compose objects to obtain new functionality.</p>
<ul>
<li><strong>Adapter</strong>: Match interfaces of different classes</li>
<li><strong>Bridge</strong>: Separates an object’s interface from its implementation</li>
<li><strong>Composite</strong>: A tree structure of simple and composite objects</li>
<li><strong>Decorator</strong>: Add responsibilities to objects dynamically</li>
<li><strong>Facade</strong>: A single class that represents an entire subsystem</li>
<li><strong>Flyweight</strong>: A fine-grained instance used for efficient sharing</li>
<li><strong>Private Class Data</strong>: Restricts accessor/mutator access</li>
<li><strong>Proxy</strong>: An object representing another object</li>
</ul>
<h2 id="behavioral-design-patterns">Behavioral design patterns</h2>
<p>These design patterns are all about Class’s objects communication. Behavioral patterns are those patterns that are most specifically concerned with communication between objects.</p>
<ul>
<li><strong>Chain of responsibility</strong>: A way of passing a request between a chain of objects</li>
<li><strong>Command</strong>: Encapsulate a command request as an object</li>
<li><strong>Interpreter</strong>: A way to include language elements in a program</li>
<li><strong>Iterator</strong>: Sequentially access the elements of a collection</li>
<li><strong>Mediator</strong>: Defines simplified communication between classes</li>
<li><strong>Memento</strong>: Capture and restore an object’s internal state</li>
<li><strong>Null Object</strong>: Designed to act as a default value of an object</li>
<li><strong>Observer</strong>: A way of notifying change to a number of classes</li>
<li><strong>State</strong>: Alter an object’s behavior when its state changes</li>
<li><strong>Strategy</strong>: Encapsulates an algorithm inside a class</li>
<li><strong>Template method</strong>: Defer the exact steps of an algorithm to a subclass</li>
<li><strong>Visitor</strong>: Defines a new operation to a class without change</li>
</ul>
<h6 id="references">References:</h6>
<ol>
<li><a href="https://sourcemaking.com/design_patterns">https://sourcemaking.com/design_patterns</a></li>
<li><a href="http://www.blackwasp.co.uk/gofpatterns.aspx">http://www.blackwasp.co.uk/gofpatterns.aspx</a></li>
<li><a href="https://en.wikipedia.org/wiki/Software_design_pattern">https://en.wikipedia.org/wiki/Software_design_pattern</a></li>
</ol>
<h6 id="books">Books:</h6>
<ul>
<li><a href="https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612">Design Patterns: Elements of Reusable Object-Oriented Software</a></li>
<li><a href="https://www.amazon.com/Head-First-Design-Patterns-Brain-Friendly/dp/0596007124">Head First Design Patterns: A Brain-Friendly Guide</a></li>
</ul>
Thu, 05 Jul 2018 22:00:23 +0000
https://www.umutdogan.com/2018/software-design-patterns/
https://www.umutdogan.com/2018/software-design-patterns/design patternsdesign patterns