The essence of the "algorithm path" is the classic algorithm, and the "algorithm path" Algorithm

Source: Internet
Author: User

The essence of the "algorithm path" is the classic algorithm, and the "algorithm path" Algorithm
The essence of "algorithm path" in the classic algorithm Section

  • This book is written by Yan hengming, the author has another book, "The string of data structures", and "the philosophical principles of operating systems ".
  • This book can be regarded as a simple example. The article is very good, and the author adds a lot of his own ideas.
  • This article includes the classic algorithm Section
Chapter 10 sorting and order
  • Insert sort
    • Extracts an insert ordered part from the unordered part.
    • In-situ sorting without occupying temporary storage space
    • In the optimal condition, it is O (n), and the average O (n ^ 2)
  • Semi-insert sorting
    • Use binary search during insertion
  • Merge Sorting
    • Divide and conquer, separate them from the middle, sort them, and then merge them carefully.
    • Sorting in different regions requires additional space
    • When n> = 30, the performance is better than the insertion sorting. Fixed complexity: O (nlog (n ))
  • Fast sorting
    • The complicated part of divide-based governance lies in decomposition, while merging is complicated.
    • In-situ sorting
    • The worst case is O (n ^ 2), but as long as it is not always the worst, the complexity is not n ^ 2, it is tough
  • For any sort based on comparison, the decision tree height must be at least nlog (n)
  • Count sorting
    • The element value range must be limited.
    • High space complexity
    • O (n)
  • Base sort
    • From the ranking bit to the highest sorting, each sorting uses a stable sorting, such as counting sorting.
    • Select log (n) bits for one-bit sorting to minimize the overall cost.
  • Sort buckets
    • Divides the nelement into n buckets by value, inserts and sorts each bucket, and connects each bucket first.
    • Elements should be evenly distributed
  • Quick order selection: Calculate the K-th number
    • Use the fast-forward partition
    • Worst O (n ^ 2), average O (n)
  • Selection of the least linear fast order
    • Set each of the five elements to the median value. Find the value in n/5 values as the partition of partition.
    • Why * not every 3 groups?
    • Make sure there are at least 3n/10 elements on the left side of the queue.
    • Worst O (n)
Chapter 2 search and hash
  • Sequential search
    • In the sequence, if the search frequency decreases exponentially from start to end, it is O (1)
  • Half-fold search
    • For an ordered sequence, it is O (logn)
  • Constant search: Hash search
    • Direct hash: Very simple, with no collision and a large waste of space
    • Division (Modulo Division) hash
      • The element is modeled on the size of the hash table m.
      • M must be a prime number; otherwise, uneven scattering may occur. For example, m contains the factor d, while most elements have equal remainder values for d.
      • M cannot be near the power of 2. If m is a power of 2, the hash result does not depend on all bits of the element. Not even close. Why?
    • Multiplication hash
      • H (k) = (A * k) % 2 ^ r> (w-r), w is the computer word width, A is 2 ^ (W-1) an odd number between 2 ^ w
      • Multiplication method: multiplication method n times (usually n = 2), and intermediate r bit
  • Open addressing hash: expands in depth during hash collision to add a linked list
    • The average search time is O (1 + a), and a is the loading factor.
  • Closed addressing hash: finds another position for the element during hash collision.
    • Finding another location is called a search
    • Linear Exploration
      • h(k,i) = (h'(k) + i) % m, H' (k) is the home location
      • Looking for unoccupied locations in the single direction
      • High-level aggregation
    • Nonlinear Exploration
      • Square Explorationh(k,i) = (h'(k) + c1 * i + c2 * i^2) % mSecondary Aggregation
    • Double hash Exploration
      • Two hash functions h1 and h2 are used to construct the new hash function.
      • h(k,i) = (h1(k) + i * h2(k) ) mod m
    • Pseudo-Random search
      • Use pseudo-random sequence
      • Secondary aggregation exists
    • The number of unsuccessful searches is expected to be1/(1-a)
    • The maximum number of successful searches is1 / a * ln( 1/(1-a))
    • Elements cannot be deleted when the hashed column is closed. You can use the flag to delete the elements. If the insert statement is sparse compared to the search statement, you can use the hash to solve the vacancy problem.
  • Randomize hash
    • Find a group of Hash Functions and randomly select a different hash function each time.
    • Used to avoid severe Clustering Effect in extreme cases of a single Hash Function
    • Global hash
      • A group of H hash functions map any two different elements to the same position. The number of functions is H/m.
  • Perfect hash
    • Construct a hash table with m = O (n) size, so that the worst search result reaches O (1)
    • The double-layer Hash is used. The size of the first layer is n. The size of each table in the second layer is the square of the number of elements that fall into the first layer position I.
    • Space consumption is O (n)
Chapter 2 Shortest Path
  • If there is a negative ring in the figure, there is no shortest path.
  • Single-source Multi-Point Shortest Path
    • Dijkstra Algorithm
      • Greedy Algorithm, requiring no negative path
      • Optimal sub-structure: each segment in the shortest path is the shortest path between two points.
      • Greedy choice attribute: The next node that the path extends outward is the node closest to the source node.
      • Each time the node closest to the source node is selected, the distance between all adjacent nodes of the node is updated.
      • The time complexity is O (V ^ 2), and the heap implementation can achieve O (E log (V )). Same as Prim algorithm
    • Bellman-Ford Algorithm
      • Can cope with negative weight
      • Perform V-1 wheel downgrading and update all edges in the graph each time
      • Complexity: O (VE)
    • BFS
      • Equal Edge Weight
      • O (V + E)
  • Multi-source and multi-point Shortest Path
    • Floyd-Warshall Algorithm
      • Dynamic Planning Algorithm
      • Sub-problem: from I to j, the intermediate node only belongs to the shortest path length of Set 1... k
      • C_ijk = min {c_ij (k-1), c_ik (k-1) + ckj (k-1)} | k
      • Complexity O (n ^ 3)
    • Jonhson Algorithm
      • Equivalent to a graph without negative weight, Dijkstra algorithm is used.
      • Add a node s. The path length to all vertices is 0. Run the Bellman-Ford algorithm and assign values to the nodes.
      • Run Dijkstra Algorithm for each node
      • The complexity is mainly the Dijkstra algorithm, which is O (VE + V ^ 2 log (V ))
      • If the Bellman-Ford algorithm report has a negative ring, you cannot use this method.

  
  

Reprinted by: Focustc. The blog address is http://blog.csdn.net/caozhk. The original link is opened by clicking
  
  
How about algorithms?

As a student interested in programming and not a computer Major, I have always wanted to have a systematic learning of algorithm theory. I bought an introduction to algorithms, but I found it difficult to read it. I was often frustrated by the mathematical reasoning in my book. Therefore, this book has been read intermittently and has not yet been completed. I accidentally saw this book "The path of algorithms". It was interesting to read at the first day. At the beginning of each chapter, the author introduced the topic to be discussed in this chapter through an interesting story. In the topic discussion, some examples of life are often used to explain and supplement each angle. There are many text descriptions in the book, but less mathematical derivation. It can be seen that the author tries his best to make the language lively, reduce the boring and abstract mathematical formula reasoning, reduce the difficulty of the reader's learning, and stimulate the reader's interest in reading. As stated in the book, "The goal of this book is the logic behind algorithms. It is a book of inspiration, not an all-encompassing algorithm ". This book introduces the basic knowledge, design analysis, and classical algorithms of algorithms, as well as hard-to-solve and non-solution problems. It discusses the main aspects of algorithms and gives up the completeness of the introduction. Therefore, this book is suitable for beginners to read. At the same time, the book also has some shortcomings that need to be improved. Although the author tries to minimize mathematical descriptions, mathematical descriptions are inevitable to clarify certain algorithm problems. However, some of the mathematical descriptions in the book are rough, and the meaning declaration of related variables is unclear, which makes it more difficult for beginners to understand. In short, compared to the "dinner" of algorithm learning such as "Introduction to algorithms", you can refer to "The Road to algorithms" as a "appetizer" before meals ", let beginners have a preliminary understanding of algorithms: the original boring algorithms also have their own interesting stories.

Where there are data structures and algorithms (preferably easy to understand, books, PPT, etc.), mainly preparing for NOIP

Introduction to algorithms Liu rujia's entry to algorithm competitions and Wu wenhu's Assembly mathematics in programming and the path to algorithms, the beauty of programming, the implementation and application of graph theory algorithms, and some QQ groups of OI or ACM can get what you want.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.