Hands-On Data Structures and Algorithms with Rust

Book description

Design and implement professional level programs by exploring modern data structures and algorithms in Rust.

Key Features

  • Use data structures such as arrays, stacks, trees, lists and graphs with real-world examples
  • Learn the functional and reactive implementations of the traditional data structures
  • Explore illustrations to present data structures and algorithms, as well as their analysis, in a clear, visual manner.

Book Description

Rust has come a long way and is now utilized in several contexts. Its key strengths are its software infrastructure and resource-constrained applications, including desktop applications, servers, and performance-critical applications, not forgetting its importance in systems' programming. This book will be your guide as it takes you through implementing classic data structures and algorithms in Rust, helping you to get up and running as a confident Rust programmer.

The book begins with an introduction to Rust data structures and algorithms, while also covering essential language constructs. You will learn how to store data using linked lists, arrays, stacks, and queues. You will also learn how to implement sorting and searching algorithms. You will learn how to attain high performance by implementing algorithms to string data types and implement hash structures in algorithm design. The book will examine algorithm analysis, including Brute Force algorithms, Greedy algorithms, Divide and Conquer algorithms, Dynamic Programming, and Backtracking.

By the end of the book, you will have learned how to build components that are easy to understand, debug, and use in different applications.

What you will learn

  • Design and implement complex data structures in Rust
  • Analyze, implement, and improve searching and sorting algorithms in Rust
  • Create and use well-tested and reusable components with Rust
  • Understand the basics of multithreaded programming and advanced algorithm design
  • Become familiar with application profiling based on benchmarking and testing
  • Explore the borrowing complexity of implementing algorithms

Who this book is for

This book is for developers seeking to use Rust solutions in a practical/professional setting; who wants to learn essential Data Structures and Algorithms in Rust. It is for developers with basic Rust language knowledge, some experience in other programming languages is required.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Data Structures and Algorithms with Rust
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Foreword
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the color images
      2. Download the example code files
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Hello Rust!
    1. Rust in 2018
      1. The 2018 edition
      2. The Rust language
        1. Objects and behavior
        2. Going wrong
        3. Macros
        4. Unsafe
    2. Borrowing and ownership
      1. Exceptional lifetimes
      2. Multiple owners
    3. Concurrency and mutability
      1. Immutable variables
        1. Shadowing
        2. Interior mutability
      2. Moving data
      3. Sharing data
      4. Send and Sync
    4. Deeper into Rust
      1. Requests for Comments (RFCs)
    5. Summary
    6. Questions
    7. Further reading
  8. Cargo and Crates
    1. Cargo
      1. Project configuration
        1. The manifest – Cargo.toml
          1. Package
          2. Profiles
          3. Dependencies
        2. Dependencies – Cargo.lock
      2. Commands
        1. The compile and run commands
        2. Testing
        3. Third-party subcommands
    2. Crates
      1. Rust libraries and binaries
        1. Static and dynamic libraries
        2. Linking and interoperability
          1. FFI
          2. Wasm
      2. The main repository – crates.io
        1. Publishing
    3. Summary
    4. Questions
    5. Further reading
  9. Storing Efficiently
    1. Heaps and stacks
      1. Sized and unsized
        1. Generics
      2. Accessing the box
    2. Copying and cloning
    3. Immutable storage
      1. States and reasoning
      2. Concurrency and performance
    4. Summary
    5. Questions
    6. Further reading
  10. Lists, Lists, and More Lists
    1. Linked lists
      1. A transaction log
      2. Adding entries
      3. Log replay
      4. After use
      5. Wrap up
        1. Upsides
        2. Downsides
    2. Doubly linked list
      1. A better transaction log
      2. Examining the log
        1. Reverse
      3. Wrap up
        1. Upsides
        2. Downsides
    3. Skip lists
      1. The best transaction log
        1. The list
      2. Adding data
        1. Leveling up
      3. Jumping around
      4. Thoughts and discussion
        1. Upsides
        2. Downsides
    4. Dynamic arrays
      1. Favorite transactions
      2. Internal arrays
      3. Quick access
      4. Wrap up
        1. Upsides
        2. Downsides
    5. Summary
    6. Questions
    7. Further reading
  11. Robust Trees
    1. Binary search tree
      1. IoT device management
      2. More devices
      3. Finding the right one
        1. Finding all devices
      4. Wrap up
        1. Upsides
        2. Downsides
    2. Red-black tree
      1. Better IoT device management
      2. Even more devices
        1. Balancing the tree
      3. Finding the right one, now
      4. Wrap up
        1. Upsides
        2. Downsides
    3. Heaps
      1. A huge inbox
      2. Getting messages in
      3. Taking messages out
      4. Wrap up
        1. Upsides
        2. Downsides
    4. Trie
      1. More realistic IoT device management
      2. Adding paths
      3. Walking
      4. Wrap up
        1. Upsides
        2. Downsides
    5. B-Tree
      1. An IoT database
      2. Adding stuff
      3. Searching for stuff
        1. Walking the tree
      4. Wrap up
        1. Upsides
        2. Downsides
    6. Graphs
      1. The literal Internet of Things
      2. Neighborhood search
      3. The shortest path
      4. Wrap up
        1. Upsides
        2. Downsides
    7. Summary
    8. Questions
  12. Exploring Maps and Sets
    1. Hashing
      1. Create your own
      2. Message digestion
      3. Wrap up
    2. Maps
      1. A location cache
        1. The hash function
      2. Adding locations
      3. Fetching locations
      4. Wrap up
        1. Upsides
        2. Downsides
    3. Sets
      1. Storing network addresses
      2. Networked operations
        1. Union
        2. Intersection
        3. Difference
      3. Wrap up
        1. Upsides
        2. Downsides
    4. Summary
    5. Questions
    6. Further reading
  13. Collections in Rust
    1. Sequences
      1. Vec<T> and VecDeque<T>
        1. Architecture
        2. Insert
        3. Look up
        4. Remove
      2. LinkedList<T>
        1. Architecture
        2. Insert
        3. Look up
        4. Remove
      3. Wrap up
    2. Maps and sets
      1. HashMap and HashSet
        1. Architecture
        2. Insert
        3. Lookup
        4. Remove
      2. BTreeMap and BTreeSet
        1. Architecture
        2. Insert
        3. Look up
        4. Remove
      3. Wrap up
    3. Summary
    4. Questions
    5. Further reading
  14. Algorithm Evaluation
    1. The Big O notation
      1. Other people's code
      2. The Big O
        1. Asymptotic runtime complexity
      3. Making your own
        1. Loops
        2. Recursion
      4. Complexity classes
        1. O(1)
        2. O(log(n))
        3. O(n)
        4. O(n log(n))
        5. O(n²)
        6. O(2n)
        7. Comparison
    2. In the wild
      1. Data structures
      2. Everyday things
      3. Exotic things
    3. Summary
    4. Questions
    5. Further reading
  15. Ordering Things
    1. From chaos to order
      1. Bubble sort
      2. Shell sort
      3. Heap sort
      4. Merge sort
      5. Quicksort
    2. Summary
    3. Questions
    4. Further reading
  16. Finding Stuff
    1. Finding the best
      1. Linear searches
      2. Jump search
      3. Binary searching
      4. Wrap up
    2. Summary
    3. Questions
    4. Further reading
  17. Random and Combinatorial
    1. Pseudo-random numbers
      1. LCG
      2. Wichmann-Hill
      3. The rand crate
    2. Back to front
      1. Packing bags or the 0-1 knapsack problem
      2. N queens
    3. Advanced problem solving
      1. Dynamic programming
        1. The knapsack problem improved
      2. Metaheuristic approaches
        1. Example metaheuristic – genetic algorithms
    4. Summary
    5. Questions
    6. Further reading
  18. Algorithms of the Standard Library
    1. Slicing and iteration
      1. Iterator
      2. Slices
    2. Search
      1. Linear search
      2. Binary search
    3. Sorting
      1. Stable sorting
      2. Unstable sorting
    4. Summary
    5. Questions
    6. Further reading
  19. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Data Structures and Algorithms with Rust
  • Author(s): Claus Matzinger
  • Release date: January 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781788995528