Diary 12-20 on GitHub to find the biggest subroutines and projects

Source: Internet
Author: User

I'd like to see that guy on GitHub is about how a C program is tested, and the arrangement of files.

Yesterday began, and later to get this, make it messy, tomatoes will help themselves out of the cycle of death, the goals and tasks noted to remind themselves.

is to use the timing function in the library function to measure the computational time learned by different methods. This is quite a good way, I have tried to compare some algorithms, such as various sorting algorithms, the time spent, forget what method was used at that time.

In this project, the man used the 10*100 array as the experimental data, giving the initial value, a large piece. It's not easy.

Using an array, in the initial value, stores the number of data that needs to be measured each time, can apply the loop, simplifies the program. Arrays, like structs, are very basic, yet very useful data structures.

In addition to the test procedures, test results files, the project also has reports, feel very fun, copy the following:

Maximum Subarray Project Report

1. Mathematical analysis

1.1 Psuedocode

1.1.1 Enumeration Pseudocode

Enumeration (A:array of integers)
max =-infinity
n = Length (a)
For i = 0 to n
sum = 0
For j = i to n
For k = i to K = j
Sum + = A[n]
If sum > Max
max = Sum
Return Max

1.1.2 Better Enumeration Pseudocode

Betterenumeration (A:array of integers)
max =-infinity
n = Length (a)
For i = 0 to n
sum = 0
For j = i to J < n
Sum + = A[j]
If sum > Max
max = Sum
Return Max


1.1.3 Divide and Conquer pseudocode

Divideandconquer (A:array of integers, lo, hi)

Base case
If lo = = Hi
return A[hi]

Recursive case
Midpoint = (Lo+hi)/2

Left side
Leftmax = Divideandconquer (A, lo, midpoint)

Right side
Rightmax = Divideandconquer (A, midpoint+1, HI)

Crossing both sides
Left side
Leftbothmax =-infinity
For i = midpoint to I >= 0
Leftbothsum + = A[i]
If Leftbothsum > Leftbothmax
Leftbothmax = Leftbothsum
Right side
Rightbothmax =-infinity
For i = midpoint to I >= 0
Rightbothsum + = A[i]
If Rightbothsum > Rightbothmax
Rightbothmax = Rightbothsum

Bothmax = Leftbothmax + Rightbothmax

Return Max (Bothmax, Leftmax, Rightmax)

1.2 Asymptomatic Analysis

1.2.1 Enumeration

Let the array size is n.
There is three nested loops.
For the first loop, the amount of work is n.
For the second loop, there are n-i work.
For the third loop, there is N-i-J
Total work is n (n-i) * (N-J)
= n^3 + an^2 + Bn +c
Therefore, enumeration is O (N^3)

1.2.2 Better Enumeration

Let the array size is n
There is nested loops
For the first loop, the amount of work is n
For the second loop, the amount of work is n-i
Therefore The total work is n*n-i = n^2 +ni
Thus, Better enumeration is O (n^2)

1.2.3 Divide and Conquer

-recursive part
Let n is the array size
For each level of recursion, the array size is halved.
Therefore, this portion of the algorithm is O (LOGN)

-iterative part
There is sequential loops.
Both loops was N/2, therefore the combined work is N.
Therefore, the iterative part is O (n)

-complete algorithm
Combined, the complete algorithm is:o (NLOGN)

2. Theoretical correctness

Claim:divideandconquer correctly returns the sum of the subarray with the largest sum.

Proof:for an array A, let P (a) is the statement that Divdeandconquer (A, lo, HI)
Correctly finds the greatest subarray. We'll prove that P (A) is true using induction.

As a base case, consder when | a| is 1. The only element is the greatest subarray.

As an induction hypothesis, suppose. P (A) is true for all lists of length < n where length >= 1; That's,
Suppose that for any array A of length < N, Divedeandconquer would correctly return the sum of the greatest subarray.

Now, consider an array A of length < N.

3. Testing

4. Experimental analysis

5. Extrapolation and interpretation

Diary 12-20 on GitHub to find the biggest subroutines and projects

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.