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
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 + " "); }}
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; } }
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
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
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
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 |
|
20172333 2018-2019-1 "program design and data structure" Fifth week study summary