Student ID 20182317 2019-2020-1 "Object-oriented programming and data structures," the eighth week of learning summary

Student ID 20182317 2019-2020-1 "Object-oriented programming and data structures," the eighth week of learning summary

Learning content summary

Three commonly used search algorithm (sequential search search, binary search, binary sort tree to find)

1. sequential search

For an array, the order given comparison value, the time complexity of 0 (n) ,, the following are achieved:

public static int Linear_Search(int[] data, int key) {
        if (data == null || data.length <= 0) {
            return -1;
        }
        for (int i = 0; i < data.length; i++) {
            if (data[i] == key) {
                return i;
            }
        }
        return -1;
    }

Binary search

Binary search for efficient lookups have been ordered sequence, time complexity 0 (n) ,, the following are achieved:

public static int binarySearch(int[] data, int key) {
        if (data == null || data.length <= 0) {
            return -1;
        }
        int low = 0;
        int high = data.length - 1;
        while (low < high) {
            int mid = (low + high) / 2;
            if (data[mid] == key) {
                return mid;
            } else if (data[mid] > key) {
                high = mid - 1;
            } else if (data[mid] < key) {
                low = mid + 1;
            }
        }
        return -1;
    }
 
    /**
     * 二分查找的前提是有序,递归
     * 
     * @param data
     * @param key
     * @return
     */
    public static int recursiveBinarySearch(int[] data, int low, int high, int key) {
        if (data == null || data.length <= 0) {
            return -1;
        }
        if (low < high) {
 
            int mid = (low + high) / 2;
            if (data[mid] == key) {
                return mid;
            } else if (data[mid] > key) {
                recursiveBinarySearch(data, low, mid - 1, key);
            } else if (data[mid] < key) {
                recursiveBinarySearch(data, mid + 1, high, key);
            }
 
        }
        return -1;
    }

Bubble Sort

Bubble sort: that is, from the array to be sorted in Comparative each adjacent two times the size of the numbers, the numbers in front of a small, large numbers on the back; first pass operation is repeated until the sorting is completed.

  • Bubble sort sorted below


public class BubbleSort {

  public static void main(String[] args) {
      int[] myArray = {18,91,38,77,36,55,74,30,2,41};
      System.out.println("排序前的数组为:");
      for(int i=0;i<myArray.length;i++) {
          System.out.print(myArray[i]+" ");
      }
      
      //冒泡排序算法
      for(int i=0;i<myArray.length-1;i++) {
          for(int j=0;j<myArray.length-1-i;j++) {
              if(myArray[j]>myArray[j+1]) {
                  int temp = myArray[j];
                  myArray[j] = myArray[j+1];
                  myArray[j+1] = temp;
              }
          }
      }
      System.out.println();
      System.out.println("排序后的数组为:");
      for(int i=0;i<myArray.length;i++) {
          System.out.print(myArray[i]+" ");
      }
  }

}

Selection Sort

Selection sort: is the time to find the minimum (or maximum) from the array to be sorted in a group is then replaced with the starting position of the sequence, and so on until a good sort the array to be sorted so far.

  • Selection Sort presentation below

public class SelectionSort {
 
    public static void main(String[] args) {
        int[] myArray = {18,91,38,77,36,55,74,30,2,41};
        System.out.println("排序前的数组为:");
        for(int i=0;i<myArray.length;i++) {
            System.out.print(myArray[i]+" ");
        }
        //选择排序算法
        for(int i=0;i<myArray.length;i++) {
            for(int j=i+1;j<myArray.length;j++) {
                int min = myArray[i];
                if(min>myArray[j]) {
                    int temp = myArray[i];
                    myArray[i] = myArray[j];
                    myArray[j] = temp;
                }
            }
        }
        System.out.println();
        System.out.println("排序后的数组为:");
        for(int i=0;i<myArray.length;i++) {
            System.out.print(myArray[i]+" ");
        }
    }
 
}

Textbook learning and problem-solving process

  • Question 1:
  • Problem 1 Solution:

  • Question 2:
  • Problem 2 Solution:

Code debugging and problem solving in the process

  • Question 1:
  • Problem 1 Solution:

Code hosting

(Run results screenshot statistics.sh script)


Last week exam wrong question summary

Last week, no exams
____

Pair peer review and

Grading

  • Based on score, I give this blog scoring: 14 points. Scores are as follows:
  1. Proper use Markdown syntax (1 point):

    • Do not use Markdown no extra points

    • A syntax error is not a plus (link does not work, does not form, the list is incorrect ...)

    • Typesetting confusion is not a plus

  2. Elements range (1 point) template
    • Missing "textbook learning and problem solving process" without points
    • Lack of "problem solving and debugging code in the process" without points
    • Managed code can not be opened without points
    • Missing "twinning and peer assessment" can not be opened without points
    • Missing "last week summed up the wrong title examination" can not be a plus
    • The lack of "progress bar" can not be a plus
    • Lack of "reference" can not be a plus
  3. Textbook learning and problem solving process, a problem 1 point

  4. Code debugging and problem solving in the process, a problem 1 point

  5. Week over 300 branches valid code (plus 2 points)
    • Submitted one week fewer than 20 times without points
  6. Other plus points:
    • Feelings, experience does not leave large empty 1 point
    • Typesetting fine plus one point
    • Progress bar records the learning time and improve the situation of 1 point
    • There are hands-on writing new code, add 1 point
    • After class choice has verified 1 point
    • Code Commit Message Specification 1 point
    • Learning the wrong questions in depth, add 1 point
    • Comments seriously, I can point out problems and blog code plus 1 point
    • Pair learning authentic plus 1 point

Comments had students blog and code

  • Pair this week learning
    • 20182318
    • 20182333
    • Pair learning content
      • Computational complexity of some of the progressive program
      • Some discussion and learning on the stack. Including a stack, stack, delete, etc.
  • Queue of some discussion and learning. Including lists and arrays queue, into the team, the team, etc.
  • Last week blog peer assessment case

After this week's study, I have knowledge who learned a deeper understanding of the data while applications such as searching and sorting methods are more familiar with, but also to understand some of the knowledge of the past can be described as not really understand benefited shallow.

Learning progress bar

The number of lines of code (add / accumulate) Blog amount (add / accumulate) Learning time (add / accumulate) Important growth
aims 5000 rows 30 400 hours
the first week 126/126 2/2 20/20
the second week 0/126 2/2 20/40
The third week 353/479 2/6 20/60
the fourth week 1760/2239 2/8 30/90
fifth week 1366/3615 2/10 20/110
Sixth Week 534/4149 2/12 20/130
Week Seven 2800/6949 2/12 20/150
Eighth Week

Reference material

Guess you like

Origin www.cnblogs.com/pytznb/p/11792407.html