An overview of data structures and algorithms in C
keep in mind this is a work in progress
When starting out in programming, it is common to perceive certain aspects or behaviors as ‘magical’.
For example, if the first language you have learned was JavaScript or Python, dynamic arrays and dictionaries/objects are often taken for granted. They work as intended, requiring only the reading of the API documentation to utilize them. There are no memory allocations, resizing, hashing functions, or other low-level implementation details to worry about.
Exploring the reasoning behind various data structures and how one can use them to implement algorithms may reduce the amount of magic involved in programming. It empowers newcomers in the field by building critical thinking skills and allowing them to make informed decisions.
I hope these examples end up being useful to someone
Contents
Chapter | Topic | Contents | Source |
---|---|---|---|
0 | Setting up a lab to work with C | A quick tutorial on how to create a development environment with docker | |
1 | Implementing a stack using an array | Overview on how a stack works and how to implement it with an array | link |
2 | Implementing a simple linked list | An explanation on how a linked list works and how to implement it | link |
3 | Creating a dynamic array | The differences between an static array an a dynamicaly sized array, with implementations | link |
4 | Checking for balanced braces in a string | A hands-on example on how to check for unbalanced braces in a string using the stack from chapter 01 | link |
5 | Implementing a hash table with separate chaining for collisions resolution | A step by step guide on how to implement a hash table | link |
How to start playing with the source code
If you want to skip all of the above, if you are a person who loves learning by reading code, you can clone the github repo.
To be able to play with the source without dealing with OS and build tools I would suggest to follow these steps:
- build and tag a docker container with everything needed. There is already a Dockerfile for this.
- Then run the container attaching an interactive terminal to it.
You can also map this repo to a folder inside the container to code in your host but use the build tools inside the container.
For example:
docker build -t clab .
docker run -v $(pwd)/:/app -it clab
Then, inside our container we can start working:
cd ./app/02_linked_list
make build
make run-tests
Note:
Keep in mind I’m not a C expert nor I know all the conventions for this language.
I will strive to keep all the examples and the source as correct as I can.
Also, If you read something odd, you can make a PR or fill an issue in the github repo.