Skip to content

Commit 7d6428a

Browse files
authored
2521 23t3 recording and new 1511 prac problems (#257)
* 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
1 parent 4162fb0 commit 7d6428a

18 files changed

+127
-8
lines changed

data/articles/2521-revision-theory.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ author: CSESoc Education Team
99
coverPhoto: '/images/generic/alexandru-acea-XEB8y0nRRP4-unsplash.jpg'
1010
---
1111

12-
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.
12+
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.
1313

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

1616
<MultiChoice>
1717
<MultiChoice.Question>

data/course-revision/1511-23T2.mdx renamed to data/course-revision/1511-23T3.mdx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: CSESoc COMP1511 Revision Practice Problems
3-
desc: Practical coding exercises to help you prepare for your COMP1511 23T2 final exam 😄
3+
desc: Practical coding exercises to help you prepare for your COMP1511 23T3 final exam 😄
44
course: COMP1511
5-
offering: 23T2
5+
offering: 23T3
66
---
77

88
# CSESoc COMP1511 Revision Practice Problems
99

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

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

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

3535
<br />
3636

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

4139
<figure class="video_container">
4240
<iframe
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: 2D Malloc
3+
desc: Malloc a variable-size 2D array of ints!
4+
class: COMP1511
5+
difficulty: 2
6+
---
7+
8+
# 2D Malloc
9+
10+
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.
11+
12+
In other words, he wants to create some array `int array[rows][cols]`.
13+
14+
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!
15+
16+
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`.
17+
18+
- `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]`.
19+
- `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.
20+
21+
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.
22+
23+
The output should look exactly like the following:
24+
25+
```bash:~/1511-revision/2d_malloc
26+
$ dcc --leak-check 2d_malloc.c -o 2d_malloc
27+
$ ./2d_malloc 10 10
28+
0 1 2 3 4 5 6 7 8 9
29+
10 11 12 13 14 15 16 17 18 19
30+
20 21 22 23 24 25 26 27 28 29
31+
30 31 32 33 34 35 36 37 38 39
32+
40 41 42 43 44 45 46 47 48 49
33+
50 51 52 53 54 55 56 57 58 59
34+
60 61 62 63 64 65 66 67 68 69
35+
70 71 72 73 74 75 76 77 78 79
36+
80 81 82 83 84 85 86 87 88 89
37+
90 91 92 93 94 95 96 97 98 99
38+
```
39+
40+
## Assumptions/Restrictions/Clarifications
41+
42+
- You may assume there is enough memory to allocate the array on the heap.
43+
- You may **not** store the arrays on the stack.
44+
- You do not need to worry about a horrific eldritch abomination destroying your computer midway through runtime.
45+
46+
## CSE Autotest
47+
48+
When you think your program is working, you can use CSE autotest to test your solution.
49+
50+
```bash:~/1521-revision/2d_malloc
51+
$ 1511 csesoc-autotest 2d_malloc
52+
```
53+
54+
## Solution
55+
56+
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T1-problems/blob/main/solutions/2d_malloc/solution.c).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Rotate Linked List
3+
desc: Rotate a linked list right!
4+
class: COMP1511
5+
difficulty: 2
6+
---
7+
8+
# Rotate Linked List
9+
10+
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`.
11+
12+
For example:
13+
14+
<img
15+
src="/images/comp1511-revision/diagram.png"
16+
alt="linked_list_rotation_example"
17+
width="800"
18+
height="474"
19+
/>
20+
21+
The output should look exactly like the following:
22+
23+
```bash:~/1511-revision/list_rotate
24+
$ dcc list_rotate.c -o list_rotate
25+
$ ./list_rotate
26+
How many numbers in list?: 5
27+
0 1 2 3 4
28+
What number to rotate by?: 0
29+
[0, 1, 2, 3, 4]
30+
$ ./list_rotate
31+
How many numbers in list?: 5
32+
0 1 2 3 4
33+
What number to rotate by?: 2
34+
[3, 4, 0, 1, 2]
35+
$ ./list_rotate
36+
How many numbers in list?: 5
37+
0 1 2 3 4
38+
What number to rotate by?: 6
39+
[4, 0, 1, 2, 3]
40+
```
41+
42+
## Assumptions/Restrictions/Clarifications
43+
44+
- You may assume that `steps >= 0`.
45+
- You may assume that the list is non-empty.
46+
- 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).
47+
- You may **_not_** assume that `steps <= list length`.
48+
- Do not change any existing functions other than `rotate`. You may make your own functions if wish.
49+
- You do not need to worry about a horrific eldritch abomination destroying your computer midway through runtime.
50+
51+
## CSE Autotest
52+
53+
When you think your program is working, you can use CSE autotest to test your solution.
54+
55+
```bash:~/1511-revision/list_rotate
56+
$ 1511 csesoc-autotest list_rotate
57+
```
58+
59+
## Acknowledgements
60+
61+
The starter code for this exercise was largely taken from the Week 08 COMP1511 lab exercise — "Reverse a Linked List".
62+
63+
## Solution
64+
65+
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T1-problems/blob/main/solutions/list_rotate/solution.c).
125 KB
Loading

0 commit comments

Comments
 (0)