Do I need to know Algorithms and Data Structures?

Started by
14 comments, last by Keinier 7 years, 10 months ago

Hello again, and sorry for asking many questions, the most complex games I've made are breakout and snake, and I was wondering if I should learn Algorithms and Data Structures before I make more games, will learning them make it easier for me to make games? I am planning to make sudoku next then tetris and I've heard I can't make sudoku without understanding Data Structures well. Also, what algorithms should I learn? Thank you for your time! :)

Dream in the shadows

Advertisement

You'll need to know about many basic algorithms and data structures, yes. You probably don't need to stop what you're doing, get a book, and read it before you move forward with making more complex games though. You can learn about them concurrently while you continue to develop games. You also don't need a book to do so, you can find very good information online, but a book may help focus you or may be a better way for you to learn.

You don't need to per se, but it will help immensely. Data structures and algorithms are the bread and butter of computer software. Sudoku in particular will be painful and bug-ridden if you don't at least understand the fundamentals of tree searches.

Regarding what algorithms to learn, it's hard to say. Searching and sorting are the barest of the fundamentals. You really can't learn too much about the subject, but that might be a good start. Maybe find an introductory computer science textbook at a library or some such. I don't have a good example, but you'll find a lot literally called "Data Structures and Algorithms". Some of them teeter on the more advanced side (i.e. for a third-year CS student), but many of them should be suitable for beginners.

Yes you need to know them. You know some already.

Every action you take in programming is an algorithm. Every series of tasks, every command you write, every function, these are algorithms.

Every object you create, every class and struct, every array, these are data structures. Any time you work with pieces of data it is a data structure.

Studying them will help you learn alternate ways to do things. One example is sorting. Sorting is something done constantly, and there are many different ways to sort things. There are sorting algorithms that are best when collections are randomized, others that are best when they are already nearly sorted, others that are best when particular patterns appear. There are also many structures for sorting, such as heaps and trees, where the structure of the data can contain the sort information and maintain the sort with little data motion.

There are a few hundred common structures and algorithms that are used everywhere, so learning and studying them is important. The same algorithm game programmers use to find a path across a map is the same one used to find the best route through traffic, to find the correct spelling in a spell checker, and find the best match in a web search engine. Data structures pair tightly with the algorithms that use them. Typically when you study one you can guess at the other; see a data structure and you can tell the algorithms that work with it, see an algorithm and you can tell the data structures that work with it.

Learning the core algorithms and data structures, and then learning how to apply them, is a skill great programmers share.

If you have lots of if statements that skips execution 99% of the time and you know some that will always be false then pre-buffering the positive and plausible ones can improve cache locality and avoid stalling hyper-threading with calculations that would otherwise be done and thrown away. Learning about broad phases is essential for both physics and game logic so that the games can scale up without lagging.

Thank you guys! I've started reading an algorithms and data structures book, and I am trying to make a tetris game at the same time, but I couldn't start out, so I looked for source code online to help me start, but I really don't understand anything about how the grid is implemented and how the blocks are stored in it and stuff, should I complete reading the book before I do anything more?

Dream in the shadows

No. Keep reading the book, but keep trying to make Tetris. Just don't look at other people's code. Do it yourself, think through the problems yourself.

If you get stuck and have specific questions about something you can't figure out how to do, make a new thread here asking about them; explain what you want to do, show what you tried already, and talk about what you're stuck with.

Okay, thank you so much! :)

Dream in the shadows

Just to edge you on... knowing Data Structures will actually help you understand some of the most complex techniques used in game design and software engineering. And I don't mean just the use case, I mean their purpose, their functionality, the discrete math behind it, and their properties.

Knowing those will make a huge difference in how maintainable and performant your code becomes. It's the same with Algorithms, though the idea of Algorithms when it's taught is not to teach you some of the common algorithms, but to teach you the methods used to make them and to find an efficient way to solve a problem given a list of specifications. There's a number of techniques that goes into this that are used to make different algorithms.

Nope.

Well, it depends on what language you're working in. If you're going all hard core in C++ and are planning on being a professional game developer, then yes... eventually.

Frob makes a good point that all computer code is algorithms. Your book is talking about specific common algorithms that every very serious programmer should probably have some concept of.

But in pretty much everything today, those algorithms and data structures are implemented for you. Even in C++ now we have STL. 1,000 times moreso in any other language. Do you really need to study how to rewrite STL? Not really. No. If you just learn to use STL properly you can write code just as effectively. In C# or Java you're never going to write double linked generic dynamic lists. You just won't.

You should probably know the difference between a stack and queue and LIFO and FIFO on a conceptual level. But really you are probably better off studying STL in C++ than Data Structures and Algorithms.

This topic is closed to new replies.

Advertisement