Searching in a Sorted Linked List and Sort Integers Into a Linked List
Total Page:16
File Type:pdf, Size:1020Kb
SEARCHING IN A SORTED LINKED LIST AND SORT INTEGERS INTO A LINKED LIST A THESIS IN Computer Science Presented to the Faculty of the University of Missouri-Kansas City in partial fulfillment of the requirements for the degree MASTER OF SCIENCE By HEMASREE KOGANTI B. Tech(CS), GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING AND TECHNOLOGY , India, 2015 Kansas City, Missouri 2019 ©2018 HEMASREE KOGANTI ALL RIGHTS RESERVED SEARCHING IN A SORTED LINKED LIST AND SORT INTEGERS INTO A LINKED LIST Hemasree Koganti, Candidate for the Master of Science Degree University of Missouri – Kansas City, 2018 ABSTRACT The research work consists of two parts. Part one is about Searching for an integer in a sorted Linked list. A tree is constructed in O(nloglogm/p+loglogm) time with p processors based on the trie with all the given integers. Additional nodes (O(nloglogm) of them) are added to the tree. After the tree is constructed, for any given integer we can find the predecessor and successor of the integer, insert or delete the integer in O(loglogm) time. The result demonstrates for the searching purpose we need not to sort the input numbers into a sorted array for this would need at least O(logn/loglogn) time while this algorithm for constructing the tree can run in O(loglogm) time with n processors. Part two is on sorting integers into a linked list. There are various best algorithms for sorting integers. The current research work applies the recent important results of sorting integers in (logn/loglogn) time. This algorithm takes “constant time” to sort integers into a linked list with nlogm processors and O(loglogm/logt) time using nt processors on the Priority CRCW PRAM model. iii APPROVAL PAGE The faculty listed below, appointed by the Dean of School of Computing and Engineering, have to examine the thesis titled “Searching in a Sorted Linked List and Sort Integers into a Linked List” presented by Hemasree Koganti, candidate for the Master of Science degree, and certify that in their opinion it is worthy of acceptance. Supervisory Committee Yijie Han, Ph.D., Chair School of Computing and Engineering Ken Mitchell, Ph.D. Department of Computer Science Electrical Engineering Sejun Song, Ph.D. Department of Computer Science Electrical Engineering iv CONTENTS ABSTRACT ................................................................................................................................... iii ILLUSTRATIONS ......................................................................................................................... vi ACKNOWLEDGEMENTS ........................................................................................................... vii CHAPTER 1. INTRODUCTION ............................................................................................................. 1 2. SEARCHING IN A SORTED LINKED LIST ................................................................. 4 2.1 Introduction ................................................................................................................. 4 2.2 Building the Search Tree based on a Trie .................................................................... 5 2.3 Augmenting the Tree ................................................................................................... 8 2.4 Searching ..................................................................................................................... 9 3. SORT INTEGERS INTO A LINKED LIST .................................................................... 11 3.1 Introduction ................................................................................................................ 11 3.2 The Algorithm .......................................................................................................... 12 3.3 Building a Tree Based on a Trie: An Example ......................................................... 19 4. CONCLUSION ............................................................................................................... 23 REFERENCES .................................................................................................................... 25 VITA .............................................................................................................................................. 28 v ILLUSTRATIONS Figure Page 1. Example of a Trie……………………………………………………………………5 2. Trie with Step numbers ……………………………………………………………………...6 3. Final Trie…………………...………………………………………………………..10 4. Processors assigned to each Input Integer…………………………………………...12 5. Example of a Trie…………………………………………........................................13 6. The Nodes with one child are removed……………………………………………...14 7. All the Nodes are shown……………………………………………………………..15 8. Trie with ‘a’ sections………………….……………………………………………..19 9. Intermediate Levels are removed…………………………………………………….20 10. Linked Lists are formed at the Nodes………………………………………………..21 11. Parent Node connects all its child Linked Lists……………………………………...22 vi ACKNOWLEDGEMENTS I would like to take this opportunity to thank following people who have directly or indirectly helped me in academic achievements. Firstly, I would like to thank Dr. Yijie Han for the constant and endearing support which has helped me in fulfilling my thesis. He has provided me with an opportunity to realize my potential in the field of my thesis. His encouragement and inputs were elements of vital guidance in my thesis. He has been a constant source of motivation and challenged me with algorithms, deadlines, that have contributed to me acquiring inspiration and ideology. His expertise and innovative insights have been phenomenal in completing my thesis. I sincerely thank Dr. Ken Mitchell and Dr. Sejun Song for accepting to be a part of my thesis committee and making time for me from their busy schedule. I would like to thank the University of Missouri- Kansas City for providing me with an opportunity to continue my research and supporting me in this regard. I would like to dedicate my thesis to my parents who constantly inspired me to pursue higher studies. I would like to thank my family who stood behind me all these years during my degree. Finally, I would like to thank all my teachers, educational administrators, present, and past and all who helped me achieve this academic goal. vii CHAPTER 1 INTRODUCTION In computer science, algorithms play a crucial role. Time and space complexities are major concern in terms of CPU and memory usage, performance and efficiency. The performance of the developed system is determined by the efficient algorithm used by it. There are various algorithms available for various purposes. It is well know that n objects drawn from an arbitrary totally ordered universe can be sorted by n processors in O(log n) time, even given a very weak model of parallel computation such as the processor network of bounded degree (assuming, of course, that binary comparisons take unit time). This result is optimal in the sense that the product of the number of processors and the time used is O(n log n), to be compared with a lower time bound of Ω(n log n) for any sequential algorithm operating according to the decision-tree model. Reif obtained a partial solution by giving a probabilistic algorithm that sorts n integers in the range {1, . n}, uses O(n/logn) processors, and terminates within O(log n) steps with high probability. Some doubt remains as to whether his algorithm is able to sort larger numbers, the question hinging on whether the sorting can be made stable. We investigate the restricted sorting problem in a deterministic setting. The algorithms we have developed has overcome the memory usage and performance issues. To achieve this I have used the recent best results of Parallel binary search with delayed read conflicts [10] by H.Meijer and S.G.Akl where search can be done in O(logn/logw) time where w is the number of bits in a word. The computation model used in both the paper’s is the CRCW (Concurrent Read Concurrent Write) PRAM (Parallel Random-Access Machine) Model. On the CRCW PRAM memory is shared among processors and multiple processors 1 can read the same memory cell in one step and can write to the same memory cell in one step. When concurrent write happens, we use the Priority CRCW PRAM in which when multiple processors write the same cell in one step the highest indexed processor wins the write. In the part one, we are going to construct a search tree for the sorted n input integers using a trie. Such a tree can be constructed in O(nloglogm/p+loglogm) time for n integers in {0, 1, …, m-1} using p processors on the CRCW (Concurrent Read Concurrent Write) PRAM (Parallel Random-Access Machine) [8]. We will add O(loglogm) nodes for each node in the tree to facilitate searching. After the tree is built then searching among these n input integers can be done in O(loglogm) time. The technique presented in this paper has been used to achieve an O(n/p+loglogloglogm) time CRCW PRAM merging algorithm [7]. This has been published as a research paper to “International Conference on Information Technology 2018, Bhubaneshwar, India”. The paper was accepted to the conference with Paper Id 2. In Algorithm 2, we show that n integers in {0, 1, …, m-1} can be sorted into a linked list in constant time using nlogm processors on the Priority CRCW PRAM model, and they can be sorted into a linked list in O(loglogm/logt) time using nt processors on the Priority CRCW PRAM model. We use a trie of height logm to sort integers into a linked list. We use A[i][j] to represent