CS1010 Notes
  • Welcome
  • Lec/Tut/Lab/Exes
    • Lecture
      • Lec 01 - Computational Problem Solving
      • Lec 02 - Functions and Types
      • Lec 03 - Basic C Programming
      • Lec 04 - Conditionals
      • Lec 05 - Loops
      • Lec 06 - Call Stacks, Arrays
        • Diagnostic Quiz
      • Lec 07 - Pointers, Memory management
        • Diagnostic Quiz
      • Lec 08 - Multi-d Array, Efficiency
        • Diagnostic Quiz
      • Lec 09 - Searching and Sorting
        • Diagnostic Quiz
      • Lec 10 - More Recursion
        • Diagnostic Quiz
      • Lec 11 - Strcut & Standard I/O
        • Diagnostic Quiz
      • Lec 12 - Recap
    • Tutorial
      • Tut 01 - Computational Problem-Solving
      • Tut 02 - Functions and Conditionals
      • Tut 03 - More on Conditionals
      • Tut 04 - Loops
      • Tut 08 - Searching and Sorting
    • Lab
      • Lab 01 - Unix/Vim Setup
      • Lab 02 - Debugging
      • Lab 03 - Assert
      • Lab 04 - Test Cases
      • Lab 05 - Arrays
      • Lab 06 - Memory Errors
      • Lab 07 - Compiling with Clang
      • Lab 08 - C Preprocessor
      • Lab 09 - Backtracking
      • Lab 10 - Struct and Wrap up
    • Exercises
      • Exercise 3 - Fixed-Length Arrays
      • Exercise 4 - Dynamic Arrays and Strings
      • Exercise 6 - Searching and Sorting
      • Exercise 7 - More Recursion
      • Exercise 8 - Struct
  • Past Year Exam
    • Midterm PE
      • PE1 (AY18/19)
      • PE1 (AY20/21)
      • PE1 (AY21/22)
      • PE0 (AY22/23)
      • PE0 (AY23/24)
    • Midterm Paper
      • Midterm (AY18/19)
      • Midterm (AY20/21)
      • Midterm (AY21/22)
      • Midterm (AY22/23)
    • PE1 Review
      • PE1 (AY23/24)
    • PE2 Review
      • PE2 (AY18/19)
      • PE2 (AY20/21)
      • PE2 (AY21/22)
      • PE2 (AY22/23)
      • PE2 (AY23/24)
    • Final Paper
      • Final (AY18/19)
      • Final (AY20/21)
      • Final (AY21/22)
      • Final (AY22/23)
      • Final (AY23/24)
  • Current Year Exam
    • PE0 (AY24/25)
    • PE1 (AY24/25)
    • PE2 (AY24/25)
    • Final (AY24/25)
  • Toolbox
    • Vim & Unix
    • GDB
  • After CS1010
Powered by GitBook
On this page
  • More on Data Structures
  • Recap of CS1010
  • What have you learned?
  • 1. How to write C
  • 2. How a C program behaves
  • 3. Tools and Practices
  • 4. Problem Solving Techniques
  • Computational Thinking
  • Four Pillars of Computational Thinking
  • Special Thanks to...
Edit on GitHub
  1. Lec/Tut/Lab/Exes
  2. Lecture

Lec 12 - Recap

PreviousDiagnostic QuizNextTutorial

Last updated 6 months ago

Slides:

More on Data Structures

A very useful website recommended by Eldon:

Recap of CS1010

What have you learned?

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!

1. How to write C

Types

  • Beware of precision issue when using double and float

Functions

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

Operations

  • bit operations in C: ^, |, &, ~, <<, >>

Branching and Logical Expressions

  • 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.

Loops

  • 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.

Arrays and Structs

  • Beware of array out-of-bound errors.

  • We skipped union and enum.

Memory

  • Arrays decays into pointers.

  • Effective habits of memory management.

Pre-processing

  • #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.

2. How a C program behaves

Memory Model

Interacting with OS

3. Tools and Practices

clang, vim, bash

  • Address and bound sanitizer

  • clang-format

  • clang-tidy

  • git

  • make

4. Problem Solving Techniques

Decomposition

  • 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!

Recursion

  • 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!

Thinking Tools

  • Flowcharts

  • Truth Tables

  • Assertion and invariants

  • Test cases

Computational Thinking

The mental process associated with computational problem solving

Four Pillars of Computational Thinking

  • 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

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.

Pattern Recognition

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

Abstraction

  • 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

Algorithms

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:

Special Thanks to...

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!

😄
😭
😭
😭
👏
Assertion
Skipping else
Types
Writing Good Functions
Fixed-Length Array
Pass an array to a function
Pass an array to a function
Arithmetic Operations
Array Name Decay
Call Stack
Counting Sort*
Binary Search*
8. Compilation Error vs. Runtime Error
Array Name Decay (Multidimensional Array)
Why we cannot use free(buckets) here?
String
Heap
Pointers
Tower of Hanoi
N-Queens
cppreference.com
C Plus Plus Reference
CS1010 AY24/25 S1 Lecture 12
Lecture Slides
Logo
Loop Invariant
Ex5 Q6 Social