The collection framework in Java is actually the encapsulation of the realization of data structure;
Reference: ren xiao Dragon teaching video
1, what is a data structure?
The data structure is the way that the computer stores it and organizes it;
Data structure refers to the collection of elements of one or more specific relationships between each other;
Typically, a well-chosen data structure can lead to higher operational or storage efficiency,
Data structures are often associated with efficient retrieval algorithms and indexing techniques.
2, basic function of data structure
Add (Create) Delete (delete) change (Update) Check (Read)
3, common data structures
3.1, array of arrays;
Arrays are the simplest data structures and are collections of the same data type .
To analyze the performance of an array from additions and deletions:
Increment: It is convenient to add elements in the last position of the array, but if you want to add elements in the first position is very troublesome, all the elements behind should be moved in the whole, the capacity is not enough to expand;
Delete : It is convenient to remove the last element of the array, but it is troublesome to remove the element from the first position, and all the elements behind it will be moved forward;
Change: Modify the specified subscript element as long as the operation can be;
Check: If the query specifies the subscript element as long as the operation, if the query specifies the subscript of the element, you need to use a linear search (find each),
Comprehensive: The performance of array modification is relatively high, and the performance of adding and deleting is relatively low;
3.2 Linked list linked list;
A linked list represents the relationship of the previous node and the next node by reference;
1 "single point list//can only traverse from the beginning to the end/only from the tail to traverse the head
The next node is stored by next, and node next represents the next node;
2 bi-directional list//can be traversed from the beginning to the end, but also from the tail to traverse the head
The previous node is represented by Prev, and Node prev represents the previous node;
Analyze the performance of the linked list from additions and deletions:
increment: A doubly linked list can get the first node and the last node directly. If the new element is in the first position or the last position, then the operation is only one time;
Delete : Remove the first element or the last element as long as the operation is done once;
change: There is no concept of subscript, need to traverse;
Check: There is no concept of subscript, need to traverse;
Comprehensive: The list of the added and deleting performance is relatively high, the performance is low;
3.3 Stack stack;
is a linear table with operation constraints, LIFO (LIFO);
Only add and remove elements at one end of the list, which is called the top of the stack, and the opposite end is called the bottom of the stack.
To add elements to a stack, also known as the stack or into the stack or into the stack, he is to put the new elements on top of the stack, making it a new stack top element;
Remove the element from a stack, also known as the stack, he is the top element of the stack is deleted, so that the adjacent elements become the top element of the stack;
Stack is based on the implementation of the array, subscript 0 is the element is the bottom of the stack, the last element is the top element of the stack;
3.4 Queues queue;
A queue is a special linear table, except that only the front end of the table is allowed to be deleted, and the back end of the table is added to the operation
Like a stack, a queue is a constrained linear table
The end of the insert operation is called the tail of the queue, and the end of the delete operation is called the team head;
One-way queue: First in and out (FIFO) can only be inserted from the end of the queue data, can only delete data from the queue header;
Two-way queue: You can insert data from the end of the queue/head, or delete data from the header/tail of the queue;
3.5 Hash Table Hash
In a general array, the position of the element in the array is random, and there is an indeterminate relationship between the value of the element and the position of the element;
Therefore, when the array looks for a value, it needs to compare the lookup value with a series of elements, and the efficiency of the query depends on the number of comparisons made during the lookup process;
If the value of the element (value) and the Subscript (index) in the array have a definite correspondence (hash),
Formula: index = hash (value);
Such an array is called a hash table, the most useful is to provide the efficiency of data lookup;
In general, the hash code (HASHCODE) is not used as the subscript for the array element, because the hash code is large and easy to cross, and can be mapped between the hash code and the subscript.
The array records the order in which the elements are added and allows the elements to be duplicated;
The hash table does not record the order in which the elements are added (the hash algorithm is ordered one by one) and does not allow duplication because if the elements are duplicated, the hash code values are equal and the subscripts are equal
Java Learning Summary-common data structures