Fifth Chapter Array
time: April 26, 2017 15:11:30~2017 April 26 15:15:54
Chapters: Chapter 05, section _01
Video Length: 09:30
content: Memory analysis of one-dimensional arraysExperience:An array in Java is a reference to the array stored in the type stack. The actual object is inside the heap memory(c and C + + are allocated in the stack)Memory Graph:
element is an array of reference data types
An array of reference types such as
time: April 26, 2017 15:16:22~2017 April 26 15:19:00
Chapters: Chapter 05, section _02
Video Length: 05:25
content: Creation and use of array elementsExperience:allocate space First, then add content to itStatic initialization: Allocates space and assigns values to array elements while defining arraysfor example, int a[]={3,2,4}Java array Subscript starting from 0
time: April 26, 2017 15:19:17~2017 April 26 15:55:10
Chapters: 05 chapters _03-
05 Chapters _14 Festival
Video Length: 6:24 +11:29 + 1:14 + 18:27+2:22 +6:44 +22:56+9:44
+19:26 +3:04 +5:33 +9:33
contents: An array of exercises and some basic algorithms to explainExperience:details about the Main methodPublic static void Main (string[] args) {}array of String types used in the command line to output subsequent arguments
array of args[] outside the question: basic types are allocated in the stack space, if you want to force them into the heapwe need to wrap them up as objects. These packaging classes are stored in the Java.lang package.These packaging classes also encapsulate a number of ways to handle these data types. Practice topic: Enter 2,4,6,7,3,5,1,9,8 with the command line parameters aboveconvert to int type array and then output from small to large.Ideas:1. Enter these number of spaces separately at the command line first2. Then convert the string type array args[] in the main method parameter to int type can be converted by Integer.parseint method3. Sorting can be manually arranged such as bubbling select Insert Quick Row (there are some special finishing before ordering)here for the time being, in the other part of the notebookor the sort Array.Sort () that comes with JavaFinal Output rearrange the quick sort here to directly post the code written in my eclipse. Package
algorithm;
import Com.jhdx.uitl.usualMethod;
/* Algorithm idea: Select a number, with this number as the benchmark, the array is divided into divided, will be smaller than his left on his, bigger than he put on his right
* Then the same recursive operation on the left and right side of the decimal group, until the array is ordered
* */Public class Quick Sort {public static int getmiddle (int[] array,int low,int high) {int Temp=array[low];
//Default the first number of arrays as the middle axis While (Lowwhile (low
//If the high number is greater than or equal to the middle axis number, push the high mark forward one high--; }Array[low]=array[high]; /
/push until the number is less than the middle axis, and switch the high number to low while (low
//If the low number is less than or equal to the middle axis number, push the low mark backward one low++; }Array[high]=array[low];
///the same goes until the number of the low mark is greater than the number of the middle axis, and the low number is changed to high }array[low]=temp;
//Put the middle axis number where it should be return low;} Public static void QuickSort (int[] array,int low,int high) {if (lowint Middle=getmiddle (array, low, high);QuickSort (array, low, middle-1);
//To split the low-order array again quickSort (array, middle+1, high);
//Double-split high-order array again }}Public static void Main (string[] args) {int Array[]=usualmethod.getrandomarray (1000000);Usualmethod.beforemethod (array);int low=0;int high=array.length-1;QuickSort (array, low, high);Usualmethod.aftermethod (array);}} here to tidy up the two-point lookup (binary find)not organized in the past. The first is the idea of arithmeticthought: binary Search, also known as binary lookup, is a highly efficient method of finding. binary Find the algorithm idea is to order the sequence (increment or decrement) arrangement, the search process using a jumping way to find, that is, the midpoint position of the ordered series is the comparison object, if the element value to find is less than the midpoint element, then the unknown origin sequence is reduced to the left half, otherwise the right half part. Reduce the lookup interval by half by a single comparison. Binary lookup is an efficient way to find. It can significantly reduce the number of comparisons and improve search efficiency. However, the prerequisite for binary lookup is that the data elements in the lookup table must be ordered.
The advantage of binary lookup method is that the number of comparisons is small, the searching speed is fast, the average performance is good, the disadvantage is that the unknown Origin table is ordered and the insertion and deletion is difficult. Therefore, the binary lookup method is suitable for an ordered list that does not change frequently and finds frequent. It's easy to say it's just a little bit of guessing game when you're a kid. You tell him it's big or small, and then you're guessing half the time, so you can guess quickly . Public class BinarySearch {
/**
* Binary search algorithm
* @param Srcarray ordered array
* @param key to find elements
* @return Key array subscript, not found return-1
*/
public static void Main (string[] args) {
int srcarray[] = {3,5,11,17,21,23,28,30,32,50,64,78,81,95,101};
System.out.println (Binsearch (srcarray, 0, Srcarray.length-1, Bayi));
}
//Two points find recursive implementations
public static int binsearch (int srcarray[], int start, int end, int key) {
int mid = (End-start)/2 + start;
if (srcarray[mid] = = key) {
return mid;
}
if (start >= end) {return-1;} else if (Key > Srcarray[mid]) {
//Returns a large array or a decimal group based on the criteria
//Then call yourself again by recursionreturn Binsearch (Srcarray, mid + 1, end, key);
} else if (Key < Srcarray[mid]) {
return Binsearch (Srcarray, start, mid-1, key);
}
return-1; }
//Two min find common loop implementationpublic static int binsearch (int srcarray[], int key) {
int mid = SRCARRAY.LENGTH/2;
if (key = = Srcarray[mid]) {
return mid;
}
int start = 0;
int end = srcarray.length-1;
While (start <= end) {
mid = (End-start)/2 + start;
if (Key < Srcarray[mid]) {
end = mid-1;
} else if (Key > Srcarray[mid]) {
start = mid + 1;
} else {
return mid;
}
}
return-1;
} } about the advanced discussion:
Pros: asl≤log2n, that is, every time a comparison is done, the look-up range is reduced by half. The search process can be completed by log2n.
Cons: Because of ordered order, it is necessary to order the search sequence, and to sort all data elements by size is a very time-consuming operation. In addition, sequential storage structure of the insertion, deletion operation is inconvenient.
consider: the ability to discard more parts through a comparison (that is, after a comparison, so that the scope of the search is smaller), in order to achieve the purpose of improving efficiency. ......?
consider combining the two methods (sequential lookup and binary lookup), that is, order lookup simple and binary find efficient, to achieve the purpose of improving efficiency? In fact, this is the algorithm idea of block lookup.
time: April 26, 2017 16:00:04~2017 April 26 16:10:34
Chapters: 05 chapters _15
05 Chapters _16 Festival
Video Length: 13:00 +14:49
content: Two-bit arraysExperience:int a[][]={{1,2},{3,4,5},{7,8,9}};the Declaration and initialization of multidimensional arrays in Java should be from high latitude to low latitudememory graph can be seen in memory first to allocate high-dimensional to continue to point to the low-dimensional
This can be dynamically initialized
about copies of arraysPublic static void Arraycopu (Object src,int srcpos,object dest int destpos, int length)Several parameters are copies of the array, the starting position, the location of the array to be copied, the starting position, the length of the copyis to change the location of the point directly through the memory address copy I used this method to sort the inserts before, so I'm more familiar with the number of inserts.
//Algorithm Sectionfor
(int i = 0; i < Array.Length; i++) {For
(int j = 0; J < i; J + +) {
if (Array[i]<array[j]) {
int temp=array[i];
system.arraycopy (Array, J, array, j+1, i-j);//copy array, copy from J sequence to j+1, make a seat, subscript is J
array[j]=temp;
}
}
}
time: April 26, 2017 16:10:40~2017 April 26 16:12:30
Chapters: Chapter 05 _17
Video Length: 00:51
Content: SummaryExperience:Summary of Knowledge pointsmemory layout of an arrayCommon Algorithms
Java Fundamentals Secondary Learning--fifth chapter array