ebook img

Data Structures and Algorithms in Ruby PDF

348 Pages·2017·5.236 MB·english
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Data Structures and Algorithms in Ruby

Data Structures & Algorithms in Ruby First Edition By Hemant Jain Problems Solving in Data Structures & Algorithms in Ruby Hemant Jain Copyright © Hemant Jain 2017. All Right Reserved. Hemant Jain asserts the moral right to be identified as the author of this work. All rights reserved. No part of this publication may be reproduced, stored in or introduced into a retrieval system, or transmitted, in any form, or by any means (electrical, mechanical, photocopying, recording or otherwise) without the prior written permission of the author, except in the case of very brief quotations embodied in critical reviews and certain other non- commercial uses permitted by copyright law. Any person who does any unauthorized act in relation to this publication may be liable to criminal prosecution and civil claims for damages. ACKNOWLEDGEMENT The author is very grateful to GOD ALMIGHTY for his grace and blessing. My deepest gratitude to my elder brother Dr. Sumant Jain for his help and support. This book would not have been possible without the support and encouragement he provided. I would like to express profound gratitude to my guide/ my friend Naveen Kaushik for his invaluable encouragement, supervision and useful suggestion throughout this book writing work. His support and continuous guidance enable me to complete my work successfully. Finally, yet importantly, I am thankful to Love Singhal, Anil Berry and Others who helped me directly or indirectly for completing this book. Hemant Jain TABLE OF CONTENTS TABLE OF CONTENTS CHAPTER 0: HOW TO USE THIS BOOK WHAT THIS BOOK IS ABOUT PREPARATION PLANS SUMMARY CHAPTER 1: ALGORITHMS ANALYSIS INTRODUCTION ALGORITHM ASYMPTOTIC ANALYSIS BIG-O NOTATION OMEGA-Ω NOTATION THETA-Θ NOTATION COMPLEXITY ANALYSIS OF ALGORITHMS TIME COMPLEXITY ORDER DERIVING THE RUNTIME FUNCTION OF AN ALGORITHM TIME COMPLEXITY EXAMPLES MASTER THEOREM MODIFIED MASTER THEOREM ARRAY QUESTIONS RECURSIVE FUNCTION EXERCISES CHAPTER 2: APPROACH TO SOLVE ALGORITHM DESIGN PROBLEMS INTRODUCTION CONSTRAINTS IDEA GENERATION COMPLEXITIES CODING TESTING EXAMPLE SUMMARY CHAPTER 3: ABSTRACT DATA TYPE & RUBY COLLECTIONS ABSTRACT DATA TYPE (ADT) DATA-STRUCTURE RUBY COLLECTION FRAMEWORK ARRAY LINKED LIST STACK QUEUE TREE BINARY TREE BINARY SEARCH TREES (BST) PRIORITY QUEUE (HEAP) HASH-TABLE DICTIONARY IN RUBY COLLECTION SET COUNTER DICTIONARY / SYMBOL TABLE GRAPHS GRAPH ALGORITHMS SORTING ALGORITHMS COUNTING SORT END NOTE CHAPTER 4: SEARCHING INTRODUCTION WHY SEARCHING? DIFFERENT SEARCHING ALGORITHMS LINEAR SEARCH – UNSORTED INPUT LINEAR SEARCH – SORTED BINARY SEARCH STRING SEARCHING ALGORITHMS HASHING AND SYMBOL TABLES HOW SORTING IS USEFUL IN SELECTION ALGORITHM? PROBLEMS IN SEARCHING EXERCISE CHAPTER 5: SORTING INTRODUCTION TYPE OF SORTING BUBBLE-SORT MODIFIED (IMPROVED) BUBBLE-SORT INSERTION-SORT SELECTION-SORT MERGE-SORT QUICK-SORT QUICK SELECT BUCKET SORT GENERALIZED BUCKET SORT HEAP-SORT TREE SORTING EXTERNAL SORT (EXTERNAL MERGE-SORT) COMPARISONS OF THE VARIOUS SORTING ALGORITHMS. SELECTION OF BEST SORTING ALGORITHM EXERCISE CHAPTER 6: LINKED LIST INTRODUCTION LINKED LIST TYPES OF LINKED LIST SINGLY LINKED LIST DOUBLY LINKED LIST CIRCULAR LINKED LIST DOUBLY CIRCULAR LIST EXERCISE CHAPTER 7: STACK INTRODUCTION THE STACK ABSTRACT DATA TYPE STACK USING ARRAY STACK USING LINKED LIST PROBLEMS IN STACK USES OF STACK EXERCISE CHAPTER 8: QUEUE INTRODUCTION THE QUEUE ABSTRACT DATA TYPE QUEUE USING ARRAY QUEUE USING LINKED LIST PROBLEMS IN QUEUE EXERCISE CHAPTER 9: TREE INTRODUCTION TERMINOLOGY IN TREE BINARY TREE TYPES OF BINARY TREES PROBLEMS IN BINARY TREE BINARY SEARCH TREE (BST) PROBLEMS IN BINARY SEARCH TREE (BST) SEGMENT TREE AVL TREES RED-BLACK TREE SPLAY TREE B-TREE B+ TREE B* TREE EXERCISE CHAPTER 10: PRIORITY QUEUE INTRODUCTION TYPES OF HEAP HEAP ADT OPERATIONS OPERATION ON HEAP HEAP-SORT USES OF HEAP PROBLEMS IN HEAP EXERCISE CHAPTER 11: HASH-TABLE INTRODUCTION HASH-TABLE HASHING WITH OPEN ADDRESSING HASHING WITH SEPARATE CHAINING PROBLEMS IN HASHING EXERCISE CHAPTER 12: GRAPHS INTRODUCTION GRAPH REPRESENTATION ADJACENCY MATRIX ADJACENCY LIST GRAPH TRAVERSALS DEPTH FIRST TRAVERSAL BREADTH FIRST TRAVERSAL PROBLEMS IN GRAPH DIRECTED ACYCLIC GRAPH TOPOLOGICAL SORT MINIMUM SPANNING TREES (MST) SHORTEST PATH ALGORITHMS IN GRAPH EXERCISE CHAPTER 13: STRING ALGORITHMS INTRODUCTION STRING MATCHING ALGORITHMS DICTIONARY / SYMBOL TABLE PROBLEMS IN STRING EXERCISE CHAPTER 14: ALGORITHM DESIGN TECHNIQUES INTRODUCTION BRUTE FORCE ALGORITHM GREEDY ALGORITHM DIVIDE-AND-CONQUER, DECREASE-AND-CONQUER DYNAMIC PROGRAMMING REDUCTION / TRANSFORM-AND-CONQUER BACKTRACKING BRANCH-AND-BOUND A* ALGORITHM CONCLUSION CHAPTER 15: BRUTE FORCE ALGORITHM INTRODUCTION PROBLEMS IN BRUTE FORCE ALGORITHM CONCLUSION CHAPTER 16: GREEDY ALGORITHM INTRODUCTION PROBLEMS ON GREEDY ALGORITHM CHAPTER 17: DIVIDE-AND-CONQUER, DECREASE-AND-CONQUER INTRODUCTION GENERAL DIVIDE-AND-CONQUER RECURRENCE MASTER THEOREM PROBLEMS ON DIVIDE-AND-CONQUER ALGORITHM CHAPTER 18: DYNAMIC PROGRAMMING INTRODUCTION PROBLEMS ON DYNAMIC PROGRAMMING ALGORITHM CHAPTER 19: BACKTRACKING INTRODUCTION PROBLEMS ON BACKTRACKING ALGORITHM CHAPTER 20: COMPLEXITY THEORY AND NP COMPLETENESS INTRODUCTION DECISION PROBLEM COMPLEXITY CLASSES CLASS P PROBLEMS CLASS NP PROBLEMS CLASS CO-NP NP–HARD: NP–COMPLETE PROBLEMS REDUCTION END NOTE APPENDIX APPENDIX A CHAPTER 0: HOW TO USE THIS BOOK What this book is about This book introduces you to the world of data structures and algorithms. Data structure defines the way how data is arranged in computer memory for fast and efficient access while algorithm is a set of instruction to solve problems by manipulating these data structures. Designing an efficient algorithm is a very important skill that all computer companies e.g. Microsoft, Google, Facebook etc. pursue. Most of the interviews for these companies are focused on knowledge of data structure and algorithm. They look for how candidates use these to solve complex problems efficiently, which is also very important in everyday coding. Apart from knowing, a programming language you also need to have good command on these key Computer fundamentals to not only qualify the interview but also excel in the top high paying jobs. This book assumes that you are a Ruby language developer. You are not an expert in Ruby language, but you are well familiar with concepts of class, references, functions, list, tuple, dictionary and recursion. At the start of this book, we will be revising Ruby language fundamentals that will be used throughout this book. We will be looking into some of the problems in Lists and recursion too. Then in the coming chapter we will be looking into Complexity Analysis. Followed by the various data structures and their algorithms. We will be looking into a Linked-List, Stack, Queue, Trees, Heap, Hash-Table and Graphs. We will also be looking into Sorting, Searching techniques. We will be looking into algorithm analysis of various algorithm techniques. Such as, Brute- Force algorithms, Greedy algorithms, Divide and Conquer algorithms, Dynamic Programming, Reduction and Backtracking. Preparation Plans Generally you have limited time before your next interview, it is important to have a solid preparation plan. The preparation plan depends upon the time and which companies you are planning to target. Below are the three-preparation plan for 1 Month, 3 Month and 5 Month durations. 1 Month Preparation Plans Below is a list of topics and approximate time users need to finish these topics. These are the most important chapters that must be prepared before appearing for an interview.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.