Algorithm and data structure,

Source: Internet
Author: User

Algorithm and data structure,

At present, computers have gone deep into every field of social life. They are Web Front-end applications, and their applications are no longer limited to scientific computing, but more for control, management, data processing, and other non-numerical computing fields. Computer is a science that studies Information Representation and processing using computers. There are two problems involved: Information Representation and information processing.

Information Representation and organization are directly related to the efficiency of information processing procedures. With the complexity of Web application problems and the rich functions of front-end pages, information increases dramatically and information ranges are extended, making the scale and structure of many WEB applications quite complex. Therefore, the features of objects to be processed and the relationships between objects must be analyzed. This is the data structure.

The general process of compiling a program to solve the actual problem:

L how to describe the problem in the form of data? -- Abstract An appropriate mathematical model from a problem

L The data volume involved in the problem and the relationship between the data

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

L what operations should be performed on the data to handle the problem?

L is the program compiled with good performance?

The problems listed above are basically solved by the data structure we learned today.

Qianfeng "HTML5 programmers" training camp is the best training base for full-stack engineers and architects in China. "algorithm and data structure" is one of the core courses in the second phase of the current curriculum system (V6.5.

Full-stack engineers need to understand algorithms and data structures. No matter which computer language you use, as long as you are a programmer, algorithms and data structures are the core of your requirements and the cornerstone of front-end developers. On the basis of mastering the front-end, you can gain an in-depth understanding of algorithms and data structures, better design and R & D from the full stack perspective, improve web performance, and gain access and experience from more users.

How to teach about algorithms and data structures? The following points are highlighted:

First, step by step. Focusing on concepts, functions, and usage, the teaching philosophy is dominated by students and supplemented by teachers. It guides students to solve their own problems and quickly improve and apply algorithms and master data storage and data processing methods.

Second, project-driven. Based on the project-driven teaching method and from a real project, this method stimulates students' interest in learning and is interest-oriented. It helps students master the project development process and project operating principles and improve the project operation efficiency.

Third, focus on practice. This allows students to constantly improve and sublimate project problems, summarize excellent algorithms, and cultivate the ability to develop and solve problems independently.

The algorithm and data contain the following two parts:

Part 1: algorithm. Common algorithms in this section include:

Recursive Algorithms. The content mainly includes the recursive idea, the role of recursion, and the implementation of recursion.

Sort algorithms. The content mainly includes sorting algorithms such as Array. prototype. sort (), insertion sorting, Bubble sorting, selection sorting, fast sorting, heap sorting, Merge Sorting, and Hill sorting.

When it comes to frontend sorting, we naturally think of the native JavaScript interface Array. prototype. sort.

This interface exists since ECMAScript 1st Edition.

Array. prototype. sort Specification

The elements of this array are sorted. the sort is not necessarily stable (that is, elements that compare equal do not necessarily remain in their original order ). if comparefn is not undefined, it shoshould be a function that accepts two arguments x and y and returns a negative value if x <y, zero if x = y, or a positive value if x> y.

Obviously, the specification does not limit what sort algorithms are implemented in sort. Even the implementation of interfaces does not require stable sorting.

In this context, the frontend sorting depends on the specific implementation of various browsers.

Insert sort

Thought: Insert a record to the sorted table to obtain an ordered table with a new number of records increasing by 1. That is, we first regard the 1st records of the sequence as an ordered sub-sequence, and then insert them one by one from 2nd records until the whole sequence is ordered.

Optimal complexity: when the input array is sorted, the complexity is 0 (n)

Worst complexity: when the input array is in reverse order, the complexity is 0 (n ^ 2)

Insert sorting is suitable for "arrays with a few elements"

Bubble Sorting

Thought: through two-to-two exchanges, like bubbles in the water, small ones come out first, and big ones come out later.

Worst run time: 0 (n ^ 2)

Optimal running time: 0 (n ^ 2)

Select sort

Thought: In the number of groups to be sorted, select the minimum (or maximum) number to exchange with the number of 1st positions, and then find the minimum (or maximum) number among the remaining values) and so on until the nth element (second to last) and NTH element (last number) are compared.

Best run time: 0 (n ^ 2)

Worst run time: 0 (n ^ 2)

Quick sorting

Algorithm steps:

1. Pick out an element from the series, which is called a "benchmark ",

2. Re-sort the series. All elements are placed before the benchmark values smaller than the benchmark values, and all elements are placed behind the benchmark values larger than the benchmark values (the same number can come to either side ). After the partition exits, the benchmark is in the middle of the series. This is called a partition operation.

3 recursively sort the subseries smaller than the reference value element and the subseries greater than the reference value element.

The bottom of recursion is that the number of columns is zero or one, that is, they are always sorted. Although this algorithm is always recursive, it always exits, because in each iteration, it will at least place an element at its final position.

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

Optimal running time: 0 (nlgn)

Heap sorting

Optimal Time: 0 (nlgn)

Worst Time: 0 (nlgn)

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

Merge Sorting

Thought: Use the separation and Control Method to Solve sorting problems

Worst case running time: 0 (nlgn)

Optimal running time: 0 (nlgn)

Divide and conquer: it refers to dividing the original problem into multiple independent sub-problems, and the form of these sub-problems is similar to that of the original problem, but the scale is reduced, after the sub-problem is solved, the combined results constitute the solution of the original problem.

Hill sorting

Idea: first, the entire record sequence to be sorted is divided into several sub-sequences for direct insertion and sorting. When the record in the whole sequence is "basic order, then, all records are inserted and sorted in sequence.

Part 2: Data Structure. Common data structures.

Linked List:

Chain storage: stores data elements in a linear table with any group of storage units. Linear table stored in this method is short for Linear Linked List.

Any level-1 storage unit of the node in the storage linked list can be continuous or discontinuous, or even scattered in any location in the memory.

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

To correctly represent the logical relationship between nodes, you must store the address (or location) indicating the direct successor node while storing each node value, which is called a pointer or chain, these two parts constitute the node Structure in the linked list.

The linked list links n nodes of a linear table in the logical order through the pointer field of each node.

Each knot contains only one linked list of pointer fields, which is called a single-chain table.

Stack and queue are two widely used data structures. They all come from linear table data structures and are linear tables with limited operations.

Stack can be implemented in multiple ways in a computer:

Hard Stack: It is implemented by using some Register Groups in the CPU or special areas of memory used by similar hardware. This type of stack has limited capacity but is fast

Soft Stack: This type of stack is mainly implemented in memory. The stack capacity can be very large. In terms of implementation methods, there are two dynamic and static methods.

STACK: a linear table that is limited to insert and delete operations at one end of the table. It is also known as a forward, forward, or Backward Linear table.

Queue: it is also a linear table with limited operations. Is a first-in-first-out linear table. You can only insert at one end of the table and delete at the other end.

Trigonometric function:

(1) The essence of trigonometric functions is the ing between the set of any angle and the variable of a specific ratio set.

(2) six basic functions: sine, cosine, tangent, cotangent, forward cut, and remainder cut.

(3) In the Cartesian coordinate system of the plane, a ray 0 p is drawn from point 0, and the rotation angle is θ. The coordinates of point p are (x, y): (oblique side c, the opposite side is a, and the adjacent side is B)

1. sine function sin θ = a/c sine (sin): opposite edge ratio of angle a Oblique Edge

2. cosine function cos θ = B/c cosine (cos): adjacent edge ratio of angle a Oblique Edge

3. tangent function tan θ = a/B tangent (tan): the adjacent edge of corner

4. cotangent function cot θ = B/a cotangent (cot): adjacent edge of corner

5. Forward cut function sec θ = c/B forward cut (sec): The oblique side of corner a is adjacent to the adjacent side.

6. The remainder cut function csc θ = c/a remainder cut (csc): Oblique Edge of angle a compared edge

Cut-off Theorem

In a right triangle, the sum of squares of the two straight edges is equal to the square of the Oblique edges. In the Right Triangle ABC, where the angle C = 90 °, the length of Direct Edge BC is a, the length of AC is B, and the length of Oblique Edge AB is c, then there is a 2 + B 2 = c 2

Implementation case: parabolic motion and circular motion

 

Related Article

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.