알고리즘

알고리즘 문제풀이 접근 방법

selonjulie 2022. 8. 7. 14:04

Algorithm: process, set of steps to accomplish a certain task

 

How to you improve
1.devise a plan for solving problem
2.master common problem solving patterns

Problem solving
1.understand the problem
2.explore concrete examples
3.break it down
4.solve/simplify
5.look back and refactor

1. 문제 이해
2. 구체적인 사례 탐색
3. 작업을 나누기
4. 해결/단순화
5. 돌아보고 리팩토링


How
1.understand the problem
-1.can I restate the problem in my own words?
-2.what are the inputs that go into the problem?
-3.what are the outputs?
-4.can the outputs be determined from the inputs?
-5.how should I label the important data
*정수 integer 실수 float

 

2.explore concrete examples
-1.start with simple examples
-2.progress to more complex examples
-3.explore examples with empty inputs
-4.explore examples with invalid inputs

 

3.break it down
explicitly write out the steps you need to take
comment for a guide: for the step to take(pseudo code) 
주석으로 커멘트 나와놓으면, 수도 코드라도 적어놓으면 인터뷰하는 사람들이 안끝내도 알 수 있음 
write a function which takes in a string and returns counts of each character in the string.

 

-1.make object to return at end
-2.loop over string, for each character…
--2.1.if the char is a number/letter AND not in object, add it to object and set value to 1
--2.2.if the char is a number/letter AND is a key in object, add one to count
--2.3.if char is something else, don’t do anything
-3.return object at end 

 

4.solve/simplify
solve the problem, if you can’t, solve a simpler problem
아예 안하는 것보다는, 쉬운거라도 푸는게 나음
나중에 어려운거는 추가하면됨

5.look back and refactor
make it more efficient 
try and improve code
efficiency & leasibility

요약
1.Devise a plan for solving problems
-1. understand the problem
-2. explore concrete examples
-3. break it down
-4. solve/simplify
-5. look back and refactor


2. Master common problem solving patterns(programming mechanism)

'알고리즘' 카테고리의 다른 글

Recursion 재귀  (0) 2022.08.15
[Sliding window] minSubArrayLen  (0) 2022.08.07
Sliding Window: maxSubarraySum  (0) 2022.07.31
[Multiple pointers] isSubsequence  (0) 2022.07.31
Divide and Conquer (binary search)  (0) 2022.07.11