We may earn an affiliate commission when you visit our partners.
Packt Publishing

Rust is a modern systems programming language designed with safety to simplify the development of large, complex software projects. Data structure and Algorithms are key to help in the collection and organization of the data for performing operations on the data and set instructions/logic to accomplish tasks in these projects. This course will be your guide for implementing classic data structures and algorithms in Rust, helping you to get up and running as a confident Rust programmer.

Read more

Rust is a modern systems programming language designed with safety to simplify the development of large, complex software projects. Data structure and Algorithms are key to help in the collection and organization of the data for performing operations on the data and set instructions/logic to accomplish tasks in these projects. This course will be your guide for implementing classic data structures and algorithms in Rust, helping you to get up and running as a confident Rust programmer.

You will begin with a primer to Rust and its syntax. You will then explore the language of Time and Memory complexity by comparing different sorting methods. You’ll then learn about Lists and Binary Trees, implement them, and compare them, to show the advantages and use cases of each. Next, you will cover different algorithms in-depth such as sorting, graph, dynamic programming, greedy, divide and conquer, and more. You will learn how counterintuitive techniques can actually make it easier to build scalable projects.

By the end of the course, you will have a sound knowledge of the key data structures and algorithms in Rust to confidently implement them in your applications.

About the Author

Matthew Stoodley is a programming expert and enthusiast, who was drawn to learn about Rust and master its features initially due to its low power usage and memory safety capabilities. He primarily uses Rust to build board games.

In addition, he also possesses several years of experience in Go, PHP, and JavaScript.

Enroll now

What's inside

Learning objectives

  • How rust can help you keep your memory access safe and effective
  • How we can use rust to build generic algorithms that we can use again and again across our codebase
  • Greedy, dynamic, and iterative algorithms and when to use them
  • Different data structures such as maps, trees, and linked lists, and when it is appropriate to use them.
  • Why and how an entity component system separates the different parts of the object into different storage areas
  • How we can build files that work like simple databases using btrees
  • How we can run our programs even faster-using multithreading

Syllabus

Getting to Grips with Rust and its Syntax

This video provides an overview of the entire course.

We need a mechanism to run the code we are writing. So, we need to get the Rust compiler installed.

   •  Download Rustup.sh

   •  Run rustup

   •  Build a simple Hello World project

Read more

In order to do anything in programming in Rust, we need ways to organize our data.

   •  Introduce the Struct

   •  Introduce the Enum

   •  Get printouts of each showing what they can do and hold

Some functions may need to let the caller know there was a problem. How can we pass that message back?

   •  Introduce the Result and Option enum types

   •  Demonstrate how these works generically

   •  Show a function returning an Error

Every program needs to perform some task multiple times. How can we do that in Rust?

   •  Introduce the loop, while, and for

   •  Show how an iterator works by returning an option

   •  Demonstrate a for loop on a new iterator type

Programs often need to grab memory to be able operate. Can we understand when they need to?

   •  Introduce the stack

   •  Demonstrate the stack in a set of function calls

   •  Show how the stack can be avoided in tail recursive situations

Making sure that our code does not write to something it should not, is tricky. How can we work with the Rust compiler?

   •  Show how an object can be copied between variables

   •  Show that in order to change a variable which need to make it mutable

   •  Show how these two features interact

Rust protects us from pointing to things that do not exist anymore. How can we work with this?

   •  Introduce the borrow notation for pointers

   •  Show how when you have a pointer to something, you cannot change it elsewhere

   •  Demonstrate that mutable pointers require mutable objects

How do we handle objects where we do not know how big they will need to be?

   •  Demonstrate how a pointer is needed to make a linked list

   •  Show how Box creates that pointer

   •  Build Dynamic arrays using vec

In this video, we will look at the difference between Str and String.

   •  Understand their differences

   •  Explore their uses

How can we make our code available to others to use?

   •  Show how to get a token from crates

   •  Show how to set up our crates for upload

   •  Show how to upload our crate and check it is uploaded

Test your knowledge
Algorithm Complexity and Sorting Algorithms

What is the simplest way we can sort a list?

   •  See if each element should swap left in the vec

   •  Repeat until sorted

   •  Calculate how long this takes to run and if we can save time

Can we go faster when sorting data?

   •  Introduce the concept of divide and conquer

   •  Show how to split the data into two smaller sections to sort

   •  Bring those two small sorted lists together in linear time

Can we do it without needing to grab so much memory?

   •  Show how to pivot data around a single item

   •  Sort the two sides separately

   •  Test that it works

How can random numbers help us build faster solutions?

   •  Show that quick sort worst case is n squared

   •  Create a random generator

   •  Add that to our quick sort and show that removes the worst case

Can we use all our processors to speed up the operation?

   •  Introduce threading

   •  Explain why this case unsafe and why it must

   •  Show how this works across all the threads

Can we limit the number of threads we use to solve a problem?

   •  Introduce the Rayon library

   •  Show how the join method uses threads

   •  Implement quick sort to use join

How can we avoid performing the same calculation?

   •  Show how a naive fibonacci calls the same function many times

   •  Show how iterative solutions avoid that

   •  Show how by storing previously calculated results, we can save ourselves a lot of calculation

Can we do better than a greedy solution?

   •  Introduce an iterative method

   •  Generate a random path

   •  Make random changes only keeping improvements

Building Linked Lists and Binary Trees

How can we store lists in the simplest way possible?

   •  Show how we can use Box to make a list

   •  Append and remove elements

   •  Show how linked list is fast for the front but not the back

How can we access both ends of a linked safely?

   •  Introduce Rc and Weak

   •  Show why one direction must be Weak

   •  Add and remove elements from both ends of the list in linear time

How can we add data to a list in just Log(n) time?

   •  Introduce trees that have two branches

   •  Show how to add data to a list

   •  Show how to read data back in order

What if we add data in a sorted manner, doesn’t that create just a linked list?

   •  Show that adding sorted data wastes the binary tree

   •  Demonstrate tree rotation

   •  Use stored heights to calculate when to rotate the tree

How can we use random data to quickly find tree elements?

   •  Introduce the idea of a layered linked list

   •  Show how the random data allows us to access parts quickly

   •  Begin building the skip list

Can we finish this skip list?

   •  Add a layer tracker to the front of the list

   •  Show how we can flip a coin to add layers as needed

   •  Test our skip list

How can Trees be used to compress data?

   •  Create a Huffman tree

   •  Show how this puts frequent elements near the top

   •  Show how to compress and decompress a string of data

Model Real Situations as Graphs of Connected Nodes

What is the best way to store a graph?

   •  Introduce different options for storing a graph

   •  Show the costs and benefits of each

   •  Select one for the rest of this section

In order to test it, our graph needs data.

   •  Make sure our graph has enough add and delete methods

   •  Add data to the graph

   •  Look at the data we have added and how it works

How can we store routes in a composable way?

   •  Show how Rc can have many clones

   •  Show many routes with the same beginning

   •  Get our routes printable

How can we find the shortest path between two points on the graph?

   •  Add all paths from the start node to a list

   •  Take the shortest path on the list and repeat from there

   •  Do not search from the node we have already searched from

How can we solve complicated problems on such as the Traveling Salesman on graphs?

   •  Introduce Traveling Salesman

   •  Introduce greedy algorithms

   •  Try a greedy algorithm to solve Traveling Salesman

How can me make sure we do not treat a new element as an old one?

   •  Introduce generation tracking

   •  Show how we can do this all in constant time across many adds and drops

   •  Build a complete generation manager

Getting Constant Time Data Access Using HashMap

Can we store data with constant time access?

   •  Introduce the idea of a HashMap

   •  Show how a set of buckets can be selected from

   •  Explain we are going to build this

How do we choose a random, but consistent bucket?

   •  Introduce the idea of a Hasher

   •  Show how the Hash and Hasher Traits work together

   •  Build a Hasher

Can we create a functioning bucket list?

   •  Create a list of buckets that stores data based on its hash

   •  Show how we can add and remove data from this list

   •  Test it

How can we get our HashMap to grow without needing to break our const time rules?

   •  Create a wrapper around two Bucket Lists

   •  When one bucket is too full, create a new bigger one

   •  Move the data across in small chunks

Can we know for sure our HashMap does what it should?

   •  Build tests for inserting into our HashMap

   •  Build tests for the growth of our HashMap

   •  Show that we need to double the size every time

When should we use which kinds of maps or sets?

   •  Show how Rust optimizes maps to act as sets

   •  Show when each kind of map is more appropriate

   •  Show when each kind of map is less appropriate

Organizing Your Data by Type with Entity Component Systems

How can we organize our data for real time processing on modern systems?

   •  Introduce ECS

   •  Show how it separates the components of an entity across stores

   •  Explain how systems then operate on the data

How do we store our data so that we cannot grab the wrong element by mistake?

   •  Show the kinds of operations a store need

   •  Show how we can use a Vec store with marked generations

   •  Show how we can loop over the elements in a store

How do the systems of ECS interact with each other?

   •  Show how simple systems can loop over the data they need

   •  Show how more complex systems can loop in different ways

   •  Build all the systems needed for a simple CLI game

How can we run this ECS game?

   •  Show how to access the terminal and raw input

   •  Show how we can count passes

   •  Show how we can manage quitting our application

Are there any tools to make doing ECS easier?

   •  Introduce the Specs crate

   •  Show a simple example from the Specs docs

   •  Explain each part of the code required

Persistent Storage Data Structure

How can we maintain persistent data with fast access?

   •  Explain the new problems of data size when working across files

   •  Prepare the crate with needed libraries

   •  Prepare an error type to handle the Blob store we are building

How can we make any data work as a string of bytes

   •  Create a Blob store type

   •  Show how Serdes and bincode make conversions possible

   •  Test our Blob object

How can we access the file with Random Access?

   •  Show how we can create a file

   •  Set up the control data for a new file

   •  Open an existing file and read the control data

How can we add data to the file?

   •  Show how we can add data with marked length

   •  Show how we can find the right place to add it

   •  Test we can add data

How can we read data from the file?

   •  Show that we can find the data following the same path

   •  Show that we can convert it back to the right type

   •  Test we get the right data back

How can we remove data from the file?

  • Show that when we remove data, we now have two blocks that need to be joint

  • Join the two blocks

  • Test that remove works as expected

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Explores Rust, a modern systems programming language known for memory safety, making it suitable for developing robust and complex software projects, which may appeal to developers seeking safer coding practices
Covers time and memory complexity analysis, which is essential for optimizing algorithms and data structures in Rust, enabling developers to write efficient and performant code for resource-constrained environments
Teaches how to build files that function as simple databases using BTrees, which is valuable for Rust developers who need to implement persistent storage solutions with efficient data retrieval capabilities
Uses the Specs crate, which may require learners to familiarize themselves with external libraries and dependencies, potentially adding complexity to the learning process for those new to Rust
Examines multithreading in Rust, which is crucial for leveraging modern hardware and improving application performance, but also introduces complexities related to data races and synchronization that learners should be aware of
Features an author who uses Rust to build board games, which may not be directly applicable to all learners' interests or professional goals, potentially limiting the course's appeal to a niche audience

Save this course

Save Hands-On Data Structures and Algorithms in Rust to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Hands-On Data Structures and Algorithms in Rust with these activities:
Review Basic Rust Syntax
Reinforce your understanding of fundamental Rust syntax, including data types, control flow, and basic ownership concepts, to prepare for the course's more advanced topics.
Browse courses on Rust
Show steps
  • Read through the official Rust documentation on basic syntax.
  • Write small Rust programs to practice using different syntax elements.
  • Complete online Rust syntax quizzes or exercises.
Read 'The Rust Programming Language'
Gain a comprehensive understanding of Rust's core concepts and features by reading the official Rust book, which will serve as a strong foundation for the course.
Show steps
  • Obtain a copy of 'The Rust Programming Language' book.
  • Read the chapters covering basic syntax, ownership, and data structures.
  • Work through the examples and exercises provided in the book.
Implement Sorting Algorithms
Solidify your understanding of sorting algorithms by implementing them in Rust, focusing on performance and memory usage.
Browse courses on Sorting Algorithms
Show steps
  • Choose a few sorting algorithms (e.g., bubble sort, merge sort, quicksort).
  • Implement each algorithm in Rust.
  • Compare the performance of different sorting algorithms using benchmarks.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Blog Post: Comparing Data Structures in Rust
Deepen your understanding of data structures by writing a blog post comparing their implementations and performance characteristics in Rust.
Browse courses on Data Structures
Show steps
  • Select a few data structures (e.g., linked lists, binary trees, hash maps).
  • Research their implementations and performance characteristics in Rust.
  • Write a blog post comparing and contrasting the data structures.
  • Publish the blog post on a personal blog or platform like Medium.
Build a Simple CLI Game with ECS
Apply your knowledge of Entity Component Systems (ECS) by building a simple command-line interface (CLI) game in Rust, reinforcing the concepts covered in the course.
Browse courses on ECS
Show steps
  • Design a simple CLI game (e.g., a text-based adventure game).
  • Implement the game using an ECS architecture in Rust.
  • Add features and complexity to the game over time.
Contribute to a Rust Data Structures Library
Enhance your understanding of data structures and algorithms by contributing to an open-source Rust library, gaining practical experience and collaborating with other developers.
Browse courses on Data Structures
Show steps
  • Find an open-source Rust library related to data structures and algorithms.
  • Identify a bug or feature request to work on.
  • Implement the fix or feature and submit a pull request.
  • Respond to feedback and iterate on your contribution.
Read 'Programming Rust'
Expand your knowledge of Rust with 'Programming Rust', which offers a deeper dive into advanced topics and real-world applications.
Show steps
  • Obtain a copy of 'Programming Rust' book.
  • Read the chapters covering advanced topics like concurrency and error handling.
  • Experiment with the examples and exercises provided in the book.

Career center

Learners who complete Hands-On Data Structures and Algorithms in Rust will develop knowledge and skills that may be useful to these careers:
Software Engineer
A software engineer designs, develops, and maintains software applications. This course focused on data structures and algorithms in Rust serves as an excellent foundation for this role. Software engineers need a deep understanding of data structures and algorithms to write efficient and scalable code. The course's exploration of time and memory complexity, along with different sorting methods, maps, trees, linked lists, and graph algorithms, directly enhances a software engineer's ability to create robust and performant applications. Learning how to implement these concepts in Rust makes this course useful for any software engineer seeking to use this language.
Systems Programmer
A systems programmer focuses on developing and maintaining low-level software, such as operating systems, device drivers, and embedded systems. This course is particularly relevant, as it delves into Rust, a language known for its safety and performance in systems programming. The course's emphasis on memory management, concurrency, and data structures like linked lists and hash maps provides a solid understanding for a systems programmer. The course's discussion on multithreading and its implementation in Rust is directly applicable to this role, and the exploration of file handling as simple databases using BTrees is quite useful for systems applications.
Game Developer
Game developers create video game software. This course will be useful for a game developer due to its focus on data structures and algorithms in Rust. Game development often involves designing and implementing complex systems with strict performance requirements, for which a solid understanding of data structures and algorithms is essential. Furthermore, the course's use of Rust is highly pertinent for game development, as its memory safety and speed are advantageous. The course's coverage of Entity Component Systems is also helpful, as this pattern is regularly used to create game engines. The course author's experience using Rust for board games also makes this well-suited for those interested in pursuing game development.
Algorithm Developer
An algorithm developer specializes in creating and optimizing algorithms for various applications. This course will help algorithm developers, as it provides practical experience using data structures and algorithms in Rust. The course covers core concepts of algorithm design and implementation, such as sorting, graph, dynamic programming, and greedy algorithms, all of which are fundamental for algorithm development. Furthermore, the course's in-depth exploration of algorithm complexity, including time and space requirements, which are essential for creating efficient solutions, will be very useful. The course goes into advanced topics such as multithreading, which will be valuable for algorithm developers seeking parallelization opportunities.
Embedded Systems Engineer
An embedded systems engineer develops software for embedded systems, such as those found in microcontrollers and sensors. For this role, the course is a good fit due to its use of Rust, a modern language which combines safety and performance. The course's emphasis on low-level memory management, data structures, and algorithm efficiency, is crucial for embedded systems development. The discussion of memory management and multithreading in Rust are particularly relevant, and the hands-on approach to implementing data structures like linked lists, binary trees, and hash maps prepares you to write efficient code for resource-constrained environments typical of embedded systems.
Backend Developer
A backend developer works on server-side logic, databases, and APIs. This course provides backend developers with a foundation in data structures and algorithms, which is necessary for building efficient and scalable backend systems. The course covers various important data structures and algorithms, such as trees, lists, hashmaps, and graph algorithms, all of which are essential for any backend developer. The course's use of Rust is also helpful, as it is becoming more common in backend development because of its speed and security. The course's in-depth exploration of algorithm complexity helps improve the performance of backend systems, making it useful for any backend developer.
Data Scientist
Data scientists analyze, interpret, and visualize data, often using programming to extract insights. While this might not be the first role that comes to mind, a data scientist sometimes needs to implement their own algorithms or data structures where existing libraries fall short. This course will be helpful to data scientists looking to better understand the implementation, runtime, and memory usage of various structures. The course covers many structures relevant to data analysis, such as graphs and trees, which helps with building data products. The course's coverage of hashing is also useful for large datasets. The course may be useful for data scientists looking to optimize performance.
Performance Engineer
A performance engineer focuses on identifying and eliminating performance bottlenecks in software systems. This course may be useful for a performance engineer, as it provides a hands-on approach to implementing data structures and algorithms in Rust, which is known for high performance. The course's detailed exploration of time and space complexity, different sorting methods, multithreading, and optimization techniques are directly relevant for identifying and addressing performance issues. Learning how to build performant data structures is also advantageous in reducing operational overhead. The course may be a useful addition to the skill set of a performance engineer.
Database Engineer
A database engineer designs, develops, and maintains databases. This course may be useful for a database engineer. While the course doesn't cover the specifics of database technologies, having a good understanding of data structures and algorithms will provide a foundation for creating performant and scalable database systems. The course covers a variety of relevant topics, such as trees, linked lists, and hash maps, which form the basis of many database index implementations. Additionally, the course discusses files as simple databases using BTrees, which, while not fully developed, can provide a useful introduction. This course may be useful for database engineers interested in learning more about the underlying implementation details of database systems.
Research Scientist
A research scientist conducts scientific research, often involving data analysis, algorithms, and software development. While this might not be the main area of focus, this course may be helpful for a research scientist. The course teaches the implementation of data structures and algorithms which are useful in many scientific domains. The course's coverage of time and memory complexity can assist a research scientist in choosing the correct approach. Additionally, the course touches on areas such as multithreading, which may be useful for speeding up computations. This course may prove valuable for research scientists seeking to implement their own data handling and processing techniques.
Robotics Engineer
A robotics engineer designs, builds, and programs robots. This course may be useful for a robotics engineer because it teaches low-level programming concepts, which is sometimes a requirement in the control systems of robots. The course discusses memory access, algorithm design, and data structures, all of which are useful in building efficient and performant software for robots. The use of Rust as a language is also particularly useful here as it combines both high performance and memory safety. Topics such as multithreading and concurrency can help robotics engineers design software for complex robotic systems. This course may be helpful for robotics engineers looking to gain a deeper understanding of programming patterns.
Data Engineer
A data engineer builds and maintains data pipelines and infrastructure. This course may be useful for a data engineer interested in understanding the implementation details of data structures. While the course's focus on low-level programming and algorithm design isn't always directly applicable to data engineering's higher level concerns, the course explores a variety of data structures (like maps, trees, and graphs) which make up the data warehouses, processing engines, and workflow systems that a data engineer works with regularly. This course may be useful to a data engineer who wants to expand their knowledge beyond the tools they regularly use.
Machine Learning Engineer
A machine learning engineer develops and deploys machine learning models. While this course does not directly teach machine learning, it may be useful for this professional. Machine learning engineers sometimes need to create or adapt algorithms for specific problems. The course covers many topics that may be useful in creating performant machine learning solutions, including algorithmic complexity, data structures such as trees, graphs, and hash maps, and advanced features such as multithreading. This course may be useful to machine learning engineers looking to implement their own algorithms.
Quantitative Analyst
A quantitative analyst, often called a quant, develops mathematical and statistical models for finance. While this course might not be directly applicable, a quant sometimes needs to implement custom algorithms based on their models. In this regard, the course's exploration of algorithm complexity, sorting methods, and dynamic programming may be helpful. The course's coverage of graphs may be useful for building networks which are often a part of quant models. This course may be useful for a quantitative analyst seeking to build high-performance algorithms.
DevOps Engineer
A DevOps engineer focuses on automating infrastructure and ensuring smooth software deployment. While this course is not directly aligned with the daily tasks of a DevOps engineer, it may be useful in particular cases. The course could be helpful in building or optimizing custom tooling. Additionally, knowledge of algorithm complexity, data structures, and multithreading might allow a DevOps engineer to understand the systems they deploy with more depth. This course may be useful to a DevOps engineer interested in better understanding the underlying performance aspects of software.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Hands-On Data Structures and Algorithms in Rust.
Is the official guide to Rust programming. It covers everything from basic syntax to advanced topics like concurrency and memory management. It's an excellent resource for both beginners and experienced programmers looking to learn Rust. This book provides a solid foundation for understanding the concepts covered in the course and serves as a valuable reference throughout your learning journey.
Provides a comprehensive introduction to Rust, covering topics such as ownership, borrowing, concurrency, and error handling. It's a great resource for experienced programmers who want to learn Rust. This book offers a deeper dive into Rust's features and provides practical examples for building real-world applications. It is particularly helpful for understanding the more nuanced aspects of Rust's memory safety and concurrency models.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser