Skip to content

Commit

Permalink
2521 23t3 recording and new 1511 prac problems (#257)
Browse files Browse the repository at this point in the history
* uploaded recording for 2521 rev sess

* updated 1511 page for 23t3

* added daniels 2d_malloc problem

* added 1511 rotate LL problem

* added 1511 linked list problem
  • Loading branch information
Allynixtor committed Nov 14, 2023
1 parent 4162fb0 commit 7d6428a
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 8 deletions.
4 changes: 2 additions & 2 deletions data/articles/2521-revision-theory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ author: CSESoc Education Team
coverPhoto: '/images/generic/alexandru-acea-XEB8y0nRRP4-unsplash.jpg'
---

This page has a set of practice questions that cover most topics in COMP2521 23T2 and will give you a chance to test your knowledge of data structures and algorithms.
This page has a set of practice questions that cover most topics in COMP2521 23T3 and will give you a chance to test your knowledge of data structures and algorithms.

Note that the theory questions in the real COMP2521 23T2 exam will not be multiple choice!
Note that the theory questions in the real COMP2521 23T3 exam will not be multiple choice!

<MultiChoice>
<MultiChoice.Question>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: CSESoc COMP1511 Revision Practice Problems
desc: Practical coding exercises to help you prepare for your COMP1511 23T2 final exam 😄
desc: Practical coding exercises to help you prepare for your COMP1511 23T3 final exam 😄
course: COMP1511
offering: 23T2
offering: 23T3
---

# CSESoc COMP1511 Revision Practice Problems

This is a set of practical programming problems designed to help you prepare for your COMP1511 23T2 final exam.
This is a set of practical programming problems designed to help you prepare for your COMP1511 23T3 final exam.

There are autotests for each problem on cse servers which you can use to check your solutions.

Expand All @@ -34,9 +34,7 @@ Links to sample solutions can be found at the bottom of each problem!

<br />

### [Pointers and Memory Slides]

(https://docs.google.com/presentation/d/1Iz8lKozedeIq5ECu0vN3ZPgnke88r2L5H7UIt9otwC8/edit?usp=sharing)
### [Pointers and Memory Slides](https://docs.google.com/presentation/d/1Iz8lKozedeIq5ECu0vN3ZPgnke88r2L5H7UIt9otwC8/edit?usp=sharing)

<figure class="video_container">
<iframe
Expand Down
56 changes: 56 additions & 0 deletions data/course-revision/1511-23T3/2d_malloc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: 2D Malloc
desc: Malloc a variable-size 2D array of ints!
class: COMP1511
difficulty: 2
---

# 2D Malloc

Daniel has been working on his COMP1511 assignment, but he wants to create a 2D `rows` x `cols` array of integers, where `rows` and `cols` are inputs to the program.

In other words, he wants to create some array `int array[rows][cols]`.

Unfortunately, the style guide for the course does not allow variable length arrays to be created on the stack, so Daniel must `malloc` his array. Of course, this also means he has to `free` all memory afterwards!

Daniel does not know how to dynamically allocate heap memory for a 2D array and free it afterwards, so your job is to implement the functions `allocate_array` and `free_array` in `malloc_two_dimension_array.c`.

- `int **allocate_array(int rows, int cols)` should take in two values, `rows` and `cols`, and should return the start of a heap-allocated array with bounds and behaviour which matches `int array[rows][cols]`.
- `void free_array(int **array, int rows, int cols)` should take in three values — `array` is the start of the array to be freed, `rows` and `cols` are the dimensions of the array.

The main function has already been included. This main function reads `rows` and `cols` as command line arguments, passes it to `allocate_array`, does some array operations, and then calls `free_array`. **Do not modify this function**, you may create new functions if you wish.

The output should look exactly like the following:

```bash:~/1511-revision/2d_malloc
$ dcc --leak-check 2d_malloc.c -o 2d_malloc
$ ./2d_malloc 10 10
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99
```

## Assumptions/Restrictions/Clarifications

- You may assume there is enough memory to allocate the array on the heap.
- You may **not** store the arrays on the stack.
- You do not need to worry about a horrific eldritch abomination destroying your computer midway through runtime.

## CSE Autotest

When you think your program is working, you can use CSE autotest to test your solution.

```bash:~/1521-revision/2d_malloc
$ 1511 csesoc-autotest 2d_malloc
```

## Solution

You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T1-problems/blob/main/solutions/2d_malloc/solution.c).
File renamed without changes.
65 changes: 65 additions & 0 deletions data/course-revision/1511-23T3/rotate_linked_list.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: Rotate Linked List
desc: Rotate a linked list right!
class: COMP1511
difficulty: 2
---

# Rotate Linked List

You are provided list_rotate.c. Implement the function `rotate` which, given the head of a linked list, the length of the list, and a non-negative integer input `steps`, rotates the list to the right by `steps`.

For example:

<img
src="/images/comp1511-revision/diagram.png"
alt="linked_list_rotation_example"
width="800"
height="474"
/>

The output should look exactly like the following:

```bash:~/1511-revision/list_rotate
$ dcc list_rotate.c -o list_rotate
$ ./list_rotate
How many numbers in list?: 5
0 1 2 3 4
What number to rotate by?: 0
[0, 1, 2, 3, 4]
$ ./list_rotate
How many numbers in list?: 5
0 1 2 3 4
What number to rotate by?: 2
[3, 4, 0, 1, 2]
$ ./list_rotate
How many numbers in list?: 5
0 1 2 3 4
What number to rotate by?: 6
[4, 0, 1, 2, 3]
```

## Assumptions/Restrictions/Clarifications

- You may assume that `steps >= 0`.
- You may assume that the list is non-empty.
- You may assume the list length will be less than 100 (but you shouldn't be hard coding any limits, it should theoretically work for any size).
- You may **_not_** assume that `steps <= list length`.
- Do not change any existing functions other than `rotate`. You may make your own functions if wish.
- You do not need to worry about a horrific eldritch abomination destroying your computer midway through runtime.

## CSE Autotest

When you think your program is working, you can use CSE autotest to test your solution.

```bash:~/1511-revision/list_rotate
$ 1511 csesoc-autotest list_rotate
```

## Acknowledgements

The starter code for this exercise was largely taken from the Week 08 COMP1511 lab exercise — "Reverse a Linked List".

## Solution

You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T1-problems/blob/main/solutions/list_rotate/solution.c).
Binary file added public/images/comp1511-revision/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d6428a

Please sign in to comment.