Edx6.00 notes

Source: Internet
Author: User

Lecture 1

1. Basics of Computation

The most basic two things a computer can do:

  • Computing: What kind of computing? First, a series of basic operations (including simple computing, logic, testing, and data movement) built into the computer are the basic units used by the computer. Of course, this is far from enough. It depends on user-defined and efficient computing.
  • Storage

Excluding Time and Space factors, computers are also limited. For example, computing is too complex (such as weather prediction) or it is basically impossible to compute problems (downtime problems)

2. Types of knowledge

Declarative Knowledge: Facts

Imperative/procedural knowledge: the method of "How to do it. Is a way to discover new knowledge.

3. Basic machine architecture

Computational Thinking: divides the problem to be solved into a series of mechanical steps to solve the problem.

What should we do to convert the solution step (recipe) into the mechanical process of the computer?

  • A dedicated machine is built to solve a special problem. Such machines are called "fixed program computers", such as calculators, and bombe machines dedicated to cracking Enigma.
  • Build a computer that can do anything we want it to do. For example, the mouse spent a huge sum of money to build deep thought. calculate ultimate answer today, and calculate ultimate question tomorrow ...... this requires the storage and operation command sequence (Program), and then the program becomes the basic operation through the translator. These machines are called "storage program computers". Modern computers are designed based on this principle. (For this history, we recommend that you read "face-to-face office-commemorating the centennial birth of Alan Turing".)

Turing says that only six basic operations can be used to calculate any computing problems (Turing completeness ). In fact, modern programming languages have more convenient basic operation sets, and new basic operations can be obtained through method abstraction (functions.

4. Programming Language Characteristics

Syntax (syntax): defines the composition of expressions in the correct format (well-formed. If the syntax is incorrect, the machine can check it out.

Semantics (semantics): defines the meanings related to expressions.

  • Static semantics: syntactically valid and meaningful.
  • Formal Semantics: The syntax is correct, there is no static semantic error, and there is only one meaning (no ambiguity ). If an error occurs in this step, the machine cannot be found. It may stop running and report an error, or get stuck in an endless loop, or output an error.

Bytes ------------------------------------------------------------------------------------

Lecture 2

1. Types of programming ages

Low-level language: commands similar to the internal control units of computers are used. For example, if you want to calculate 1 + 2, the Assembly Language defines the address of two numbers in the storage system, move them to the register, and then add ...... (I have never learned assembly, please correct me) it is quite difficult to understand the internal structure of the computer. Wiki

Advanced Language: Abstraction of computer details. Compared with low-level languages, advanced languages are closer to natural languages for easy understanding and use. Now, just enter "1 + 2! Wiki

  • Compiled language: the abstract expression is converted into a lower-level code by compilation, and then translated and executed. Five phases of Compilation: lexical analysis, syntax analysis, semantic check, and intermediate code generation, code optimization, and target code generation. Source code → compiler → object code ). For example, the C language refers to the source file (. c/example ).
  • Interpreted language: a special program converts a source program into an internal data structure and directly converts each step into a low-level machine instruction. That is, a translation and an instruction are executed. For example, Java is a language that is compiled and then interpreted. The source program is converted to intermediate code (bytecode) by compilation. When the program is running, the virtual machine then interprets the bytecode as the machine command execution on a specific platform based on different platforms, that is, the so-called "platform independence ".

The difference between the two: the compilation language needs to be executed after all source code is converted to the machine language. It is inconvenient to check for errors and errors, but it runs fast. Although the explanation language runs slowly, it is easy to find the error point because it is executed while translating.

2. Python objects

The object type defines what the program can do for it.

3. Variables and naming

Create a connection between the variable name and value (stored in a computer) and write down these connections with a table.

4. String

Operator Overloading: uses the same operator for different tasks. For example, 1 + 2 is an addition, while '1' + '2' is a string connection. That is, let the operator determine its own function based on the different types of the object. (Return to the above definition of "type)

Bytes ------------------------------------------------------------------------------------

Lecture 3

There are three methods:

  • Exhaustive enumeration)
  • Bisection search: For floating-point values, if the exhaustive step is too large, the correct answer may be skipped. If the step is too small to run and slow, it is necessary to use the binary method. If the missing half is left half.
  • Newton-Raphson (also called the Newton Iteration Method)

Why can we get a better approximate value for the third Newton's method? Return to the high number of Taylor expand (cough) p (x) Taylor at the gpoint unfold take the first two items (the first two steps of the next step of the Shenma 2 Step 3 step n derivative are ignored) P (x) = (in fact, it is approximately equal to) P (G) + P' (G) (G-x), so that p (x) = 0.

Bytes ------------------------------------------------------------------------------------

Lecture 4-Function

1. Turing complete: If a series of rules for operating data have the computing power of a simulated Turing machine, it is completely Turing. For details, refer to Wiki (extended: Turing Machine). Using previous tools such as variable assignment, input and output, comparison, condition branches, and loops, any computing problems can be computed. At the same time, any problem that can be computed in a certain language can also be computed in other languages.

I wanted to write a graph engine, and then I found a cool article: Graph engine and NP

If you are interested, you can search for the church-Turing thesis topic)

2. Enviroment

Like variable assignment, after the function definition is submitted to shell, it is bound to the function name as a procedure object (process object identified by the identifier) in the environment (Variable-value table ).

When a function is called, internal parameter operations are performed in the new stage, regardless of the variables in the original environment.

If you think this concept is a bit abstract, codeskulptor has a very good function called viz mode. It provides visual debugging and can fully understand the variable storage and environment step by step. (FQ required)

 

To sum up the two features of a function:

  • Decomposition: divides the problem into independent modules and can be reused.
  • Abstract: A function can be regarded as a black box, and the user does not care about the details. You only need to provide valid input based on the specification of the function to obtain the corresponding results.

Bytes ------------------------------------------------------------------------------------

Lecture 5-Recursion

1. Recursive Algorithms

  • Recursive step-scale down a problem to the same version, but it is simpler
  • Basic events-scale down to a simple event that can be directly solved

The idea is the same as that of mathematical induction.

2. Using environments to understand Recursion

  • Every recursive call actually creates a new environment.
  • The binding between variables and values in each stage is independent and will not be changed by recursive calls.
  • After the return value is recursively called, the control flow returns to the previous stage.

3. Global Variables

Global variables can be seen or modified in many places beyond the function range, which will damage the local code.

Bytes ------------------------------------------------------------------------------------

Lecture 6-Object

1. Lists

The difference between lists and other objects (such as tuple, Int, float, STR) is that the object is mutable and internal elements can be modified.

2. functions as objects

First Class Object)

  • Type
  • It can be an element of some data structures (such as lists ).
  • Can appear in expressions (Value assignment, function parameters)

Functions are actually the first type of objects. This page may help you understand.

The method used to use functions as elements of the data structure is Higo-order programming (HOP) wiki.

Hop: map provided by Python (applies a function to every element of List)

3. Dictionaries

Is a generalized lists, element subscript is not necessarily an integer, it can be any immutable value (it can be tuple ). Index becomes a key that can be viewed. A set of <keyword, value> records forms a "Dictionary ". These records are unordered.

Bytes ------------------------------------------------------------------------------------

Lecture 7-Debugging

1. Test suites

During the test, we hope to use a set of inputs that can effectively reveal bugs, that is, to use a small amount of input to fully test the bug.

What input should I choose? We can divide the input fields into subsets (the input in each subset is equivalent to the input in correctness), and then select a representative from each subset as a test case. You can use the dividing points of the input domain to divide a subset. When dividing a subset, avoid additional, invalid, and repeated tests as much as possible.

2. black-box testing

Black box testing: A software testing method that tests the functionality of an application. In the tester's opinion, a program, like a black box, can only be used according to the specification (specification), but does not know the specific internal details of the program. The advantage is that you can avoid inherent bias from the perspective of general users. The test can be viewed from the following two perspectives:

  • General situation: According to the statement of procedure, what are possible typical events?
  • Specifically: What are possible extreme events?

3. Glass-box testing

White box test: A test of the glass box ". Compared with the black box test, the tester now knows exactly what the internal structure of the program is. Therefore, when designing the test case, try to go through every path.

Test rules:

4. test drivers and stubs

Unit Testing: tests each module. Algorithm errors may occur.

Integration Testing: Interaction errors between modules may occur.

Test drivers: a program used for testing. Create an environment, define a test set, test the operation, and generate reports. If other undebugged parts are used, use stubs to simulate the behavior.

Perform unit tests and overall tests repeatedly until the code is correct, and then perform a regression test (regression testing) to ensure that the previously functioning part is not damaged by any modifications.

Bytes ------------------------------------------------------------------------------------

Lecture 8-Assertions and exceptions

Assertion: This gives the program some preconditions for running it in a safe range and finally produces the expected results. The advantage of using assertions is that they are simple and crude. When an error is ruled out in advance (if the assertions are not satisfied, assertionerror is directly generated), you do not need to consider how to handle exceptions. Easy debugging. The disadvantage is that you need to check whether the assertions are correct repeatedly during the operation, which may reduce the efficiency.

Assertions should not be used during testing, or exceptions should be identified.

Assertions are generally used to check data types or certain constraints.

Bytes ------------------------------------------------------------------------------------

Lecture 9

How can you evaluate a program after it is compiled?

First, this program must be correct. Second, it must be efficient (especially in real-time control, "efficiency" is really critical). Efficiency includes two aspects: time and space. How to calculate the expected results as soon as possible within a limited space is the goal of our optimization programs and algorithms. The so-called "let the horse eat less and let the horse run fast" is also.

How can we measure the complexity of an algorithm? Let's look at the time complexity. The first thought is, "What is the specific running time of this program ?" There are three influencing factors:

  1. Different machine performance
  2. Different Python versions
  3. Different inputs

The first two factors use the ram model (which is the same as the theoretical model as the Turing Machine) to convert to measurements of the basic steps. The third factor is based on different inputs, it can also be divided into the best and worst cases. We examine the number of basic steps for Algorithm Execution in the worst case.

Assume that the problem scale of an algorithm is N, and the number of basic operations in this algorithm is F (N) (take the worst case) of N function. As N increases, we can see that F (n) shows an increasing trend in general, and we use this F (n) to measure the time complexity. We further introduce the big onote in mathematics. We define the time complexity of an algorithm as follows:

What is the meaning of this large OSN? Simply put, a relatively simple function is used to represent the progressive upper bound of the function. Generally, the highest order of the polynomial F (n) is used (the smallest order and the constant coefficient are ignored ). In addition to the big O symbol, there are also the big Ω symbol (opposite to the big O symbol, indicating the progressive lower bound) and the big Ω symbol (the large O and the big Ω take the middle)

Common time complexity ):

Bytes ------------------------------------------------------------------------------------

Lecture 10

The emergence of every classical algorithm may be the result of the Creator's painstaking efforts. For our common programmers, although it is difficult to create "new" effective algorithms (except for genius ......), however, we can stand on the shoulders of giants and break down each problem into small subproblems. Then, we can use the existing effective algorithms to solve each part and finally obtain the entire problem. This section mainly describes some selection and sorting algorithms:

1. Search

Including sequential search, binary search (half-fold search), and hash table

2. Sorting

Including selection and sorting, two-way Merge Sorting

There are still many common sorting algorithms, such as insertion sorting, Bubble Sorting (which is an exercise after class), fast sorting, heap sorting, and Hill sorting. If you are interested, you can find the data structure, or it's good to go to the course above Tsinghua. For more information, see:

  • Python implementation
  • Complexity Analysis

Python provides a sorted function for list. The algorithm used is timsort, which will be mentioned later in class.

 

There are two other knowledge points:

1. Ram model (Random Access Machine Model)

This RAM (random-access machine) is an abstract machine model. One of its most important features is that any storage unit can be accessed within a constant time.

Python provides an indirection mechanism to implement this feature (using pointers to indirectly point out the storage location of elements, similar to the indirect addressing of command systems)

2. When auxiliary space is used, a space (array) is allocated first, and then an element is inserted. What should I do if I want to insert data when the space is full? Method: allocate a new space, which is twice the size of the original space. Copy the original element to the new space and insert the new element. How efficient is this?

Data analysis shows that the ratio of the total running time of each segment to the time used to add new elements is basically <= 3, not related to the element scale N (equivalent to the constant time ). Here we use the idea of "amortized cost analysis", that is, in a series of operations, even if a certain operation costs a lot, the overall average price is still very small. That is to say, although the operation of "inserting new elements into a full space" is complicated, the larger new space is useful for subsequent insertion, so the average cost is not that high.

Edx6.00 notes

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.