Data structures and algorithms

Source: Internet
Author: User
Tags shallow copy

09 Summary of principles: # #单一职责原则 * responsibilities are defined as: Causes of change; * The SRP principle is embodied as: an object (method) only do one thing; # # #常用模式:* Proxy mode * Iterator mode * Singleton mode * Decorator Mode # # # # #分离职责 * If as demand changes, There are two responsibilities that always change at the same time, so there is no need to separate them; * The axis of responsibility changes only when they are determined to change ... Read the full text posted @ 2015-07-02 18:05 jinkspeng read (4) |  Comments (0)   Edit  01 Basic Summary: # #鸭子类型:* Focus only on the behavior of the object, not on the object itself ; # #多态:* Introduction: The same operation for different objects can produce different results; * The idea behind: to separate things from what might change, to encapsulate; The key is to eliminate the coupling between types; * Implementation: * General language: Common inheritance, upward transformation to show the polymorphic characteristics of the object; * JS: Because of its own ' Duck type ' special ... Read the full text posted @ 2015-07-02 18:03 jinkspeng read (4) |  Comments (0)   Edit  08 status, adapter summary: # #状态模式 * The key to state mode is to encapsulate each state of things into a separate class, and the behavior associated with such a state is encapsulated within the class, and when the internal state changes, it brings different behavioral changes; # # # #电灯开关的例子 "var offlightstate = function ( Light) {this.light = Light;};o F... Read the full text posted @ 2015-06-17 09:53 jinkspeng read (3) |  Comments (0)   Editor  07 Mediator, decorator Summary: # #中介者模式 * Unbind the object from the object; When an intermediary is added, all objects can be communicated by intermediaries instead of referencing each other; # # # #中介者模式例子 * game ' function Player (name, teamcolor) {this.state = ') Live '; THIS.name = name; ... Read the full text posted @ 2015-06-17 09:52 jinkspeng Read (7) |  Comments (0)   Edit  06 Enjoy, Responsibility chain Summary: # #享元模式 * is a model for performance optimization; The core is the use of shared technology to effectively support a large number of fine-grained objects; # # # #内部状态和外部状态 * Enjoy meta mode requires that the attributes of the object be divided into internal and external states; * The target is to reduce the number of shared objects; * Internal state is stored inside the object; The internal state can be shared by some objects; * Internal state is independent of the specific scene, pass ... Read the full text posted @ 2015-06-17 09:51 jinkspeng Read (5) |  Comments (0)   Edit  05 combination, template summary: # #组合模式 * Combine objects into a tree structure to represent ' Partial-whole ' hierarchy; the traversal of the tree structure requires only one operation; * Use the unity of object polymorphism to treat combination objects and individual objects without concern for their differences; * The macro command in the command mode is a combination mode; # # # #请求在树中传递的过程; * If the child node is a leaf node, The leaf object itself will handle the request; Read the full text posted @ 2015-06-17 09:50 jinkspeng Read (5) |  Comments (0)   Edit  04 Observation, command summary: # #观察者模式 * Also known as the Publish subscription mode, Defines a one-to-many dependency between objects, and when an object's state changes, all objects that depend on it are notified; * JS Development, the general use of event model to replace the traditional publish-subscribe mode # # # #作用 * can be widely used in asynchronous programming, instead of traditional callback functions, such as subscribing to the ' Ajax ' request ' Error, SUCC ' event; * Replace Object ... Read the full text posted @ 2015-06-17 09:48 jinkspeng Read (5) |  Comments (0)   Edit  03 Agent, iterator Summary: # #代理模式 * Provides a substitute or placeholder for an object. In order to control his access; # # # # # # # # # # # #面向对象设计原则-Single Duty principle * in the case of a class (object, function), there should be only one cause for his change; # # # # #代理和本体借口的一致性 * # # # # # # # # # # # # # # # # # # # # #保护代理 * ; can be used to control different permissions on ... Read the full text posted @ 2015-06-17 09:47 jinkspeng read |  Comments (0)   Edit  02 Singleton, policy summary: # #单例模式 * Ensure that a class has only one instance,and provides a access to his global access point; # # # #模拟单例实现 * Traditional way: ' var creatediv = (function () {var instance; var creatediv = function (HTML) {if (instance ) ... Read the full text posted @ 2015-06-17 09:46 jinkspeng Read (9) |  Comment (0)   Edit  JS: Data structure note 14--Advanced algorithm Summary: Dynamic planning: Recursion is the decomposition of the problem from the top, solving the problem by resolving all the small problems, the dynamic plan solves the problem from the bottom, solves all the small problems, and then merges a whole solution; function Dynfib (n) {var val = []; var i = 1; I b)? A:B;} Functi ... Read the full text posted @ 2014-10-25 12:04 jinkspeng Read (0) |  comment (+)   Edit  JS: Data structure note 13--Retrieval algorithm summary: Sequential lookup: Also called linear lookup , a basic format for brute force lookups: var nums = [];for (var i = 0; I max min = arr[i];}} return min;} View code Self-organizing data: After multiple lookups, the most frequently found elements will be from the original ... Read the full text of posted @ 2014-10-25 10:48 jinkspeng reading (0) |  Comment (2)   Edit  JS: Data structure note 12--sorting algorithm summary: Advanced Sorting algorithms: (Processing Big Data: Millions more) Hill sort: is an optimized version of the insert sort, first sets the interval array, then sorts each interval, respectively, such as the first interval is 5, first a[5] and a[0] to insert the sort, and then a[6] and a[0],a[1] for the insertion sort, Until the last one; then replace the interval value until all the interval values are sorted (when the interval value is 1 o'clock, it is normal ...). Read the full text posted @ 2014-10-20 09:11 jinkspeng Read (0) |  Comment (1)   Edit  JS: Data structure note 11--sort algorithm (+) Summary: Basic preparation: function CArRay (numelems) {this.datastore = []; this.pos = 0; this.numelems = numelems; this.insert = insert; this.tostring = toStr. . Read the full text posted @ 2014-10-19 17:23 jinkspeng read |  Comments (0)   Edit  JS: Data structure notes 10--diagram and graph algorithm summary: Figure: is a set of edges and fixed points, according to the order of the fixed point of the graph can be divided into: directed and non-directed graph; path: All vertices are made up of edge joins; The path length is the number between the first point and the last vertex; the loop: a vertex pointing to itself, a length of 0; And the first vertex is the same as the last vertex; strong connectivity: If there is a path between the two vertices, the two vertices are strongly connected, and vice versa ... Read the full text posted @ 2014-10-18 19:14 jinkspeng read |  Comments (1)   Edit  JS: Data structure notes 9--Two tree summary: tree: Storing data in a hierarchical manner ; Node: root node, child node, parent node, leaf node (node without any child nodes); Layer: root node starts at layer 0, binary tree: No more than two nodes per node; find faster (than linked list), add, delete fast (than array); BST: Two tree lookup: Set the root node to the current node If the node to be inserted is less than the current node, set its left node to be the new current node, or greater than the right ... Read the full text posted @ 2014-10-18 11:24 jinkspeng read (2) |  Comments ()   Edit  JS: Data structure notes 8--Collection Summary: Collections: Uniqueness, disorder ; Basic structure: function Set () {this.datastore = []; this.add = add; this.remove = remove; this.contains =contains; this.show = s how; } ... Read the full text posted @ 2014-10-17 20:45 jinkspeng read |  Comments (0)   Edit  JS: Data structure notes 7--hash table summary: Hash table (hash table): by hash functionMaps a key value to a dictionary; a hash function: a hash function that relies on the data type of the key value; A basic hash table: (the key value is computed as a string) function HashTable () {this.table = new Array (137); This.simplehash = Simpleh ... Read the full text of posted @ 2014-10-17 16:13 jinkspeng Read (0) |  comment on the   edit  JS: Data structure notes 6--dictionary abstract: The basis of the Dictionary class is that the array is not an object; The main purpose of the dictionary is to use key values; Basic definition: function Dictionary () {this.datastore = new array (); this.add = add; this.find = Find; This.remove = ... Read the full text posted @ 2014-10-17 14:09 jinkspeng read |  Comments (0)   Edit  JS: Data structure notes 5--List summary: Arrays: Array defects in other languages: Add/Remove arrays trouble; The disadvantage of JS array: Being implemented as an object is inefficient; If you want to implement random access, the array is a better choice; list: structure: Basic code: Function Node (elem) {This.elem = Elem; This.next = null;} Function Llis ... Read the full text of posted @ 2014-10-17 11:45 jinkspeng reading (0) |  Comments ()   Edit  JS: Data structure notes 4--Queue summary: Queues are a special list, The data structure is FIFO; definition: function Queue () {this.datastore = []; this.enqueue = enqueue; this.dequeue = dequeue; this.front = front; t His.bac ... Read the full text posted @ 2014-10-16 10:26 jinkspeng Read the |  comments (0)   Edit  JS: Data structure notes 3--Stack summary: Stacks are a special list, Data structure is LIFO;: function Stack () {this.datastore = []; this.top = 0; this.push = push; this.pop = pop; this.peek = peek; This.len ... Read the full text posted @ 2014-10-15 09:41 jinkspeng Read (0) |  Comments (2)   Edit  JS: Data structure note List summary: list: definition: A set of ordered data function List () {this.listsize = 0; this.pos = 0; this.datastore = []; this.find = Find, ..............} Method: Append: ... Read the full text posted @ 2014-10-13 09:31 jinkspeng read (+) |  Comments (0)   Edit  JS: Data structure NOTE 1---An array summary: JS Array: Just a special object, less efficient than other languages; A property is an index used to represent an offset; in JS, a numeric index is internally converted to a string type (which is why it is not called when you write an object property) because the property in the object must be a string type ; Operation: Judge: IsArray (); copy: Shallow copy: var arr1 = arr2; deep copy: Functi ... Read the full text posted @ 2014-10-12 13:29 jinkspeng read (+) |  Comments (0)   Edit

Data structures and algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.