Lec 12 - Recap
Last updated
Last updated
Slides:
A very useful website recommended by Eldon:
A legit soul searching question. What have I learned in this course? I believe everyone more or less must learn something. But now, let's follow Prof Ooi's steps and have a look at what we've gone through together!
Beware of precision issue when using double
and float
This is legit awesome for me! The specific settings in the
clang
compiler legit force me to think "breaking a big problem into smaller ones"! It
bit operations in C: ^
, |
, &
, ~
, <<
, >>
Use tables and flowcharts to help you understand the logic and simplify your code. (Lec 04 - Conditionals)
How to use the assert
macro
We skipped switch/case
and goto
statements.
Identify the inital condition, what to repeat, when to stop, what/how to update after each repetition. (Lec 05 - Loops)
Ensure we move towards the terminating conditions.
We skipped break
and continue
statements.
Beware of array out-of-bound errors.
We skipped union
and enum
.
Arrays decays into pointers.
Effective habits of memory management.
#include
for headers
#define
constants and macros
#ifdef
and #endif
for conditional compilation
These content are covered in Lab 08 - C Preprocessor
We focused on writing clean code. Not just code that works. That's why in Functions, we've mentioned that we should write functions that are small and do one thing.
clang
, vim
, bash
Address and bound sanitizer
clang-format
clang-tidy
git
make
Break down the problem into "bite-size" sub-problems
Solve them one-by-one
Compose them back to solve the original problem
There are many valuable Exercises that legit legit practice this "Decomposition" idea!
Solve the "simplest" version.
Assume you can solve the "simpler" version.
Compose the solution to the original problem from the solution of the simpler version.
The idea of "wishful thinking", classic!
Flowcharts
Truth Tables
Assertion and invariants
Test cases
The mental process associated with computational problem solving
Decomposition
Pattern Recognition
Abstraction
Algorithms
If you want to grow up in programming, please don't stop "dirty work", that is coding practically and try these four very very important ideas!
Decomposition makes a problem easier to solve, reason about, and test
George Polya said: "If you can't solve a problem, there is an easier problem that you can solve: find it"
Solve the easier problem first, then generalized.
E.g., pattern
: draw the left most cell, then generalized
Recursion
Assume the easier problem is solved, then generalized
E.g., binary
: assume we know how to convey a binary number n-1 digits to decimal, then solve for n digits.
Observe trends and patterns, then generalized
Writing loops
What to initialize?
What changes from one loop to the next?
Loop invariants
Make code shorter and easier to change
Taxi
from Exercise 1
Identifying and abstracting relevant information
Hide details
Adapt to change
Generalize to other domain
Data Abstraction
Model the problem with only the necessary information
Functional Abstraction
Hide details and focus on higher-level logic
Ways to solve problems
Branches and Loops
Recursion
Memoization with arrays
Divide and Conquer
Exploit properties in data
Four Pillars of Computational Thinking
Decomposition
Pattern Recognition
Abstraction
Algorithms
Still remember from Lec 1, Prof Ooi told us:
Lemme go back to the Lec01 Slides, here are the words of advice given by Prof Ooi before the lecture starts:
"Grade is not everything. Focus on: learning new things, level-up your skills and enriching your experience!"
At last, there is "One more thing..." as usual:
From Prof Ooi:
The tutorial instructors: Eric, Gizem, Yunjeong, Malaika
The lab tutors: (all 25 of them)
The SoC IT Support Team: Tan Hsiao Wei, Lai Zit Seng, and lab technicians
All the students
For me, I legit want to express my gratitude to:
Prof Ooi and Dr. Eldon for lectures
Dr. Eric for tutorials
My senior Zhang Puyu for the lab
All my classmates during lab and tutorials
"The course may end, but the journey of learning will never end!"
Let's begin the most exciting, impressing and moving but probably the last part of CS1010!
Use the correct type for the correct data ()
Write functions that are small and do one thing ()
arithmetic operations: +
, -
, *
, /
, %
()
Use assertions to reason about your code. ()
Avoid expressions that are always true or always false. ()
Use loop invariants to reason about your loops. ()
Composite data types that store multiple values together. ()
Arrays is useful as a lookup table. ()
String is nothing but an array with terminating null character (\0
) ()
Usually, array out-of-bound errors won't be detected by the compiler, so it won't generate compilation error/warning. But, it will generate Runtime Error and usually it is the segmentation fault. (See more at )
Using pointers for passing by reference. ()
For 1-D array, arrays decay to memory address of a basic data type variable, e.g. long
(). For a 2-D array, arrays decay to the memory address of a pointer variable. ()
Stack and heap ( and )
Pointers and memory addresses ()
Pass by value vs. pass by reference ()
Proper memory management with malloc
and free
. ()
E.g., : find two-hops friends, then generalized to k hops
E.g., : assume we know how to move k-1 discs, then solve for k disc.
This idea I feel is covered more in designed the search algorithm. e.g., should the bounds be inclusive or exclusive? See more from the tips in . Besides searching problem, when you are doing Exercise 6, you also need this skill of Pattern Recognition!
Wah, nostalgic, legit nostalgic
The string abstarction we've used in .
Now, it comes to the end of the recap of the content covered in CS1010. It's a bit disappointing because why the time passes so fast . But, stay strong and be optimistic, there will be more challenging but interesting courses about coding waiting for you (CS2040C, CS3230, etc).
What great word of advice! After these intense and tough "trainings" by CS1010, I believe more or less you will fell growing up in coding!