External Sorting Why Sort? Sorting a File in RAM 2-Way Sort of N Pages

Total Page:16

File Type:pdf, Size:1020Kb

External Sorting Why Sort? Sorting a File in RAM 2-Way Sort of N Pages Why Sort? A classic problem in computer science! Data requested in sorted order – e.g., find students in increasing gpa order Sorting is the first step in bulk loading of B+ tree External Sorting index. Sorting is useful for eliminating duplicate copies in a collection of records (Why?) Chapter 13 Sort-merge join algorithm involves sorting. Problem: sort 100Gb of data with 1Gb of RAM. – why not virtual memory? Take a look at sortbenchmark.com Take a look at main memory sort algos at www.sorting-algorithms.com Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Database Management Systems, R. Ramakrishnan and J. Gehrke 2 Sorting a file in RAM 2-Way Sort of N pages Requires Minimum of 3 Buffers Three steps: – Read the entire file from disk into RAM Pass 0: Read a page, sort it, write it. – Sort the records using a standard sorting procedure, such – only one buffer page is used as Shell sort, heap sort, bubble sort, … (100’s of algos) – How many I/O’s does it take? – Write the file back to disk Pass 1, 2, 3, …, etc.: How can we do the above when the data size is 100 – Minimum three buffer pages are needed! (Why?) or 1000 times that of available RAM size? – How many i/o’s are needed in each pass? (Why?) And keep I/O to a minimum! – How many passes are needed? (Why?) – Effective use of buffers INPUT 1 – Merge as a way of sorting – Overlap processing and I/O (e.g., heapsort) OUTPUT INPUT 2 Main memory buffers Disk Disk Database Management Systems, R. Ramakrishnan and J. Gehrke 3 Database Management Systems, R. Ramakrishnan and J. Gehrke 4 Two-Way External Merge Sort General External Merge Sort Each pass we read + write Suppose we can have more than 3 buffers! Can we each page in file. 3,4 6,2 9,4 8,7 5,6 3,1 2 Input file PASS 0 use them effectively and do better? N pages in the file => the 1,3 2 1-page runs 3,42,6 4,9 7,8 5,6 number of passes PASS 1 To sort a file with N pages using B buffer pages: 4,7 1,3 2,3 2-page runs – Pass 0: use B buffer pages. Produce NB / sorted runs of B log2 N 1 4,6 8,9 5,6 2 PASS 2 pages each. So total cost is: 2,3 – Pass 2, …, etc.: merge B-1 runs. 4,4 1,2 4-page runs 21NNlog2 6,7 3,5 6 8,9 INPUT 1 PASS 3 Idea: Divide and conquer: 1,2 INPUT 2 sort subfiles and merge OUTPUT 2,3 . 3,4 8-page runs 4,5 INPUT B-1 Can we improve upon 6,6 Disk this? How? 7,8 Disk B Main memory buffers 9 Database Management Systems, R. Ramakrishnan and J. Gehrke 5 Database Management Systems, R. Ramakrishnan and J. Gehrke 6 Cost of External Merge Sort Number of Passes of External Sort Number of passes: 1 logB1 NB / Cost = 2N * (# of passes) E.g., with 5 buffer pages, to sort 108 page file: N B=3 B=5 B=9 B=17 B=129 B=257 – Pass 0: 108 / 5 = 22 sorted runs of 5 pages each 100 7 4 3 2 1 1 (last run is only 3 pages) 1,000 10 5 4 3 2 2 – Pass 1: 22 / 4 = 6 sorted runs of 20 pages each (last run is only 8 pages) 10,000 13 7 5 4 2 2 – Pass 2: 2 sorted runs, 80 pages and 28 pages 100,000 17 9 6 5 3 3 – Pass 3: Sorted file of 108 pages 1,000,000 20 10 7 5 3 3 Note that with 3 buffers, initial can be of 3- 10,000,000 23 12 8 6 4 3 page runs (not 1) 100,000,000 26 14 9 7 4 4 –Cost is: 1 + 2Nlog2 N /3 1 1,000,000,000 30 15 10 8 5 4 Database Management Systems, R. Ramakrishnan and J. Gehrke 7 Database Management Systems, R. Ramakrishnan and J. Gehrke 8 Internal (main memory) Sort Algorithm Min-Heap Quicksort is a fast way to sort in memory. – A divide-and-conquer algorithm – Partition initial array into 2 (preferably equal size) with some property for each partition – Sort each partition recursively – In-place sort algorithm – Sorts a fixed size input to generate a fixed-size output! An alternative is “tournament sort” (aka “heapsort”) – You build a max- or min-heap (binary tree with some property) A node’s key >= its children’s keys Can be implemented using an array – Can HEAPIFY a HEAP to insert a new value! http://www.sorting-algorithms.com/random-initial-order Database Management Systems, R. Ramakrishnan and J. Gehrke 9 Database Management Systems, R. Ramakrishnan and J. Gehrke 10 Internal (main memory) Sort Algorithm More on Heapsort Fact: average length of a run in heapsort is 2B Given B buffers, Use 1 input, B-2 current set, and 1 – The “snowplow” analogy output buffer Worst-Case: Use heapsort on the current set and output the – What is min length of a run? smallest to output buffer – How does this arise? Insert new record into current set and output the smallest from current set which is greater than the Best-Case: largest in the output (for ascending sort) – What is max length of a run? – How does this arise? Terminating condition B – when all values in the current set is smaller than the output, Quicksort is faster, but our aim is to reduce start a new run the number of initial runs and hence reduce Instead of discreet sort, we are doing a continuous the number of passes!! sort (snow plow example) – Hence heapsort is better for disk-based sorting! Database Management Systems, R. Ramakrishnan and J. Gehrke 11 Database Management Systems, R. Ramakrishnan and J. Gehrke 12 I/O for External Merge Sort I/O for External Merge Sort (2) … longer runs often means fewer passes! Blocked I/O We are assuming that I/O is done one page at a – Suppose a block is b pages time – We need b buffer pages for output (1 block) In fact, can read a block of pages sequentially! – We can only merge ceiling ((B-b)/b) runs (instead – Much faster/cheaper than reading pages of the of B-1 runs when we read 1 page at a time) block individually – If we have 10 buffer pages, we can Suggests we should make each buffer (input Either merge nine runs without using blocks, or /output) be a block of pages. Four runs if we assume 2 page blocks – This tradeoff between using blocks vs. the number – But this will reduce fan-out during merge passes! of runs needs to be taken into account for external Why? merge sort! – In practice, most files still sorted in 2-3 passes. – The good news is that with greater memory, both Minimizes I/O cost, not the # of I/O’s block sizes and #runs can be kept to a decent Also, double buffering. What does this reduce? value Database Management Systems, R. Ramakrishnan and J. Gehrke 13 Database Management Systems, R. Ramakrishnan and J. Gehrke 14 Number of Passes of Optimized Sort Blocked I/O Let b be the units of read and write N B=1,000 B=5,000 B=10,000 100 1 1 1 Given B buffers, # of runs that can be merged 1,000 1 1 1 is floor ( (B-b)/b) 10,000 2 2 1 If we have 10 buffers, we can 100,000 3 2 2 – Merge 9 runs at a time with 1 page buffer, or 1,000,000 3 2 2 – Merge 4 runs at a time with 2 page input (for each 10,000,000 4 3 3 block) and output buffer blocks 100,000,000 5 3 3 1,000,000,000 5 4 3 How does it reduce I/O cost? Block size = 32, initial pass produces runs of size 2B. Database Management Systems, R. Ramakrishnan and J. Gehrke 15 Database Management Systems, R. Ramakrishnan and J. Gehrke 16 Double Buffering Sorting Records! (http://sortbenchmark.org/) To reduce wait time for I/O request to complete, can prefetch into `shadow block’. Since 2007, it is done by a the sort benchmark committee – Tradeoff between buffers and passes; in practice, most files still sorted in 2-3 passes. Daytona (stock car) Indy (formula 1) Sort code must be general Need only sort 100-byte records purpose. with 10-byte keys. INPUT 1 INPUT 1' INPUT 2 OUTPUT INPUT 2' OUTPUT' b block size Disk INPUT k Disk INPUT k' B main memory buffers, k-way merge Does double buffering reduce the # i/o’s? Database Management Systems, R. Ramakrishnan and J. Gehrke 17 Database Management Systems, R. Ramakrishnan and J. Gehrke 18 2016, 44.8 TB/min 2016, 60.7 TB/min Tencent Sort Tencent Sort 100 TB in 134 Seconds 100 TB in 98.8 Seconds 512 nodes x (2 OpenPOWER 10-core POWER8 2.926 512 nodes x (2 OpenPOWER 10-core POWER8 GHz, 2.926 GHz, 512 GB memory, 4x Huawei ES3600P V3 1.2TB 512 GB memory, 4x Huawei ES3600P V3 1.2TB Gray NVMe SSD, NVMe SSD, Using B+ Trees for Sorting 100Gb Mellanox ConnectX4-EN) 100Gb Mellanox ConnectX4-EN) Jie Jiang, Lixiong Zheng, Junfeng Pu, Jie Jiang, Lixiong Zheng, Junfeng Pu, Xiong Cheng, Chongqing Zhao Xiong Cheng, Chongqing Zhao Tencent Corporation Tencent Corporation Mark R.
Recommended publications
  • Coursenotes 4 Non-Adaptive Sorting Batcher's Algorithm
    4. Non Adaptive Sorting Batcher’s Algorithm 4.1 Introduction to Batcher’s Algorithm Sorting has many important applications in daily life and in particular, computer science. Within computer science several sorting algorithms exist such as the “bubble sort,” “shell sort,” “comb sort,” “heap sort,” “bucket sort,” “merge sort,” etc. We have actually encountered these before in section 2 of the course notes. Many different sorting algorithms exist and are implemented differently in each programming language. These sorting algorithms are relevant because they are used in every single computer program you run ranging from the unimportant computer solitaire you play to the online checking account you own. Indeed without sorting algorithms, many of the services we enjoy today would simply not be available. Batcher’s algorithm is a way to sort individual disorganized elements called “keys” into some desired order using a set number of comparisons. The keys that will be sorted for our purposes will be numbers and the order that we will want them to be in will be from greatest to least or vice a versa (whichever way you want it). The Batcher algorithm is non-adaptive in that it takes a fixed set of comparisons in order to sort the unsorted keys. In other words, there is no change made in the process during the sorting. Unlike other methods of sorting where you need to remember comparisons (tournament sort), Batcher’s algorithm is useful because it requires less thinking. Non-adaptive sorting is easy because outcomes of comparisons made at one point of the process do not affect which comparisons will be made in the future.
    [Show full text]
  • An Evolutionary Approach for Sorting Algorithms
    ORIENTAL JOURNAL OF ISSN: 0974-6471 COMPUTER SCIENCE & TECHNOLOGY December 2014, An International Open Free Access, Peer Reviewed Research Journal Vol. 7, No. (3): Published By: Oriental Scientific Publishing Co., India. Pgs. 369-376 www.computerscijournal.org Root to Fruit (2): An Evolutionary Approach for Sorting Algorithms PRAMOD KADAM AND Sachin KADAM BVDU, IMED, Pune, India. (Received: November 10, 2014; Accepted: December 20, 2014) ABstract This paper continues the earlier thought of evolutionary study of sorting problem and sorting algorithms (Root to Fruit (1): An Evolutionary Study of Sorting Problem) [1]and concluded with the chronological list of early pioneers of sorting problem or algorithms. Latter in the study graphical method has been used to present an evolution of sorting problem and sorting algorithm on the time line. Key words: Evolutionary study of sorting, History of sorting Early Sorting algorithms, list of inventors for sorting. IntroDUCTION name and their contribution may skipped from the study. Therefore readers have all the rights to In spite of plentiful literature and research extent this study with the valid proofs. Ultimately in sorting algorithmic domain there is mess our objective behind this research is very much found in documentation as far as credential clear, that to provide strength to the evolutionary concern2. Perhaps this problem found due to lack study of sorting algorithms and shift towards a good of coordination and unavailability of common knowledge base to preserve work of our forebear platform or knowledge base in the same domain. for upcoming generation. Otherwise coming Evolutionary study of sorting algorithm or sorting generation could receive hardly information about problem is foundation of futuristic knowledge sorting problems and syllabi may restrict with some base for sorting problem domain1.
    [Show full text]
  • The Influence of Caches on the Performance of Sorting
    The Influence of Caches on the Performance of Sorting Anthony LaMarca* & Richard E. Ladner Department of Computer Science and Engineering University of Washington Seattle, WA 98195 lamarcaQparc.xerox.com [email protected] Abstract quicksort [12], and radix sort*. Heapsort, mergesort, We investigate the effect that caches have on the per- and quicksort are all comparison based sorting algo- formance of sorting algorithms both experimentally and rithms while radix sort is not. analytically. To address the performance problems that For each of the four sorting algorithms we choose an high cache miss penalties introduce we restructure heap- implementation variant with potential for good overall sort, mergesort and quicksort in order to improve their performance and then heavily optimize this variant us- cache locality. For all three algorithms the improvement ing traditional techniques to minimize the number of in cache performance leads to a reduction in total ex- instructions executed. These heavily optimized algo- ecution time. We also investigate the performance of rithms form the baseline for comparison. For each of radix sort. Despite the extremely low instruction count the comparison sort baseline algorithms we develop and incurred by this linear sorting algorithm, its relatively apply memory optimizations in order to improve cache poor cache performance results in worse overall perfor- performance and, hopefully, overall performance. For mance than the efficient comparison based sorting algo- radix sort we optimize cache performance by varying rithms. the radix. In the process we develop some simple an- alytic techniques which enable us to predict the mem- 1 Introduction. ory performance of these algorithms in terms of cache misses.
    [Show full text]
  • Sorting Algorithms
    Sorting Algorithms CENG 707 Data Structures and Algorithms Sorting • Sorting is a process that organizes a collection of data into either ascending or descending order. • An internal sort requires that the collection of data fit entirely in the computer’s main memory. • We can use an external sort when the collection of data cannot fit in the computer’s main memory all at once but must reside in secondary storage such as on a disk. • We will analyze only internal sorting algorithms. • Any significant amount of computer output is generally arranged in some sorted order so that it can be interpreted. • Sorting also has indirect uses. An initial sort of the data can significantly enhance the performance of an algorithm. • Majority of programming projects use a sort somewhere, and in many cases, the sorting cost determines the running time. • A comparison-based sorting algorithm makes ordering decisions only on the basis of comparisons. CENG 707 Data Structures and Algorithms Sorting Algorithms • There are many sorting algorithms, such as: – Selection Sort – Insertion Sort – Bubble Sort – Merge Sort – Quick Sort • The first three are the foundations for faster and more efficient algorithms. CENG 707 Data Structures and Algorithms Selection Sort • The list is divided into two sublists, sorted and unsorted, which are divided by an imaginary wall. • We find the smallest element from the unsorted sublist and swap it with the element at the beginning of the unsorted data. • After each selection and swapping, the imaginary wall between the two sublists move one element ahead, increasing the number of sorted elements and decreasing the number of unsorted ones.
    [Show full text]
  • 17. Chapter 11
    11 EXTERNALSORTING Good order is the foundation of all things. —Edmund Burke Sorting a collection of records on some (search) key is a very useful operation. The key can be a single attribute or an ordered list of attributes, of course. Sorting is required in a variety of situations, including the following important ones: Users may want answers in some order; for example, by increasing age (Section 5.2). Sorting records is the first step in bulk loading a tree index (Section 9.8.2). Sorting is useful for eliminating duplicate copies in a collection of records (Chapter 12). A widely used algorithm for performing a very important relational algebra oper- ation, called join, requires a sorting step (Section 12.5.2). Although main memory sizes are increasing, as usage of database systems increases, increasingly larger datasets are becoming common as well. When the data to be sorted is too large to fit into available main memory, we need to use an external sorting algorithm. Such algorithms seek to minimize the cost of disk accesses. We introduce the idea of external sorting by considering a very simple algorithm in Section 11.1; using repeated passes over the data, even very large datasets can be sorted with a small amount of memory. This algorithm is generalized to develop a realistic external sorting algorithm in Section 11.2. Three important refinements are discussed. The first, discussed in Section 11.2.1, enables us to reduce the number of passes. The next two refinements, covered in Section 11.3, require us to consider a more detailed model of I/O costs than the number of page I/Os.
    [Show full text]
  • Evaluation of Sorting Algorithms, Mathematical and Empirical Analysis of Sorting Algorithms
    International Journal of Scientific & Engineering Research Volume 8, Issue 5, May-2017 86 ISSN 2229-5518 Evaluation of Sorting Algorithms, Mathematical and Empirical Analysis of sorting Algorithms Sapram Choudaiah P Chandu Chowdary M Kavitha ABSTRACT:Sorting is an important data structure in many real life applications. A number of sorting algorithms are in existence till date. This paper continues the earlier thought of evolutionary study of sorting problem and sorting algorithms concluded with the chronological list of early pioneers of sorting problem or algorithms. Latter in the study graphical method has been used to present an evolution of sorting problem and sorting algorithm on the time line. An extensive analysis has been done compared with the traditional mathematical methods of ―Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort. Observations have been obtained on comparing with the existing approaches of All Sorts. An “Empirical Analysis” consists of rigorous complexity analysis by various sorting algorithms, in which comparison and real swapping of all the variables are calculatedAll algorithms were tested on random data of various ranges from small to large. It is an attempt to compare the performance of various sorting algorithm, with the aim of comparing their speed when sorting an integer inputs.The empirical data obtained by using the program reveals that Quick sort algorithm is fastest and Bubble sort is slowest. Keywords: Bubble Sort, Insertion sort, Quick Sort, Merge Sort, Selection Sort, Heap Sort,CPU Time. Introduction In spite of plentiful literature and research in more dimension to student for thinking4. Whereas, sorting algorithmic domain there is mess found in this thinking become a mark of respect to all our documentation as far as credential concern2.
    [Show full text]
  • Algorithm Efficiency and Sorting
    Measuring the Efficiency of Chapter 10 Algorithms • Analysis of algorithms – contrasts the efficiency of different methods of solution Algorithm Efficiency and • A comparison of algorithms Sorting – Should focus of significant differences in efficiency – Should not consider reductions in computing costs due to clever coding tricks © 2006 Pearson Addison-Wesley. All rights reserved 10 A-1 © 2006 Pearson Addison-Wesley. All rights reserved 10 A-2 The Execution Time of Algorithm Growth Rates Algorithms • Counting an algorithm's operations is a way to • An algorithm’s time requirements can be access its efficiency measured as a function of the input size – An algorithm’s execution time is related to the number of operations it requires • Algorithm efficiency is typically a concern for large data sets only © 2006 Pearson Addison-Wesley. All rights reserved 10 A-3 © 2006 Pearson Addison-Wesley. All rights reserved 10 A-4 Order-of-Magnitude Analysis and Algorithm Growth Rates Big O Notation • Definition of the order of an algorithm Algorithm A is order f(n) – denoted O(f(n)) – if constants k and n0 exist such that A requires no more than k * f(n) time units to solve a problem of size n ! n0 • Big O notation – A notation that uses the capital letter O to specify an algorithm’s order Figure 10-1 – Example: O(f(n)) Time requirements as a function of the problem size n © 2006 Pearson Addison-Wesley. All rights reserved 10 A-5 © 2006 Pearson Addison-Wesley. All rights reserved 10 A-6 Order-of-Magnitude Analysis and Order-of-Magnitude Analysis and Big O Notation Big O Notation • Order of growth of some common functions 2 3 n O(1) < O(log2n) < O(n) < O(nlog2n) < O(n ) < O(n ) < O(2 ) • Properties of growth-rate functions – You can ignore low-order terms – You can ignore a multiplicative constant in the high- order term – O(f(n)) + O(g(n)) = O(f(n) + g(n)) Figure 10-3b A comparison of growth-rate functions: b) in graphical form © 2006 Pearson Addison-Wesley.
    [Show full text]
  • Sorting Algorithms
    Sort Algorithms Humayun Kabir Professor, CS, Vancouver Island University, BC, Canada Sorting • Sorting is a process that organizes a collection of data into either ascending or descending order. • An internal sort requires that the collection of data fit entirely in the computer’s main memory. • We can use an external sort when the collection of data cannot fit in the computer’s main memory all at once but must reside in secondary storage such as on a disk. • We will analyze only internal sorting algorithms. Sorting • Any significant amount of computer output is generally arranged in some sorted order so that it can be interpreted. • Sorting also has indirect uses. An initial sort of the data can significantly enhance the performance of an algorithm. • Majority of programming projects use a sort somewhere, and in many cases, the sorting cost determines the running time. • A comparison-based sorting algorithm makes ordering decisions only on the basis of comparisons. Sorting Algorithms • There are many comparison based sorting algorithms, such as: – Bubble Sort – Selection Sort – Insertion Sort – Merge Sort – Quick Sort Bubble Sort • The list is divided into two sublists: sorted and unsorted. • Starting from the bottom of the list, the smallest element is bubbled up from the unsorted list and moved to the sorted sublist. • After that, the wall moves one element ahead, increasing the number of sorted elements and decreasing the number of unsorted ones. • Each time an element moves from the unsorted part to the sorted part one sort pass is completed. • Given a list of n elements, bubble sort requires up to n-1 passes to sort the data.
    [Show full text]
  • Comparison Sorts Name Best Average Worst Memory Stable Method Other Notes Quicksort Is Usually Done in Place with O(Log N) Stack Space
    Comparison sorts Name Best Average Worst Memory Stable Method Other notes Quicksort is usually done in place with O(log n) stack space. Most implementations on typical in- are unstable, as stable average, worst place sort in-place partitioning is case is ; is not more complex. Naïve Quicksort Sedgewick stable; Partitioning variants use an O(n) variation is stable space array to store the worst versions partition. Quicksort case exist variant using three-way (fat) partitioning takes O(n) comparisons when sorting an array of equal keys. Highly parallelizable (up to O(log n) using the Three Hungarian's Algorithmor, more Merge sort worst case Yes Merging practically, Cole's parallel merge sort) for processing large amounts of data. Can be implemented as In-place merge sort — — Yes Merging a stable sort based on stable in-place merging. Heapsort No Selection O(n + d) where d is the Insertion sort Yes Insertion number of inversions. Introsort No Partitioning Used in several STL Comparison sorts Name Best Average Worst Memory Stable Method Other notes & Selection implementations. Stable with O(n) extra Selection sort No Selection space, for example using lists. Makes n comparisons Insertion & Timsort Yes when the data is already Merging sorted or reverse sorted. Makes n comparisons Cubesort Yes Insertion when the data is already sorted or reverse sorted. Small code size, no use Depends on gap of call stack, reasonably sequence; fast, useful where Shell sort or best known is No Insertion memory is at a premium such as embedded and older mainframe applications. Bubble sort Yes Exchanging Tiny code size.
    [Show full text]
  • 1 Sorting: Basic Concepts
    UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B P. N. Hilfinger Fall 1999 Sorting∗ 1 Sorting: Basic concepts At least at one time, most CPU time and I/O bandwidth was spent sorting (these days, I suspect more may be spent rendering .gif files). As a result, sorting has been the subject of extensive study and writing. We will hardly scratch the surface here. The purpose of any sort is to permute some set of items that we'll call records so that they are sorted according to some ordering relation. In general, the ordering relation looks at only part of each record, the key. The records may be sorted according to more than one key, in which case we refer to the primary key and to secondary keys. This distinction is actually realized in the ordering function: record A comes before B iff either A's primary key comes before B's, or their primary keys are equal and A's secondary key comes before B's. One can extend this definition in an obvious way to hierarchy of multiple keys. For the purposes of these Notes, I'll usually assume that records are of some type Record and that there is an ordering relation on the records we are sorting. I'll write before(A; B) to mean that the key of A comes before that of B in whatever order we are using. Although conceptually we move around the records we are sorting so as to put them in order, in fact these records may be rather large.
    [Show full text]
  • Dynamic Algorithms for Partially-Sorted Lists Kostya Kamalah Ross
    Dynamic Algorithms for Partially-Sorted Lists Kostya Kamalah Ross School of Computer and Mathematical Sciences November 3, 2015 A thesis submitted to Auckland University of Technology in fulfilment of the requirements for the degree of Master of Philosophy. 1 Abstract The dynamic partial sorting problem asks for an algorithm that maintains lists of numbers under the link, cut and change value operations, and queries the sorted sequence of the k least numbers in one of the lists. We examine naive solutions to the problem and demonstrate why they are not adequate. Then, we solve the problem in O(k · log(n)) time for queries and O(log(n)) time for updates using the tournament tree data structure, where n is the number of elements in the lists. We then introduce a layered tournament tree ∗ data structure and solve the same problem in O(log'(n) · k · log(k)) time for 2 ∗ queries and O(log (n)) for updates, where ' is the golden ratio and log'(n) is the iterated logarithmic function with base '. We then perform experiments to test the performance of both structures, and discover that the tournament tree has better practical performance than the layered tournament tree. We discuss the probable causes of this. Lastly, we suggest further work that can be undertaken in this area. Contents List of Figures 4 1 Introduction 7 1.1 Problem setup . 8 1.2 Contribution . 8 1.3 Related work . 9 1.4 Organization . 10 1.5 Preliminaries . 11 1.5.1 Trees . 11 1.5.2 Asymptotic and Amortized Complexity .
    [Show full text]
  • Experimental Based Selection of Best Sorting Algorithm
    International Journal of Modern Engineering Research (IJMER) www.ijmer.com Vol.2, Issue.4, July-Aug 2012 pp-2908-2912 ISSN: 2249-6645 Experimental Based Selection of Best Sorting Algorithm 1 2 D.T.V Dharmajee Rao, B.Ramesh 1 Professor & HOD, Dept. of Computer Science and Engineering, AITAM College of Engineering, JNTUK 2 Dept. of Computer Science and Engineering, AITAM College of Engineering, JNTUK Abstract: Sorting algorithm is one of the most basic 1.1 Theoretical Time Complexity of Various Sorting research fields in computer science. Sorting refers to Algorithms the operation of arranging data in some given order such as increasing or decreasing, with numerical data, or Time Complexity of Various Sorting Algorithms alphabetically, with character data. Name Best Average Worst There are many sorting algorithms. All sorting Insertion n n*n n*n algorithms are problem specific. The particular Algorithm sort one chooses depends on the properties of the data and Selection n*n n*n n*n operations one may perform on data. Accordingly, we will Sort want to know the complexity of each algorithm; that is, to Bubble Sort n n*n n*n know the running time f(n) of each algorithm as a function Shell Sort n n (log n)2 n (log n)2 of the number n of input elements and to analyses the Gnome Sort n n*n n*n space and time requirements of our algorithms. Quick Sort n log n n log n n*n Selection of best sorting algorithm for a particular problem Merge Sort n log n n log n n log n depends upon problem definition.
    [Show full text]