The main data structures java

A. Array

The same set of types of elements; gives a continuous space in the memory.

Compared to the list in terms of advantages and disadvantages:

advantage:

1) query faster, because the array size is fixed and is a continuous memory space, the elements need only locate a query on a particular piece of memory; and the list of non-continuous memory space, by the front and rear pointers associated order, the list of query elements slower

 

Disadvantages:

1) a fixed size, convenient to add dynamic data (dynamically add or delete data will affect the majority of the array elements, lower than the efficiency of a linked list); (the list can be dynamically add, delete data, high efficiency because the data before and after the list is associated with a pointer , add or delete an element affects only around two associated elements)

java in the array is a fixed length, the length can not be dynamically increased. If you want to expand the array, only by redefining the array, copy the contents of the old array to the new array.

 

II. Stack

Also known as the stack, which is a linear table operation is limited; only insertions and deletions in the table section, the end of the stack is called;

The latter is advanced out of the stack data structure.

 

III. Queue

Queue stack and the like is a linear table, except that it allows the insertion of the front end of the table, be deleted at the end of the table, the latter is advanced out of the linear table.

 

IV. List

List storage unit is a physically non-sequential, non-continuous sequence of logical storage structure, data elements are linked by a pointer order linked list implementation.

List consists of a series of nodes, each element of the list is called a node, a node may dynamically generated at run time, each node comprising two parts: a data field storing data elements, and the other is a next node address storage the pointer field; compared to linear operation table, more complicated.

Advantages and disadvantages:

advantage:

Was added to the list or delete elements speed is relatively fast, because the list pointer operation is carried out by adding or removing elements and affect only a front or a related element, without affecting other elements; and if the array add or delete elements, most of the elements will affect the entire array, for example, to delete an array with 10 elements in the third element, then it is imperative array 4 through 10 elements are left a.

 

Disadvantages:

Discover more slowly, since the list is linked through pointers before and after the data elements, a query from the array elements is not as a continuous query faster memory.

 

------------------------------------------------------------------------------------------------------------------------------------------------------------

ArrayList和 LinkedList

1.ArrayList data structure is implemented based on dynamic array, LinkedList based linked list data structure. 
2. For random access get and set, ArrayList LinkedList superior, because LinkedList to move the pointer. 
3. For new and delete operations add and remove, LinedList comparative advantage, because ArrayList to move data.

Summary: internal ArrayList is to use zo-length arrays to achieve, it is a get and set methods are spending a fixed time, but if insert elements and remove elements, unless the insertion and deletion position in the table at the end, otherwise the code overhead will be very large, because the need to move inside the array.
LinkedList is implemented using a doubly-linked list, so get will be very resource consuming, unless the position of the head from close. However, insert and delete elements takes constant time.

 

 

V. tree

Less exposure practical application, the concept of:

And only a specific called the root (Root) node; when n> 1, the remaining nodes can be divided into m (m> 0) disjoint finite sets T1, T2, ..., Tm, each set Ti (1≤i≤m) are tree, and T is called a sub-tree (subTree).
  

 

VI. Hash table

The HashTable (hash table) is an implementation of the Map interface, a linear table is a special storage structure; key-value pairs in a manner of storing data, wherein the key can not be repeated, the value may be repeated.

The main difference is that HashMap and HashTable 

1) HashTable are thread-safe, while HashMap is not thread safe

2) HashMap allows null keys, HashTable allowed


 

Seven heap:

java heap is available to get new part of programmers of computer memory. The heap data structure of binary tree is a special (heap is a tree, as compared to the array, the insertion speed fast reactors, but slow deleted).

Heap data structure is a binary tree having the following characteristics:

1. It is a complete binary tree, that is, except the last one node of the tree need not be full, the other from left to right of each layer must be full.

2. It is often implemented using arrays.

3. Each node heap stack satisfy the condition, that is to say for each keyword value greater than or equal key values ​​child nodes of this node.

 

 

Eight array, list, set of interchangeable:

1. Converts an array list

String array={"aaa","aaa","bbb"};

List list = Arrays.asList(array)

After conversion list contains three elements

 

2. list turn set

Connect examples:

HashSet hashset=new HashSet(list);

After conversion, the original list of the repeated elements will be removed, HashSet contains only two elements

 

If you need to re-array, by converting the array into a set manner

Published 11 original articles · won praise 2 · views 10000 +

Guess you like

Origin blog.csdn.net/zhengyin_tmac/article/details/87205922