Skip to content

Instantly share code, notes, and snippets.

@V-Wong
Forked from jedavidson/2521_exercises.md
Created December 27, 2020 01:10
Show Gist options
  • Save V-Wong/983eaa98b71009c22c601d1df1f5f5e6 to your computer and use it in GitHub Desktop.
Save V-Wong/983eaa98b71009c22c601d1df1f5f5e6 to your computer and use it in GitHub Desktop.
A curated list of some good revision and exam preparation problems for UNSW's COMP2521. Personal opinion.

These exercises are some I did while studying for COMP2521, as well as some others which I've found afterwards which I think will be relevant. I've collected these problems mostly from LeetCode and HackerRank, which are excellent sites for practicing your coding abilities. Accounts on both sites will be necessary to do the problems listed.

The difficulty ranking is my opinion, but generally speaking here is what they mean:

  • Easy: problems that you should be able to do with minimal difficulty
  • Intermediate: problems that are a bit harder but doable; may take a little bit of thought and intuition
  • Challenges: problems that I think are difficult and/or interesting, if you're up for it; possibly beyond the scope of 2521

Based on past exams, most practical exam questions fall in the Easy and Intermediate categories, and more often than not in the Easy category. If you're able to solve the Easy and Intermediate problems without much difficulty, you're probably very well prepared for any exam questions you'll receive (curveballs notwithstanding).

I'm also additionally marking problems I'd recommend most (regardless of their difficulty ranking) with a star (★). These are the ones I think are the most important, either because they're fundamental or I think they'd be most similar to exam questions.

Some advice first

First, if it's crunch time and you don't have very long to prepare for your 2521 exam, attacking these exercises is not the best use of your time. The theory component is ultimately king in terms of marks allocated in the final exam, and unfortunately doing these exercises likely won't help you understand theory (though, you may learn a few useful things regardless). This list is intended for people who already have a good plan to study for theory, and are looking for something solid to supplement this to take care of studying for the practical section, since course materials can be hit or miss.

As for actually doing these, I strongly encourage you when you're doing these exercises to think of different ways to do the problem, looking to reduce your time and space complexity as much as possible. While having any solution that works is (usually) enough in an exam, you can learn a lot by trying to come up with more efficient algorithms. This is also a skill which will serve you well in the natural successor to this course, COMP3121/3821.

I also strongly recommend you to not look at the official solution or other users' solutions until you've come up with something on your own. It's too easy to see a solution to a problem and trick yourself into thinking "I would've come up with that!" prematurely; you're cheating yourself out of a valuable learning experience too. Beware that some C solutions you come across to these problems also do some things which go against best practices in COMP2521 (e.g. simply overwriting pointers between linked lists rather than freeing the underlying memory). Submissions on these websites don't take style into account, but I would encourage you to write your solutions under the assumption that your style is being taken into account.

Linked List Exercises

Easy

Intermediate

Challenges

Tree Exercises

Note that in some of these problems, the tree is not necessarily a search tree.

Easy

Intermediate

Challenges

Graph Exercises

Note that there is a disappointing number of good 2521-style graph problems available, so I'm mostly going to give ideas for problems. This obviously takes time, so apologies if this section is empty when you view this page. For exercises without a link, you're welcome to just theorise about how you'd solve it and describe solutions in pseudocode, or you can try to implement a graph, test cases and the actual solutions to these problems in C.

Easy

  • Find the sum of all even-numbered nodes in a graph ★
  • Find the node in a graph with maximum value ★
  • Count the number of edges in a graph ★
    • Think about how you'd do this for each representation of a graph you've learned.
  • Find the shortest path between two vertices in an unweighted, undirected graph

Intermediate

Challenges

  • Build a copy of a graph
    • The copy should be a deep copy, meaning that each node should be a distinct object in memory from the companion node in the original graph. Being cheeky and just returning the original graph is not how you should do this question!
  • Construct the transpose of a given graph
  • Count the number of strongly connected components in a graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment