Algorithms and data structures

Source: Internet
Author: User
Tags time 0

? At present, the computer has been deep into all areas of social life, it is the Web front-end application, its application is no longer confined to scientific computing, and more is used in the control, management and data processing, such as 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:

How can 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

How to store data and reflect the relationship between data in a computer

What do I need to do with the data when dealing with problems?

Is the program you are writing in good performance?

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

The "HTML5 Programmer" training camp is the best training base for all-stack engineers and architects in the country, and "algorithms and data Structure" is one of the core courses in the second stage of the current curriculum system (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, it's natural to think of JavaScript's native interface Array.prototype.sort first.

This interface exists since ECMAScript 1st edition.

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: Inserting a record into a sorted ordered table to get an ordered table with a new record count of 1. 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 group of numbers to be sorted, select the smallest (or largest) number to exchange with the number of the 1th position, and then in the remaining number, find the minimum (or maximum) number of the 2nd position to exchange, and so on, until the first N-1 element (the penultimate number) and the nth element (the last number) is 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: The use of certain register groups in the CPU or a special area of memory for similar hardware. 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.

(c) In a planar Cartesian coordinate system, a ray 0p is drawn from point 0, with a rotation angle of θ,p point coordinates (x, y) are: (Hypotenuse C, the Edge is a, the adjacent edge is b)

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

2. Cosine function cosθ= b/c cosine (COS): Adjacent edge ratio hypotenuse of angle a

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 cutting function cscθ= c/a (CSC): Bevel edge of angle A

Pythagorean theorem

In right triangle, the square of 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

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.