Open Course Study Notes-[Harvard] Computer Science CS50 (IV)

Source: Internet
Author: User

Course Merge Sorting-2011.10.27

The efficiency of Bubble sort is still low. The measurement efficiency includes space occupation and CPU cycles. The sorting condition is measured by the worst condition, such as reverse order. Merge Sort is highly efficient.

Merge Sort (Merge Sorting) is described in detail. It is easy to implement using the recursion (recursion) method. The algorithm is as follows:

Sore (){
If (n <2)
Return
Else
Sore () left half
Sore () Right Half
Merge () combines the left and right semi-ordered sorting
}

Use Time: T (n) = T (n/2) + T (n/2) + n; if n> 1; T (n) = 0, if (n = 1), the total efficiency is O (NLogN ).

Lesson 1 pointer-2011.10.28

Design, it is very important to have a good user experience, not just correct work.

This section describes pointers. For example, int X a = & B; int temp = * a; (pointer a refers to content, that is, B ).

For memory, from top (low address) to bottom (high address), first static allocation, gobal and static data, static allocation at the beginning of the program; under is the dynamic allocation of space in the operation, known as heap, is the control allocated in C through malloc or Java through new. Finally, stack is allocated from the bottom up. It is automatically allocated during running. It is used for the storage space of functions or methods. When a function is called, a space is allocated to it on the stack, store related local parameters. Since the heap is from top to bottom, the stack is from bottom to top. If there is no space, overflow will occur and a Core segment error will occur in C. In general, the C language uses stacks to store the function return address/Stack callback base address, complete function parameter transfer, and store function local variables.
If the program needs to dynamically allocate memory during running, Heap can be used.

Related Links: My articles related to programming ideas

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.