20172333 2018-2019-1 "program design and data structure" Fifth week study summary

Source: Internet
Author: User

20172333 2018-2019-1 "program design and data structure" Fifth week study summary textbook Study summary = = "Java software structure and data Structure" chapter Nineth-sort and find = = First, find
    • ①. Find a concept: look for an element in a project or determine whether an element exists in the project.
    • ②. Type of lookup: Find in the Nineth chapter, we mainly discuss two types, one is linear lookup and the other is binary search.
    • ③. The target of the lookup: finding is actually a comparison between different elements, and the goal of finding is to find an element and maintain the most efficient performance while looking.
second, linear search method
    • ①. The concept of linear lookup: If the item is a list of a type, the implementation of the linear lookup method is to compare each value from beginning to end, until it is found or traversed to the last.
    • Linear Lookup

    • ②. Method implementation:

public static <T>           boolean linearSearch(T[] data, int min, int max, T target)    {        int index = min;        boolean found = false;        while (!found && index <= max)         {            found = data[index].equals(target);            index++;        }        return found;    }
three or two-point lookup method
    • ①. Two points Find concepts: binary search Each search reduces the existing group of elements by half the feasible candidates, greatly enhancing efficiency. Figure two points
    • ②. Two points to find the prerequisites: = = The element group should be sorted. ==
    • ③. Two-point lookup method implementation:
public static <T extends Comparable<T>>          boolean binarySearch(T[] data, int min, int max, T target)    {          boolean found = false;        int midpoint = (min + max) / 2;  // determine the midpoint        if (data[midpoint].compareTo(target) == 0)            found = true;        else if (data[midpoint].compareTo(target) > 0)        {            if (min <= midpoint - 1)                found = binarySearch(data, min, midpoint - 1, target);        }                else if (midpoint + 1 <= max)            found = binarySearch(data, midpoint + 1, max, target);        return found;    }
    • ④. Comparison between linear lookup and binary search:
      • The advantage of linear lookup is that it is simpler than binary search, = = debugging and programming easier = =. Linear find = = Do not need to sort the queue to use = =
      • The advantage of binary search: The time complexity of linear search is ==o (n) = =, the time complexity of binary lookup is ==o (log2 n) = =, in the increase of N, the efficiency of binary search is much higher than that of linear finding.
Iv. Sort
    • ①. Sorting Concepts:
      • 1. Sorting is the order of ascending or descending order of a set of elements according to a particular requirement.
      • 2. According to the efficiency divided into two kinds of sorting: sequential sorting, logarithmic sorting
      • 3. Sequential sorting is divided into three different ways according to the method: Select Sort, insert sort, bubble sort.
      • 4. Logarithmic sorting is divided into two types according to the method: fast sorting, merging sorting.

Five, sequential sorting

    • ① Select a sorting concept: iterate through all the elements of a list, place the largest or smallest element first, and then iterate through the list of other elements, repeating the operation until the last element. Choose

    • Code implementation:

public class SelectionSort {     public static void selectionSort(int[] a) {        int n = a.length;        for (int i = 0; i < n; i++) {            int k = i;                        for (int j = i + 1; j < n; j++) {                if (a[j] < a[k]) {                    k = j;                }            }                if (k > i) {                int tmp = a[i];                a[i] = a[k];                a[k] = tmp;            }        }    }     public static void main(String[] args) {        int[] b = { 49, 38, 65, 97, 76, 13, 27, 50 };        selectionSort(b);        for (int i : b)            System.out.print(i + " ");    }}
    • ② insertion Sorting concept: The use of this sort method is to start from the left second element to the left or the right to make a comparison, each comparison has two cases, if according to small to large row, the proposed element and its existing position on the left side of the element to the left, and the previous element backward one If an element is raised that is larger than its left position, the comparison of the element is stopped and the next element is compared.
    • Insert Sort method

    • Insert Sort Code Implementation:

public static void insertSort(int[] numbers)    {    int size = numbers.length;    int temp = 0 ;    int j =  0;        for(int i = 0 ; i < size ; i++)    {        temp = numbers[i];             for(j = i ; j > 0 && temp < numbers[j-1] ; j --)        {        numbers[j] = numbers[j-1];        }        numbers[j] = temp;    }    }
    • ③ Bubble Sorting concept: This sort method to some extent similar to the insertion sort method, the first step is the same as the insertion sort, is to compare an element with the left or right elements, if the premise of small to large, the left element is greater than the right element to the right one to continue the step, But once the element is less than the right, the element is fixed, the element that is just larger starts to compare to the right, and so on.
    • Bubble Sort Method

    • Bubble Sort Code implementation:

private static void bubbleSort(int[] sortNum)    {        int temp = 0;        for (int i = 0; i < sortNum.length-1; i++)         {                       for (int j = 0; j < sortNum.length-1-i; j++)             {                       if(sortNum[j+1]<sortNum[j])                {                                   temp = sortNum[j];                    sortNum[j] = sortNum[j+1];                    sortNum[j+1] = temp;                }            }        }    }
Five, logarithmic sort
    • ① Fast sequencing concept: This method introduces three important variables I, j, k,i = = = Left variable ==,j = = Right variable ==,k = = = Reference Value = =. The method starts with a selection of K (the first element is generally selected), (= = first traversal = =) and then the I variable is traversed from the left to the far right, each time I is the element with the reference value, if the element is greater than the base value of the base value of the interchange position. (= = Second Traversal = =) starts the reverse order of the elements less than the base value from the right until the leftmost. When the element to the left of the datum value is less than the base value, and the element to the right of the datum value is greater than the base value, then it is divided into two regions, and the above steps are continued until they cannot be separated for the two regions.
    • Quick Sort Method Diagram

    • Quick Sort Code implementation:

public class Quickdemo {public static void main (string[] args) {int[] arr = {5,2,4,9,7};    Sort (arr, 0, arr.length-1);        } public static void sort (int arr[], int. Low, int.) {int L = low;        int h = high;        int k = Arr[low]; while (L < h) {while (L < h && Arr[h] >= k {h--;                H=6} if (L < h) {int temp = arr[h];                ARR[H] = arr[l];                                ARR[L] = temp;            l++;            } while (L < h && Arr[l] <= k) {l++;                } if (L < h) {int temp = arr[h];                ARR[H] = arr[l];                ARR[L] = temp;            h--;        }} print (arr); System.out.print ("l=" + (L + 1) + "h=" + (H + 1) + "k=" + K + "\ n ");     if (L > Low) The IF (H < high) sort (arr, L + 1, high);
    • ② Merge Sorting concept: This method in my opinion is divided into three steps, the first step is the idea of splitting, a group of elements from the middle of the beginning to separate, until a single element, the second step is to separate the elements of the comparison. The third step is to compare the subsequent merges into a set of elements.
    • Merge Sort method diagram
Six, the base sort
    • Concept: This method will be sorted by the number of bits of the element, divided into 10 groups (0,1,2,3,4,...,9) first starting from the first point (that is, bits) placed in the corresponding group, and then according to the order from 0 to 9, and then the 10-bit placement, and then in the order of 0 to 9 to take out, Until the highest bits of these elements end
    • Straightforward picture explanation:
    • Single digit Sort chart

    • 10-bit Sort chart

    • Hundred Sort Chart

Problems in teaching materials learning and the solving process
    • Question 1: Insert sort and bubble sort there are many similarities between them in the sort process so who is better in terms of efficiency between them?
    • Answer: The time complexity of first inserting sort is O (n^2), and the time complexity of bubble sort is O (n^2). So the light is impossible to judge from the complexity of time, so can we directly define them to be of the same efficiency? Obviously not, in the writing process of pp9.3 clearly stipulated that the answer to the question, in the test can be seen at a glance, bubble sort takes less time than the insertion sort but the operand is much larger than the Insert sort chart comparison
      Bubble:
      Insert:

    • Question 2: Under what circumstances, the binary sorting method is more efficient than the sequential sorting method?
    • Answer: Because most of the methods of the binary sorting method are recursive implementation of the order, and the more data, the two-point ordering method time requirements are not high, and the order of the law has a large influence, if the specific to how many elements to judge 0 points, only specific problems specific analysis.

      Problems in code debugging and the resolution process
    • Issue 1: An out-of-scope issue was found when using the detection type that comes with the book. Figure

    • Resolution: After the debug found in the 5th time out of range, the back of the detection cycle conditions when the Fifth element is the seventh element in the comparison, the array is 0-6, No 7 will be error, slightly changed the conditions to solve the diagram

    • Question 2: When doing pp9.2, there is a picture of the output address

    • Resolution: After the inspection found that the use of sout when the variable is wrong to add a s on the problem. Figure

Code Hosting

-Figure Code

Last week's summary of the wrong quiz
    • No
Pairing and mutual evaluation

Based on the scoring standards, I give Linan's blog score: 7 points. The score is as follows:

Correct use of markdown syntax (plus 1 points)

Complete features in the template (plus 1 points)

Problems and solutions in textbook learning (plus 3 points)

Problem and resolution in code debugging, no problem

Feelings, experience real (add 1 points)

Reviews seriously, can point out the blog and the Code of the problem (plus 1 points)

reviewed the classmates blog and code
    • This week's study of the knot
      • 20172330 Linan
      • Pair of photos
      • Pairs of learning content
        • Find
        • Sort
Other (sentiment, thinking, etc., optional)

The idea is clear, it is uncomfortable to write.

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
Goal 5000 rows 30 Articles 400 hours
First week 0/0 1/1 10/10
Second week 0/0 1/2 10/20
Third week 1500/1500 1/3 10/30
Week Four 2761/4261 2/5 25/55
Week Five 814/5075 1/6 15/70
    • Java Programming and Data Structure Tutorial (second edition)

    • Tutorial on Java Programming and data Structure (second edition) Learning Guide
    • Quick sorting method of graphic interpretation
    • The cardinal Sort method clearly explains

20172333 2018-2019-1 "program design and data structure" Fifth week study summary

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.