Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1010 Discussion Group 11 Week 3 - Computational Thinking/Algorithms.

Similar presentations


Presentation on theme: "CS1010 Discussion Group 11 Week 3 - Computational Thinking/Algorithms."— Presentation transcript:

1 CS1010 Discussion Group 11 Week 3 - Computational Thinking/Algorithms

2 HELLO! I am Yan Hwa Computer Science Year 3 leeyanhwa@u.nus.edu

3 Complete tutorial questions before class so we can discuss
Expectations Complete tutorial questions before class so we can discuss Ask any questions during class or post on forum Attempt tutorial questions before expecting an answer Also learning from you Make friends! Don’t wait till recess week to catch up

4 Programming background? (if any) Your expectations? Your concerns?
About you Programming background? (if any) Your expectations? Your concerns?

5 Can arrive earlier to ask any questions
Discussion sessions Can arrive earlier to ask any questions Attendance will be taken; 5% of final grade Go through some questions in Discussion Sheet QnA After a few weeks, may split session into two sub- sessions First session: Complusory Second session: Experienced students may choose to leave Arrive earlier Please participate~ Don’t wait till recess week to catch up Going through some questions  group discussion and/or presentation if time permits

6 Reminders Check IVLE regularly for announcements/forum postings
Participate actively in IVLE forums Post in forums instead of sending s Have you tested out CodeCrunch by submitting the Lab0? Lab1 has been released. Please take note the deadline is next Wednesday (6th September) 5pm. Fill in “My Progress Chart” in the CS1010 Student Handbook regularly. I may spot-check! Post in forums instead of sending s

7 Victory Road Nature of CS1010 Practice make perfect!
This module can be very easy or very tough Don’t leave it till the last minute Not just a course on C programming Practice make perfect! It is not one module where you can leave it till the last minute. Rather, if you have done it right then just before the exams you should be feeling very relaxed.

8 Google is your best friend
Let me google that for you

9 Lecture Summary Decomposition

10 Problem Solving and Incremental Coding
Lecture Summary Define Problem! Problem Solving and Incremental Coding Inputs? Outputs? Constraints? Relationship? Make Plan! Code, Test, Code, Test Define problem. Capture all relevant information What are the inputs (data)? What are the outputs (unknowns)? What are the constraints? Connection/relationship between inputs and outputs? Make a Plan Step by Step, code and test / debug / do logging

11 Tips on Labs Do Follow Instructions
Give meaningful names for variables Appropriate commenting Must do Double/triple check your indentation (gg=G in vim will auto-indent your program nicely!) Do not Forget to initialise variables whenever necessary Output format does not conform to requirement Commenting = Think, will you understand this piece of code very quickly by just reading it? A few days later? Years later? Never name your classes and functions ambiguously. Always use inline comments on code blocks that are complicated or may appear unclear. Always use descriptive variable names. Always write comments describing the intent or reason why a piece of code exists. Always keep comments up to date when editing commented code.

12 Ask early if unclear (Forums, Email)
Tips on Labs Ask early if unclear (Forums, ) Do NOT copy from friends! (changing variable names, spacing, shifting codes around is not going to work!) Last-minute uploading could be a traumatic experience It is not one module where you can leave it till the last minute. Rather, if you have done it right then just before the exams you should be feeling very relaxed.

13 Tutorial Exercise CodeCrunch Lab #0 Have you submitted?

14 Lab #1 Three Simple Exercises
Tutorial Exercise Lab #1 Three Simple Exercises Read Ex3 Packing and fill in the worksheet

15 Given a list of N integers, find out how many of them are negative.
Tutorial 1 Q4 Given a list of N integers, find out how many of them are negative. Let the list of integers be a1, a2, …, aN. for k from 1 to N if (a[k] < 0) countNeg  countNeg + 1; print countNeg Are you all okay with this qn? Where is the condition to change?

16 countNeg  0 Tutorial 1 Q4a Why must we initialise? for k from 1 to N
if (a[k] < 0) countNeg  countNeg + 1; print countNeg Why must we initialise? However until the variable is initialised, that piece of memory could contain anything. This is why using it is unpredictable. Other languages may assist you in this area by initialising variables automatically when you assign them, but as a C programmer you are working with a fairly low-level language that makes no assumptions about what you want to do with your program. You as the programmer must explicitly tell the program to do everything.

17 How to use a for loop instead?
Tutorial 1 Q4d sum  0; k  1; while ( k ≤ N ) { sum  sum + a[k]; k  k + 2; } How to use a for loop instead? Pattern is not very obvious. Need to use strong pattern recognition sum  0; for k from 1 to N step 2 sum  sum + ak;

18 Find the number of swaps required to move all white balls to the left of black balls
Only swapping of neighbours allowed Tutorial 1 Q5 How many swaps needed? Not allowed!!

19 Find the number of swaps required to move all white balls to the left of black balls
Only swapping of neighbours allowed Tutorial 1 Q5 2 swaps?

20 Find the number of swaps required to move all white balls to the left of black balls
Only swapping of neighbours allowed Tutorial 1 Q5 2 swaps!

21 Warm-up exercise : Find the white balls! Similar to Q4?
Tutorial 1 Q5 Warm-up exercise : Find the white balls! Similar to Q4? let’s call the balls Bk, 1 ≤ k ≤ N where N is the number of balls countWhite  0; for k from 1 to N if (Bk is white) countWhite  countWhite + 1; print countWhite Pattern recognition!

22 How to find out total number of swaps needed
Decompose Problem Plan your solution Find Patterns We need to know: Number of swaps needed for each white ball then add them up!

23 Tutorial 1 Q5 Algorithm 1 Number of swaps needed for each white ball = Position of white ball (k) – desired pos countSwaps  0; desiredPos  1; for k from 1 to N if (Bk is white) numSwaps  k – desiredPos; countSwaps  countSwaps + numSwaps; desiredPos  desiredPos + 1; Print countSwaps Pattern recognition!

24 Tutorial 1 Q5 Algorithm 2 Number of swaps needed for each white ball = number of black balls to the left of the white ball countSwaps  0; blackToLeft  0; For k from 1 to N if (Bk is black) blackToLeft  blackToLeft + 1; else /*it is a white ball */ countSwaps  countSwaps + blackToLeft; Print countSwaps Pattern recognition!

25 Tips for Vim Navigate around using arrow keys or hjkl Google for Vim Shortcuts and cheatsheets Use Vim Tutor!

26 Tips for Vim

27 Summary Computational thinking and Problem Solving Plan before programming anything Start doing your lab! Learn Vim! Practise!

28 Sources of Practice Reference book Practice exercises we put up on CodeCrunch ( tml) Google for more questions and cheatsheets sections/1/Cheatsheet-c.pdf Books definitive-c-book-guide-and-list

29 Sources of Practice comments-tell-you-why/


Download ppt "CS1010 Discussion Group 11 Week 3 - Computational Thinking/Algorithms."

Similar presentations


Ads by Google