Data Structures and Algorithms Reading Notes
1. Doubt: What are data structures and algorithms? Is it useful?
Data Structures: Arrays, Linked Lists, Stacks, Binary Trees, Hash Tables
Algorithms: Manipulation of data in structures
The role of algorithms and data structures: Real-world data storage (storage of home addresses) Real-world modeling (graphs) Programmer tools
Algorithm Overview: Add, Delete, Search, Traverse, Sort, Recursion
Terminology: database records field keywords (qualifiers bring out records, records contain all fields, and all records constitute a database)
Problems with procedural language:
Lack of correspondence between programs and the real world
There is a problem with the internal structure of the program,
Emphasis on methods, not on data, rough data organization structure,
Object characteristics:
Objects contain both methods and fields
A class is a description of an object
To create an object, use new with the name of the class
.call the method of the object
Class library for Java data structures: java.util.*
2. Array
What's so good about arrays?
Features: The data items are known, the length of the array is fixed, the non-empty data items are stored continuously, and there cannot be empty ones.
Insert fast (data item)
Lookup is slow (n/2)
delete slow (n/2 find n/2 move)
Comparison between algorithms with duplicate values allowed and algorithms with no duplicates allowed
Don't be in a hurry: the slow but methodical nature of algorithms
Basic knowledge of arrays in Java: who is responsible for indexing an array, and what is the caller concerned about?
Hidden data structures perform their own duties arr.setEle(k,arr.getEle(ke+1)) evolved to arr.set(value)
Sorted array:
Linear search: if you find a larger than yourself, exit the query
Binary search: Binary search significantly improves speed log2n logarithm
Fast query, slow insertion
Comparison of Algorithms, Big O Notation: O(1) O(logN) O(N) O(N Squared)
Unordered array insertion: constant
Linear query: proportional to N
Binary search: proportional to logN
Why not use an array to represent everything? Caused by the shortcomings of the array, slow, fixed length
3. Simple sorting
Where are computers inferior to humans? Not smart enough
Bubble sort: bubbling, bubbling, as the name suggests, what a bubbling method: compare the most and put it on the edge
Algorithm efficiency: (n-1)+(n-2)+(n-3)...+1=n*(n-1)/2 O(n2) level
Immutability: the data items to the right of out are always ordered
Insertion sort: partially ordered, partially unordered
Number of comparisons: a probability theory perspective. Maximum: n*(n-1)/2 Average: n*(n-1)/2/2 Minimum: 1/2 less comparison than bubble sort
Invariance: data items smaller than the subscript of the outer variable are locally ordered
Collation: compareTo() method
Algorithm performance comparison rules: Big O notation
Algorithm stability: Data items with the same key are sorted multiple times, and their order remains unchanged, and such sorting is stable
Invariance: = regularity
4. Stacks and queues, priority queues. Only do one thing before you can do another
Different uses: array--database stack queue as a programmer's tool
Restricted access: array--any access, only one data item can be operated on the stack queue at a specific time
More abstract: can be based on other data structures
Stack: 3*(4+5) is very hanging, just a concept, abstract
Incisive: low-priority items are pushed to the bottom of the stack, waiting to come back for execution
Stack capacity: small
Examples of stacks: reverse, delimiter matching
Efficiency: O(1)
Queue: The movement of the queuing pointer improves efficiency
Circular queue: "buffer ring" continuous sequence broken sequence
When a large number of insert and remove operations, data item statistics affect performance
IsFull, isEmpty queue implementation without data item count field? logic, brain
Efficiency: O(1)
Deque: Versatile = Deque + Stack + Queue.