Basic data structure trong lập trình

63 412 2
Basic data structure trong lập trình

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MỤC LỤC Data structures (7) • Sqrtdecomposition TeX • Fenwick tree • The system of disjoint sets TeX • Segment tree TeX • Treap (treap, deramida) • Modification of the stack and queue for finding the minimum in O (1) • Randomized heap TeX Sqrtdecomposition Sqrtdecomposition is a method or a data structure that allows some typical operations (sum of subarray elements, to find the minimum maximum, etc.) for , significantly faster than for the trivial algorithm. First, we describe a data structure for one of the simplest applications of this idea, then show how to generalize it to solve some other problems, and, finally, look at some other use of this idea: the partition of the input requests sqrtblocks. The data structure on the basis of decomposition sqrt We pose the problem . Given an array . Required to implement such a data structure that will be able to find the sum of the elements for arbitrary and for operations. Description The basic idea sqrtdecomposition is what to do next predposchёt : divide the array into blocks of length approximately , and in each block in advance predposchitaem sum of elements in it. We can assume that the length of one unit and the number of units equal to one and the same number the root of , rounded up: then the array is divided into blocks like this: Although the latter unit may comprise less than , the elements (if not divisible ) is not essential. Thus, for each block , we know the amount on it : So, let the values previously calculated (that is, obviously, operations). That they can give the calculation of the response to another request ? Note that if the interval is long, then it will contain several blocks as a whole, and these blocks, we can find out the amount on them in a single operation. As a result, the total length will be only two blocks falling into it is only partially, and these pieces we have to sum trivial algorithm. Illustration (here designated block number, wherein the lie , and by the number of the block in which lies ): This figure shows that in order to calculate the amount of the segment , it is necessary to sum the elements of only two tails: and , and sum the values in all the blocks, starting from and ending with : (Note: this is incorrect formula where : in this case, some elements are added together twice and in this case it is necessary to sum the elements simply by ) Thus we ekononim significant number of operations. Indeed, the size of each of the tails clearly does not exceed the block length and the number of blocks not exceed . Since we have chosen , the total amount for the calculation of the interval , we need only operations. Implementation We give first a simple realization: входные данные int n; vector a (n); предпосчёт int len = (int) sqrt (n + .0) + 1; и размер блока, и количество блоков vector b (len); for (int i=0; i

Ngày đăng: 11/05/2015, 05:53

Từ khóa liên quan

Mục lục

  • Sqrt-decomposition

    • The data structure on the basis of decomposition sqrt-

      • Description

      • Implementation

      • Other objects

      • Sqrt-decomposition of the input query

        • An example of the problem: adding the interval

        • Example problem: disjoint-set-union division

        • Off-line tasks to requests for subsegments and versatile array sqrt-heuristics for them

        • Fenwick tree

          • Description

          • Implementation Fenwick tree for the sum of one-dimensional case

          • Implementation Fenwick tree for a minimum of one-dimensional case

          • Implementation Fenwick tree for the sum of two-dimensional case

          • The system of disjoint sets

            • Building an efficient data structure

              • Naive implementation

              • Heuristics compression path

                • Evaluation of the asymptotic behavior of the application of heuristics compression path

                • Heuristics union by rank

                  • Evaluation of the asymptotic behavior of the application of heuristics rank

                  • Combining heuristics: path compression plus rank heuristic

                  • Use in various tasks and improve

                    • Support for the connected components of the graph

                    • Search the connected components in the image

                    • Support for additional information for each set

                    • Application DSU compression "jumps" over the interval. The problem of painting subsegments Offline

                    • Support distances to the leader

                    • Support for parity path length and the problem of verification of bipartite graphs online

Tài liệu cùng người dùng

Tài liệu liên quan