Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Computational Thinking

Introduction to Computational Thinking

The title said it all.

Avatar for Wisnu Adi Nurcahyo

Wisnu Adi Nurcahyo

March 28, 2021
Tweet

More Decks by Wisnu Adi Nurcahyo

Other Decks in Programming

Transcript

  1. Proclub Dream. Think. Code. Win. Introduction to Computational Thinking March

    28th, 2021 A Problem-Solving Process for Programming Problem
  2. Outline Dram. Think. Code. Win. Proclub • What is Computational

    Thinking? • Where & when to use Computational Thinking? • Why should we use Computational Thinking? • How to use Computational Thinking? ◦ Print a simple pattern ◦ Binary Search case study (bonus if we have some time left) • What’s next? • Any Questions?
  3. Proclub Dream. Think. Code. Win. Hello, Proclub 2021! Proclub 2016

    here! My name is Wisnu Adi Nurcahyo and you may call me Wisnu. Technically speaking, I’m already an alumni since I’ve passed my “sidang yudisium”. I’m working as a Software Engineer at Traveloka. I’m not that active on Discord atm but you may ask me programming related stuff. Nice to meet you all!
  4. Computational Thinking is... Dram. Think. Code. Win. Proclub A problem-solving

    process consists of four steps. 1. Decomposition 2. Pattern recognition 3. Pattern generalization (abstraction) 4. Algorithm design The main goal is to solve a programming related problems. Or, we can say any problems that can be computed by a computer.
  5. Decomposition To put it simply, it is the process of

    breaking down data. We also identify the components, or smaller parts, of the problem. What we will do are as follows: 1. Define the goal. 2. Set the problem constraints. 3. Divide the problem into several subproblems.
  6. Pattern Recognition It is the process of finding similarities, or

    patterns, once we go through the decomposition of problems. Would be great if you able to set the constraints well. There is no “standard” of finding similarity (unless it is a mathematical pattern/sequence). However, I usually do something like this: 1. How it looks like when I have the minimum number of data. 2. How it looks like when I have the maximum number of data. 3. How it looks like when I have a random number of data. 4. What happens if my data is out of the constraints.
  7. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 ...
  8. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … incremental number
  9. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … find the difference either subtract or divide
  10. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … find the difference either subtract or divide 0 1 1 2 3 5 8 ...
  11. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … 0 1 1 2 3 5 8 ...
  12. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … 0 1 1 2 3 5 8 ...
  13. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … 0 1 1 2 3 5 8 … 8 - 5 = 3
  14. Pattern Recognition Another way is to run through your data.

    Just like how you try to figure out fibonacci pattern. 1 1 2 3 5 8 13 21 … 0 1 1 2 3 5 8 … 8 - 5 = 3 8 = 3 + 5
  15. Pattern Recognition Finding pattern is not an easy task. The

    best way to improve our hunch while finding pattern is to practice more. Also, do learn some techniques to find mathematical pattern/sequence. It will help a lot!
  16. Pattern Generalization Once we have recognized our pattern, we need

    to go through pattern generalization and abstraction. That is, we want to make sure that the solution we come up with can be used for multiple instances of the problem we have identified. Well, to put it simply, create our own “formula” to handle all kind of conditions within the constraint.
  17. Pattern Generalization Let’s use fibonacci from before. 1 1 2

    3 5 8 13 21 … 0 1 1 2 3 5 8 … We finally know that 8 needs 5 and 3 which means f(n) = f(n - 1) + f(n - 2)
  18. Pattern Generalization Let’s use fibonacci from before. 1 1 2

    3 5 8 13 21 … 0 1 1 2 3 5 8 … What about those 1? Well, we just need to set them as the base case.
  19. Pattern Generalization Hence, you got: f(0) = 1 f(1) =

    1 f(n) = f(n - 1) + f(n - 2) as the pattern generalization, the formula!
  20. Algorithm Design An algorithm is a set of instructions. So,

    in this step, we try to give the computer our instruction to solve the problem. The algorithm and the data structure used are based on two things: 1. The problem constraints. 2. The pattern generalization.
  21. Algorithm Design Let’s use fibonacci from before. We already got

    the formula from the pattern generalization step. Is it as easy as implementing the formula like this? def fib(n): if n == 0 or n == 1: return 1 return f(n - 1) + f(n - 2)
  22. Algorithm Design Well, it is depends on the problem constraints

    too! Answer this: Just how big is the input? In this case, the `n` variable. 10? 20? 100? 1000000?
  23. Algorithm Design If it is 10, then you may implement

    as it is. However, what happens if it is 1000? Your algorithm would take too long to finish. Imagine, the time complexity is O(2^n). You have 1000 so it is 2^1000 which is equal to 10715086071862673209484250490600018105614048117055336074437503883 70351051124936122493198378815695858127594672917553146825187145285 69231404359845775746985748039345677748242309854210746050623711418 77954182153046474983581941267398767559165543946077062914571196477 686542167660429831652624386837205668069376 computations.
  24. Algorithm Design If 10^8 computations are roughly equal to 1

    second, how many seconds it takes to finish that gigantic number of computations? Then, you need to design a better algorithm! Not that easy, huh? And yeah, this is where the fun begins!
  25. Where & when to use? Whenever you encounter a problem

    that can be solved by a computer. A programming problem in general could be solved with computational thinking approach. So, yeah, IMO, if you code then you need to know computational thinking or even better, use it. NOTE: Do not involve UI/UX related work.
  26. How to use? Dram. Think. Code. Win. Proclub To make

    it easy for you to understand, we will try to solve these following problem: • Print a simple pattern • Binary Search case study (bonus if we have some time left) We will follow computational thinking steps on each problem above.
  27. Print a Simple Pattern Let’s say we have this pattern

    below if we give 5 as the input. 0 12 345 6789 01234
  28. Print a Simple Pattern Decomposition 0 12 345 6789 01234

    we will have one single input, n, which is a positive integer
  29. Print a Simple Pattern Decomposition 0 12 345 6789 01234

    we will have one single input, n, which is a positive integer based on the sample output (in the left), if n = 5 then we print a pattern with 5 lines
  30. Print a Simple Pattern Decomposition 0 12 345 6789 01234

    we will have one single input, n, which is a positive integer based on the sample output (in the left), if n = 5 then we print a pattern with 5 lines it turns out that the number of character in that line is equals with its line number
  31. Print a Simple Pattern Pattern Recognition 0 12 345 6789

    01234 started by zero ended by nine
  32. Print a Simple Pattern Pattern Recognition 0 12 345 6789

    01234 started by zero ended by nine started over by zero again
  33. Print a Simple Pattern Pattern Generalization 0 12 345 6789

    01234 f(x) = x, if x < 10 f(x) = 0, if x > 9
  34. Print a Simple Pattern Pattern Generalization 0 12 345 6789

    01234 f(x) = x, if x < 10 f(x) = 0, if x > 9 ?
  35. Print a Simple Pattern Pattern Generalization 0 12 345 6789

    01234 f(x) = x % 10 f(0) = 0 % 10 = 0, f(1) = 1 % 10 = 1, f(2) = 2 % 10 = 2, …, f(10) = 10 % 10 = 0, f(11) = 11 % 10 = 1, …
  36. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input())
  37. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input()) x = 0
  38. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input()) x = 0 for row in range(1, n + 1):
  39. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input()) x = 0 for row in range(1, n + 1): for col in range(row):
  40. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input()) x = 0 for row in range(1, n + 1): for col in range(row): print(f(x), end='')
  41. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input()) x = 0 for row in range(1, n + 1): for col in range(row): print(f(x), end='') x += 1
  42. Print a Simple Pattern Algorithm Design 0 12 345 6789

    01234 def main(): n = int(input()) x = 0 for row in range(1, n + 1): for col in range(row): print(f(x), end='') x += 1 print(end=’\n’)
  43. What’s next? Practice more! You may use any online judge

    platform such as TLX, HackerRank, Codeforces, etc. Also, you need to read more about algorithm strategy and data structure. The more “tools” you have, the more options available to solve the problem.