Algorithms and data structures

Source: Internet
Author: User
Tags cos sin time 0

at present, the computer has been deep into all areas of social life, by which it is Web front-end application, its application is no longer confined to scientific computing, but more is used in control, management and data processing and other non-numerical computing fields. Computer is a research computer for information representation and processing of science. This involves two questions: the representation of information, the processing of information.

the representation and organization of information is directly related to the efficiency of the process of processing information. With the continuous complexity of web application problems, the rich of front-end page features, resulting in information explosion and the widening of the scope of information, so many Web applications are large scale, the structure is quite complex. Therefore, it is necessary to analyze the characteristics of the objects in the problem to be handled and the relationship between the objects, which is the data structure.

The general process of writing a program to solve practical problems:

L How do I describe a problem in data form? --to abstract an appropriate mathematical model from the problem

L The amount of data involved in the problem and the relationship between the data

L how to store data and reflect the relationship between data in a computer

L What do you need to do with your data when dealing with problems?

L are you writing a program that performs well?

The questions listed above are basically solved by the data structure we are learning today.

Qian Feng "HTML5 " algorithm and data structure " (V6.5)

All-Stack engineers need to understand the algorithms and data structures, regardless of the computer language, as long as the programmer, then the algorithm and data structure is your required core, but also the cornerstone of the front-end developers. Proficient in the front-end based on the deep understanding of the algorithm and data structure, can better stand in full stack angle to design and research and development, improve Web performance, access and experience for more users.

How are algorithms and data structures taught? The following points are mainly highlighted:

First, gradually. Focus on concept, function, usage, students-oriented, teachers as a supplement to the teaching concept, guide students to solve the problem of self-thinking, rapid upgrading and application of algorithms and master data storage and processing methods.

Second, project-driven. The project-driven teaching method, starting from the real project, stimulates students ' learning interest, takes interest as guidance, helps students master the project development process and the operation principle of the project, and improves the running efficiency of the project.

Third, focus on actual combat. Let students continue to solve project problems to be improved and sublimation, summed up the excellent algorithm, cultivate independent development and problem-solving ability.

The algorithm and the data contain two parts, the concrete content is as follows:

The first part: Algorithm . The common algorithms in this section are:

Recursive algorithm. The content mainly includes recursive thought, recursive function, recursive realization.

sorting algorithm. The content mainly contains Array.prototype.sort (), insert sort, bubble sort, select sort, quick sort, heap sort, merge sort, hill sort etc sorting algorithm.

when it comes to front-end sequencing, nature first thinks The native interface of JavaScript is Array.prototype.sort.

This interface is self - ECMAScript 1st edition is present.

Array.prototype.sort specification

The elements of this array is sorted. The sort is isn't necessarily stable (that's, elements that compare equal does not necessarily remain in their original order ). If Comparefn is not undefined, it should being a function that accepts the arguments x and Y and returns a negative value if x < Y, zero if x = y, or a positive value if x > Y.

Clearly, the specification does not qualify what sort algorithm is implemented within the sort. Even the implementation of the interface does not need to be a stable sort

In this context, the front-end sort of the matter depends on the specific implementation of each browser.

Insert Sort

thought: insert a record into the sorted ordered table to get a new of the an ordered table with an increase of 1 records . That is, the 1th record of the sequence is considered an ordered subsequence, and then inserted from the 2nd record one after the other until the entire sequence is ordered.

optimal complexity: When an input array is sorted, the complexity is 0 (n)

worst-case complexity: When the input array is in reverse order, the complexity is 0 (n^2)

Insert Sort comparison suitable for "arrays of small number of elements"

Bubble sort

Thought: Through 22 exchange, like the bubbles in the water, the small first popped out, the big one came out.

Worst run Time:0 (n^2)

Best Running time:0 (n^2)

Select sort

thought: In the set of numbers to sort, select the minimum (or maximum) number to exchange with the first position, and then in the remaining number, find the smallest (or largest) number in the 2nd position, and so on, Until the first N-1 element (the penultimate number) and the nth element (the last number) are compared.

Best run Time:0 (n^2)

Worst run Time:0 (n^2)

Quick Sort

Algorithm steps:

1 Select an element from the series, called the "datum",

2 Reorder the columns, where all elements are placed in front of the datum in a smaller position than the base value, and all elements are larger than the base value behind the datum (the same number can be on either side). After the partition exits, the datum is in the middle of the sequence. This is called partitioning operation.

3 recursively sorts the sub-columns that are less than the base value element and the sub-numbers that are larger than the base value element.

At the bottom of the recursive scenario, the size of the sequence is 0 or one, which is always sorted. Although it is always recursive, the algorithm always exits, because in each iteration, it will at least put an element in its final position.

Worst run Time: Time 0 (n^2) when the input array is sorted

Best Running time:0 (NLGN)

Heap Sort

best time:0 (NLGN)

worst Time:0 (NLGN)

Thought: Using the minimum heap, the maximum heap of this data structure, and the heap can also be used to build a priority queue.

Merge sort

Thought: Solving the problem of sorting by the thought of divide and conquer

worst-case Run time:0 (NLGN)

Best Running time:0 (NLGN)

Divide-and-conquer method: It is to decompose the original problem into several independent sub-problems, and the form of these sub-problems similar to the original problem, but the scale is reduced, after solving the sub-problem, the merging result constitutes the solution of the original problem.

Hill sort

thought: First, the entire sequence of records to be sorted into a number of sub-sequences of the direct insertion of the order, the entire series of records in the "basic order", then the whole record is inserted in order.

The second part: data structure. Common data structures.

Linked list:

Chained storage: Stores data elements in a linear table with a set of arbitrary storage units. Linear lists, which are stored in this way, are referred to as linear list.

The first-level arbitrary storage units of the nodes in the storage chain can be contiguous or discontinuous, or even scattered in arbitrary locations in memory.

The logical and physical order of nodes in a linked list is not necessarily the same.

In order to correctly represent the logical relationship between nodes, each node value must be stored at the same time as the address (or position) indicating its immediate successor, called a pointer or chain, which forms the node structure in the list.

A linked list links the n nodes of a linear table to their logical order by the pointer field of each node .

Each knot contains only a linked list of pointer fields, called a single-linked list.

stacks and queues are two widely used data structures, both from linear table data structures, which are "operation constrained" linear tables.

Stacks are implemented in computers in a number of ways:

Hard stacks: Leveraging Some register groups in the CPU or similar hardware use special areas of memory to implement. These stacks have limited capacity but are fast

Soft stacks: This type of stack is primarily implemented in memory. The stack capacity can reach a large size. In the way of implementation, there are two kinds of dynamic and static methods.

Stack: is a linear table that restricts insertion and deletion at one end of a table. Also known as the last-in-first-out or advanced post-outlet table.

Queue: A linear table that is also constrained by operations. is an advanced first-out linear table. Only one end of the table is allowed to be inserted, and the other end is deleted.

Trigonometric function:

(a) the essence of trigonometric functions is the mapping between the set of arbitrary angles and the variables of a set of ratios.

(ii) Six basic functions: sine, cosine, tangent, cotangent, secant, and Remnant cut.

(iii) in a planar Cartesian coordinate system, a ray 0p is drawn from point 0, the rotation angle is θ,the coordinates of the P point are (x, y) are: (Hypotenuse C, the Edge is a, the adjacent side is b)

1. sine function sinθ = A/C sine (sin): angle A's edge ratio hypotenuse

2. cosine function cosθ = b/c cosine (COS): The adjacent edge of angle A is more than the hypotenuse

3. tangent function tanθ = A/b tangent (tan): Edge of Corner a adjacent edge

4. cotangent function cotθ = b/a cotangent (cot): Adjacent edge alignment edge of angle a

5. secant function secθ = c/b secant (sec): Corner a hypotenuse adjacent edge

6. residual cut function cscθ = c/a redundancy (CSC): Bevel edge of angle a

Pythagorean theorem

Right Triangle , the square of the two straight edges equals the square of the hypotenuse. Even if right triangle ABC, wherein the angle c=90°, the length of the straight edge BC is A,AC length is B, the length of the hypotenuse AB is C, there is A2+B2=C2

Implementation case: Parabolic motion, circular motion


This article is from the "Wang Qinque" blog, make sure to keep this source http://wangqingkai.blog.51cto.com/9235701/1982507

Algorithms and data structures

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.