Download presentation
1
Programming Appreciation Camp
Session 1: Introduction and Problem Solving Aaron Tan NUS School of Computing
2
[Programming Appreciation Camp November 2008]
Contents Why are You here? Some Local Programming Competitions What is Computer Science? What is Problem Solving? What is Algorithmic Problem Solving? [Programming Appreciation Camp November 2008]
3
[Programming Appreciation Camp November 2008]
Why are You here? What are your objectives? What is your level of programming skills? What you think programming is about? Have you taken part in any programming competition? [Programming Appreciation Camp November 2008] 3
4
Some Local Programming Competitions
There are many local competitions, some are more programming related, some are less: National Infocomm Competitions (NIC) These are more algorithmic-problem-solving type of programmig competitions: National Olympiad in Informatics (NOI) NUS School of Computing, March National Software Competition (NSC) Singapore Polytechnic, September Asia-Pacific Informatics Olympiad (APIO) NUS School of Computing, May [Programming Appreciation Camp November 2008] 4
5
The Ultimate Competition
The International Olympiad in Informatics (IOI) Singapore participated since 1992, and we have won 4 gold, 16 silver, and 23 bronze medals since. How to get to the honour roll? Participate in NOI and be one of the gold medallists If you are Singaporean, you’ll be invited for training for IOI Do well in the selection tests during training, and be one of the top four students Off you go, to IOI (in Bulgaria next year)! [Programming Appreciation Camp November 2008] 5
6
What is Computer Science? (1/3)
Computing Curricula 2001 (Computer Science) Report identifies 14 knowledge focus groups Applications within and outside of Computing Discrete Structures (DS) Programming Fundamentals (PF) Algorithms and Complexity (AL) Architecture and Organization (AR) Operating Systems (OS) Net-Centric Computing (NC) Programming Languages (PL) Human-Computer Interaction (HC) Graphics and Visual Computing (GV) Intelligent Systems (IS) Information Management (IM) Social and Professional Issues (SP) Software Engineering (SE) Computational Science (CN) [Programming Appreciation Camp November 2008] 6
7
What is Computer Science? (2/3)
Some recommended readings Algorithmics: The Spirit of Computing David Harel, 2nd ed, Addison-Wesley (3rd ed. available) Introduction to Algorithms T.H. Cormen, C.E. Leiserson, R.L. Rivest, C. Stein, 2nd ed, MIT Press The New Turing Omnibus: 66 Excursions in Computer Science A.K. Dewdney, Holt [Programming Appreciation Camp November 2008] 7
8
What is Computer Science? (3/3)
Come to NUS School of Computing (SoC) to find out! Honours degree in… Communications and Media Computational Biology Computer Engineering Computer Science Electronic Commerce Information Systems Website: [Programming Appreciation Camp November 2008] 8
9
Problem Solving Process (1/5)
Analysis Design Implementation Testing Determine the inputs, outputs, and other components of the problem. Description should be sufficiently specific to allow you to solve the problem. [Programming Appreciation Camp November 2008]
10
Problem Solving Process (2/5)
Analysis Design Implementation Testing Describe the components and associated processes for solving the problem. Straightforward and flexible Method – process Object – component and associated methods [Programming Appreciation Camp November 2008]
11
Problem Solving Process (3/5)
Analysis Design Implementation Testing Develop solutions for the components and use those components to produce an overall solution. Straightforward and flexible [Programming Appreciation Camp November 2008]
12
Problem Solving Process (4/5)
Analysis Design Implementation Testing Test the components individually and collectively. [Programming Appreciation Camp November 2008]
13
Problem Solving Process (5/5)
[Programming Appreciation Camp November 2008]
14
Problem Solving Exercises
The exercises in the next few slides are of varied nature, chosen to illustrate the extent of general problem solving. Different kinds of questions require different domain knowledge and strategies. Apply your problem solving skills and creativity here! [Get participants to form groups of 3 or 4.] [Programming Appreciation Camp November 2008]
15
[Programming Appreciation Camp November 2008]
Exercise #1: Bear A bear, starting from the point P, walked one mile due south. Then he changed direction and walked one mile due east. Then he turned again to the left and walked one mile due north, and arrived at the point P he started from. What was the colour of the bear? [Programming Appreciation Camp November 2008]
16
Exercise #2: Silver chain
A traveller arrives at an inn and intends to stay for a week. He has no money but only a silver chain consisting of 7 links. He uses one link to pay for each day spent at the inn, but the innkeeper agrees to accept no more than one broken link. How should the traveller cut up the chain in order to settle accounts with the innkeeper on a daily basis? [Programming Appreciation Camp November 2008]
17
Exercise #3: Glasses of milk
Six glasses are in a row, the first three full of milk, the second three empty. By moving only one glass, can you arrange them so that empty and full glasses alternate? [Programming Appreciation Camp November 2008]
18
[Programming Appreciation Camp November 2008]
Exercise #4: Puzzles What am I? You can catch me but not throw me. I go all around the world but stay in the corner. You throw away the outside and eat the inside. Then you eat the outside and throw away the inside. [Programming Appreciation Camp November 2008]
19
Exercise #5: Mad scientist
A mad scientist wishes to make a chain out of plutonium and lead pieces. There is a problem, however. If the scientist places two pieces of plutonium next to each other, BOOM!!! The question is, in how many ways can the scientist safely construct a chain of length n? [Programming Appreciation Camp November 2008]
20
[Programming Appreciation Camp November 2008]
Exercise #6: Dominoes Figure 1 below shows a domino and Figure 2 shows a 44 board with the two squares at opposite corners removed. How do you show that it is not possible to cover this board completely with dominoes? All dominoes should lay flat on the board, without overlapping one another, and should not cover area outside the board. Figure 1. A domino. Figure 2. A 44 board with 2 corner squares removed. General case: How do you show the same for an nn board with the two squares at opposite corners removed, where n is even? Special case: How do you show the same for an nn board with the two squares at opposite corners removed, where n is odd? [Programming Appreciation Camp November 2008]
21
Exercise #7: Triominoes
Figure 3 below shows a triomino and Figure 4 shows a 4 4 board with a defect (hole) in one square. How do you show that the board can be covered with triminoes? Figure 3. A triomino. Figure 4. A 44 board with a hole. General case: How do you show that a 2n 2n board (where n 1) with a hole in one square (anywhere on the board) can be covered with triominoes? [Programming Appreciation Camp November 2008]
22
Algorithmic Problem Solving
An algorithm is a well-defined computational procedure consisting of a set of instructions, that takes some value or set of values, as input, and produces some value or set of values, as output. Algorithm Input Output Exact Terminate Effective General [Programming Appreciation Camp November 2008]
23
[Programming Appreciation Camp November 2008]
Euclidean Algorithm First documented algorithm by Greek mathematician Euclid in 300 B.C. To compute the GCD (greatest common divisor) of 2 integers. Let A and B be integers with A > B ≥ 0. If B = 0, then the GCD is A and algorithm ends. Otherwise, find q and r such that A = q.B + r where 0 ≤ r < B Note that we have 0 ≤ r < B < A and GCD(A,B) = GCD(B,r). Replace A by B, and B by r. Go to step 2. [Programming Appreciation Camp November 2008]
24
[Programming Appreciation Camp November 2008]
Control Structures Three control structures Sequence Selection (branching) Repetition (loop) Recursion [Programming Appreciation Camp November 2008]
25
Writing Pseudocodes (1/4)
Example 1: Compute average of 3 integers. A possible algorithm: enter values for num1, num2, num3 ave ( num1 + num2 + num3 ) / 3 print ave num1 Variables used: num2 num3 ave Another possible algorithm: enter values for num1, num2, num3 total ( num1 + num2 + num3 ) ave total / 3 print ave num1 Variables used: num2 num3 ave total [Programming Appreciation Camp November 2008]
26
Writing Pseudocodes (2/4)
Example 2: Arrange 2 integers in increasing order (sort). Algorithm A: enter values for num1, num2 // Assign smaller number into final1, // larger number into final2 if num1 < num2 then final1 num1 final2 num2 else final1 num2 final2 num1 // Transfer values in final1, final2 back to num1, num2 num1 final1 num2 final2 // Display sorted integers */ print num1, num2 Variables used: num1 num2 final1 final2 [Programming Appreciation Camp November 2008]
27
Writing Pseudocodes (3/4)
Example 2: Arrange 2 integers in increasing order (sort). Algorithm B: enter values for num1, num2 // Swap the values in the variables if necessary if num2 < num1 then temp num1 num1 num2 num2 temp // Display sorted integers */ print num1, num2 Variables used: num1 num2 temp [Programming Appreciation Camp November 2008]
28
Writing Pseudocodes (4/4)
Example 3: Find the sum of positive integers up to n (assuming n is a positive integer). Algorithm: enter value for n // Initialise a counter count to 1, and ans to 0 count 1 ans 0 while count <= n do the following ans ans + count // add count to ans count count + 1 // increase count by 1 // Display answer print ans Variables used: n count ans [Programming Appreciation Camp November 2008]
29
Exercise: Compute Maximum
Compute the maximum of a list of values. The values are entered repeatedly into a variable num. max ? // max to hold the largest value eventually while there is still input, enter num if num > max then max num print max [Programming Appreciation Camp November 2008]
30
Task 1: Area of a circle (1/2)
What is the data? Side of square = 2a What is the unknown? Area of circle, C. What is the condition? If radius r is known, C can be calculated. How to obtain r? [Programming Appreciation Camp November 2008]
31
Task 1: Area of a circle (2/2)
Pythagoras’ theorem: r2 = 2 * a2 Area of circle C = * r = * 2 * a2 [Programming Appreciation Camp November 2008] 31
32
Task 2: Pascal’s Triangle
1 1 1 Compute nCk or C(n,k) nCk = n! / (k! * (n – k)!) [Programming Appreciation Camp November 2008] 32
33
[Programming Appreciation Camp November 2008]
Task 3: NE-Paths To find the number of north-east paths between any two points. North-east (NE) path: you may only move northward or eastward. How many NE-paths between A and C? C A A A A [Programming Appreciation Camp November 2008] 33
34
[Programming Appreciation Camp November 2008]
Task 4: Palindrome A word is a palindrome if it reads the same forward and backward. Examples: NOON, RADAR. How do you determine if a word is a palindrome? [Programming Appreciation Camp November 2008] 34
35
[Programming Appreciation Camp November 2008]
Task 5: Anagrams Two words are anagrams if the characters in one word can be rearranged to form the other word. Example: “STAR” and “RATS”. (In general, it could be two sentences instead of words. You may ignore spaces and punctuations in the sentences. See for some examples.) How do you determine if two words are anagrams? [Programming Appreciation Camp November 2008] 35
36
[Programming Appreciation Camp November 2008]
Task 6: Coin Change Given this list of coin denominations: $1, 50 cents, 20 cents, 10 cents, 5 cents, 1 cent, find the smallest number of coins needed for a given amount. You do not need to list out what coins are used. Example 1: For $3.75, 6 coins are needed. Example 2: For $5.43, 10 coins are needed. [Programming Appreciation Camp November 2008] 36
37
[Programming Appreciation Camp November 2008]
THE END [Programming Appreciation Camp November 2008]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.