1 / 29

CS1010 Discussion Group 11

Join the CS1010 Discussion Group for Week 3 to discuss computational thinking, algorithms, and programming. Complete tutorial questions, ask questions, and make friends!

irenea
Download Presentation

CS1010 Discussion Group 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 E0004806@u.nus.edu http://www.comp.nus.edu.sg/~yanhwa/

  3. 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!

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

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

  6. Reminders • Check IVLE regularly for announcements/forum postings • Participate actively in IVLE forums • Post in forums instead of sending emails • Have you tested out CodeCrunch by submitting theLab0? • Lab1has 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!

  7. Victory Road • Nature of CS1010 • 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!

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

  9. Lecture Summary

  10. Problem Solving and Incremental Coding Inputs? Outputs? Constraints? Relationship? Lecture Summary Define Problem! Make Plan! Code, Test, Code, Test

  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

  12. Tips on Labs Ask early if unclear (Forums, Email) 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

  13. CodeCrunch Lab #0 Have you submitted? Tutorial Exercise

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

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

  16. Tutorial 1 Q4a Why must we initialise? countNeg0 for k from 1 to N if (a[k]< 0) countNeg countNeg + 1; print countNeg

  17. Tutorial 1 Q4d How to use a for loop instead? sum  0; k 1; while ( k ≤ N ) { sum  sum + a[k]; kk + 2; }

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

  22. How to find out total number of swaps needed Decompose Problem Plan your solution Find Patterns

  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

  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

  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 (http://www.comp.nus.edu.sg/~cs1010/4_misc/practice.html) Google for more questions and cheatsheetshttps://courses.cs.washington.edu/courses/cse351/14sp/sections/1/Cheatsheet-c.pdf Books https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list

  29. Sources of Practice https://blog.codinghorror.com/code-tells-you-how-comments-tell-you-why/

More Related