Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: raywenderlich Tutorial Team, Irina Galata, Matei Suica

Rating No ratings yet

Learn Data Structures & Algorithms in Kotlin! Data structures and algorithms are fundamental tools every developer should have. In this book, you'll learn how to implement key data structures in Kotlin, and how to use them to solve a robust set of algorithms. This book is for intermediate Kotlin or Android developers who already know the basics of the language and want to improve their knowledge. Topics Covered in This Book Introduction to Kotlin: If you're new to Kotlin, you can learn the main constructs and begin writing code. Complexity: When you study algorithms, you need a way to compare their performance in time and space. Learn about the Big-O notation to help you do this. Elementary Data Structures**: Learn how to implement Linked List, Stacks, and Queues in Kotlin. Trees: Learn everything you need about Trees — in particular, Binary Trees, AVL Trees, as well as Binary Search and much more. Sorting Algorithms: Sorting algorithms are critical for any developer. Learn to implement the main sorting algorithms, using the tools provided by Kotlin. Graphs: Have you ever heard of Dijkstra and the calculation of the shortest path between two different points? Learn about Graphs and how to use them to solve the most useful and important algorithms. About the Tutorial Team The Tutorial Team is a group of app developers and authors who write tutorials at the popular website raywenderlich.com. We take pride in making sure each tutorial we write holds to the highest standards of quality. We want our tutorials to be well written, easy to follow, and fun. If you've enjoyed the tutorials we've written in the past, you're in for a treat. The tutorials we've written for this book are some of our best yet — and this book contains detailed technical knowledge you simply won't be able to find anywhere else.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide that teaches you to build essential data structures from scratch in Kotlin and apply them to classic algorithms, written for intermediate Kotlin or Android developers who want to sharpen their problem-solving skills and ace technical interviews. 【Book Arc】 - **Opening (~0%–15%)**: Sets the foundation with a Kotlin refresher covering variables, functions, generics, and the standard library's List and Map, then introduces Big-O notation as the lens for comparing algorithm performance in time and space. - **Early (~15%–35%)**: Builds elementary data structures hands-on — linked lists (with node manipulation, iteration, and challenges like reversing), stacks, and queues — while comparing implementation trade-offs such as ArrayList versus linked-list backing. - **Middle (~35%–55%)**: Moves into trees, covering general tree traversal strategies (depth-first and level-order) and then binary trees with in-order and pre-order traversal, plus serialization concerns. - **Late (~55%–80%)**: Extends into balanced trees (AVL) and binary search, then tackles sorting algorithms implemented with Kotlin's tools, connecting structure choice to algorithmic efficiency. - **Ending (~80%–100%)**: Closes with graphs, including shortest-path problems like Dijkstra's algorithm, showing how the structures built earlier combine to solve real-world routing and search problems. 【Key Takeaways】 - **Complexity analysis is the backbone of the book** (Opening): Big-O notation is introduced early and revisited throughout, teaching you to drop constants and focus on the dominant growth term — the skill that makes every later trade-off discussion meaningful. - **Lists hide a costly insertion problem** (Early): Inserting anywhere but the end forces every subsequent element to shift, an O(n) operation that grows with list size — motivating the linked list as an alternative. - **Linked lists trade random access for cheap pointer surgery** (Early): You implement nodes, push/pop, and iteration from scratch, learning that removing the last node still requires a full traversal without a back-reference. - **Queues have no single best implementation** (Middle): ArrayList queues dequeue in linear time, linked-list queues achieve O(1) but pay allocation overhead, ring buffers suit fixed sizes, and a two-stack approach gives amortized O(1) with better spatial locality. - **Tree traversal strategy depends on the problem** (Middle): Depth-first and level-order (breadth-first) traversals serve different needs, and level-order uses a queue as an intermediary container at O(n) time and space. - **Binary tree traversals follow strict ordering rules** (Middle): In-order visits left-most first then the value then right; pre-order visits the current node first — each produces different useful orderings. - **Naive deserialization can be quadratic** (Middle): Repeatedly calling removeAt on an array yields O(n²), a concrete example of how implementation choices silently degrade performance. - **Graphs unify the earlier toolkit** (Ending): Shortest-path algorithms like Dijkstra's rely on the queues, trees, and complexity reasoning built in prior chapters. 【Reading Tips】 - **Skim the Kotlin refresher if you're already comfortable** with the language; the generics and mutability discussion is worth a careful read since it underpins every custom structure. - **Deep-read the complexity chapter** — it's short but it's the conceptual key to everything that follows, and the book returns to it implicitly in every trade-off table. - **Type out the implementations rather than reading them**; the value is in the pointer manipulation and edge cases (empty structures, single elements, index bounds) that only surface when you run the code. - **Do the end-of-chapter challenges** — they consolidate each structure before you move on, and solutions are provided for self-checking. - **Pay attention to the strengths-and-weaknesses summaries** after each implementation; they're the book's most interview-relevant content. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half of the book in detail; later chapters on AVL trees, sorting, and graphs are represented mainly by the table of contents and brief mentions, so specific algorithms and their implementations in those sections are not fully covered here.
Excerpt 1
tutorials we've written in the past, you're in for a treat. The tutorials we've written for this book are some of our best yet — and this book contains detai...
View in text
Excerpt 2
ng a small number, like 2, you’ll get the following output: | 1 x 1 = 1 | 1 x 2 = 2 | | 2 x 1 = 2 | 2 x 2 = 4 | This time, the function prints all of the pro...
View in text
Excerpt 3
o mergeSorted immediately below the declaration for result and right above return result: // 1 var left = nodeAt(0) var right = otherList.nodeAt(0) // 2 whil...
View in text
Excerpt 4
evel-order traversal continues until your queue is empty. 3. Inside the first while loop, you begin by setting nodesLeftInCurrentLevel to the current element...
View in text
Excerpt 5
uld have become a long, unbalanced chain of right children. Revisi6ng remove Retrofitting the remove operation for self-balancing is just as easy as fixing i...
View in text
Excerpt 6
Returns true because the element was inserted with success. The overall time complexity here is the complexity of the sort implementation, because the add op...
View in text
Excerpt 7
hms. It’s relatively simple to understand, and serves as a great introduction to how to divide and conquer algorithms work. Merge sort is O(n log n), and thi...
View in text
Excerpt 8
T>, destination: Vertex<T>): Double? } enum class EdgeType { DIRECTED, UNDIRECTED } This interface describes the common operations for a graph: • createVerte...
View in text
Tags
AI categories
KotlinProgramming
ISBN: 1942878915
Publisher: Razeware LLC
Publish Year: 2019
Language: English
Pages: 424
File Format: PDF
File Size: 20.0 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…