SlideShare a Scribd company logo
1 of 36
About
Memoization
동일한 계산을 반복해야 할 경우,
한 번 계산한 결과를 메모리에 저장,
꺼내 씀으로써 중복계산 방지 가능.
Dynamic Progamming 의핵심이 되는 기술
=> 메모리라는 공간 비용을 투입
계산에 소요되는 시간 비용을 감소
f(4)= f(1) + f(0) + f(1) + f(1) + f(0)
함수 f를 호출하는 횟수는 총 9번
9번의 계산 중에 무려 4번을 중복계산
시간복잡도는 피보나치 수열의 값에 따라
폭발적으로 증가
Dynamic Programming
Fibonacci
출처: https://new93helloworld.tistory.com/92
Recursive Recursive + Memoization
Fibonacci
출처: https://www.youtube.com/watch?v=L53nqHCSSFY
Tower of Hanoi
Tower of Hanoi
Ex) n = 3 일때
Non-recursive
Tower of Hanoi
Non-recursive
Array & List
Array
Array 생성 시 반드시 크기를 알아야함
Array의 원소에는 index값을 이용해서 직접 access할 수 있다
Array 전체가 이미 사용 중인 경우, 원소 추가 시 크기를 늘린다 how?
(=>step 1: former array 우선 두고, 새로운 크기의 array을 위한 메모리 탐색
step 2: step 1의 결과에 따라, new array assign
step 3: Copy
step 4: former array 삭제)
ArrayList
Array이다! 위의 재할당 방법을 사용
새로운 원소를 추가할 때마다, 자동으로 더 큰 크기의 array로 재할당
원소를 많이 삭제해도 크기는 줄어들지 않는다.
Index를 사용하여 원소에 random access할 수 있다
LinkedList
Array가 아님, list 안에서 다음 원소를 가리키는
내부 객체를 이용
Index를 이용해 원소에 access할 경우, 해당
index에 access할 때까지 List를 순회
배열 재할당 과정이 없음으로, 거기에 따른 손실
(리소스 낭비+메모리)을 막아줌
원소 개수가 계속 변경되는 상황에서 유리, 크기
에 따라 메모리 용량 결정
https://opentutorials.org/module/1335/8636
Array & List
연산 Array Linked List
Access O(1) O(n)
Search O(n) – linear search
O(log n) – binary search
O(n)
Insertion
(첫번째, 마지막, 중간)
O(n)
O(n), O(1), O(n)
O(1)
O(1), O(1), O(1)
Deletion O(n)
O(n), O(1), O(n)
O(1)
O(n), O(1), O(n)
Python은 list를 제공, array를 제공하지 않음(numpy에서는 제공)
But Python의 list는 사실상의 array에다가 list의 기능을 합쳐놓은 것
그래서 C의 array보다는 메모리를 더 많이 필요로 한다는 단점
LinkedList 예시
7
0x123134
Prev
0x60..
Next
0x93..
LinkedList 예시
Sparse Matrix
• Let us represent each column of a sparse matrix as a circularly linked
list with
a head node.
• Also, let us represent each row of a sparse matrix similarly.
• We will define two types of nodes: header node and element node.
• Each column will have a head node (header) and element nodes
(element).
• Each row will have a head node (header) and element nodes (element).
• The list of head nodes (for all columns and all rows) will also have a
head
node, which is an element node type.
– The head of head node will contain number of rows (row), number of columns
(col), and number of element nodes (value).
LinkedList 예시
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
MapReduce
Itertools
Itertools
Itertools
Collection
Copy(DeepCopy)
Thank You

More Related Content

What's hot

말의여행
말의여행말의여행
말의여행mil23
 
Howto_Tensorflow+Linear Regression
Howto_Tensorflow+Linear RegressionHowto_Tensorflow+Linear Regression
Howto_Tensorflow+Linear RegressionHyo jeong Lee
 
Project#2말의여행 Hwp
Project#2말의여행 HwpProject#2말의여행 Hwp
Project#2말의여행 HwpKimjeongmoo
 
DP Optimization
DP OptimizationDP Optimization
DP Optimization승혁 조
 
[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘
[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘
[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘GDGCampusKorea
 
Graph
GraphGraph
GraphGNGLB
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap SortBill Kim
 
RNC C++ lecture_5 Array
RNC C++ lecture_5 ArrayRNC C++ lecture_5 Array
RNC C++ lecture_5 Arrayitlockit
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조영기 김
 
[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...
[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...
[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...종빈 오
 
Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기창규 김
 
Deferred Shading
Deferred ShadingDeferred Shading
Deferred Shading종빈 오
 
[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)
[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)
[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)Myeongun Ryu
 
[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이
[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이
[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이NAVER D2
 

What's hot (20)

말의여행
말의여행말의여행
말의여행
 
Lec 00, 01
Lec 00, 01Lec 00, 01
Lec 00, 01
 
자료구조02
자료구조02자료구조02
자료구조02
 
Howto_Tensorflow+Linear Regression
Howto_Tensorflow+Linear RegressionHowto_Tensorflow+Linear Regression
Howto_Tensorflow+Linear Regression
 
Project#2말의여행 Hwp
Project#2말의여행 HwpProject#2말의여행 Hwp
Project#2말의여행 Hwp
 
Array & Loop
Array & LoopArray & Loop
Array & Loop
 
DP Optimization
DP OptimizationDP Optimization
DP Optimization
 
02_3_여러가지연산자
02_3_여러가지연산자02_3_여러가지연산자
02_3_여러가지연산자
 
[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘
[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘
[Devfest Campus Korea 2021]효율적인 문제해결 With 알고리즘
 
Graph
GraphGraph
Graph
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap Sort
 
RNC C++ lecture_5 Array
RNC C++ lecture_5 ArrayRNC C++ lecture_5 Array
RNC C++ lecture_5 Array
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조
 
[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...
[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...
[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Comput...
 
Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기
 
Deferred Shading
Deferred ShadingDeferred Shading
Deferred Shading
 
Valentine
ValentineValentine
Valentine
 
[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)
[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)
[명우니닷컴] 2번째 숙제 - 두 정수의 연산 (공연 예약 시스템)
 
[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이
[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이
[D2 CAMPUS] 부산대 Alcall 프로그래밍 경시대회 문제 풀이
 
1. alps c&c++
1. alps c&c++1. alps c&c++
1. alps c&c++
 

Similar to Effective Python, Clean Code

스칼라와 스파크 영혼의 듀오
스칼라와 스파크 영혼의 듀오스칼라와 스파크 영혼의 듀오
스칼라와 스파크 영혼의 듀오Taeoh Kim
 
Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버Jaejin Yun
 
2015-2 MODA 두 번째 스터디
2015-2 MODA 두 번째 스터디 2015-2 MODA 두 번째 스터디
2015-2 MODA 두 번째 스터디 SKKU
 
1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)fmbvbfhs
 
Mlp logical input pattern classfication report doc
Mlp logical input pattern classfication report docMlp logical input pattern classfication report doc
Mlp logical input pattern classfication report doc우진 신
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexityskku_npc
 
자료구조 Project2
자료구조 Project2자료구조 Project2
자료구조 Project2KoChungWook
 
Linq to object using c#
Linq to object using c#Linq to object using c#
Linq to object using c#병걸 윤
 
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)Kyoungchan Lee
 
2017 tensor flow dev summit
2017 tensor flow dev summit2017 tensor flow dev summit
2017 tensor flow dev summitTae Young Lee
 
Adversarial Attack in Neural Machine Translation
Adversarial Attack in Neural Machine TranslationAdversarial Attack in Neural Machine Translation
Adversarial Attack in Neural Machine TranslationHyunKyu Jeon
 
DP 알고리즘에 대해 알아보자.pdf
DP 알고리즘에 대해 알아보자.pdfDP 알고리즘에 대해 알아보자.pdf
DP 알고리즘에 대해 알아보자.pdfHo Jeong Im
 
Tensorflow for Deep Learning(SK Planet)
Tensorflow for Deep Learning(SK Planet)Tensorflow for Deep Learning(SK Planet)
Tensorflow for Deep Learning(SK Planet)Tae Young Lee
 

Similar to Effective Python, Clean Code (20)

스칼라와 스파크 영혼의 듀오
스칼라와 스파크 영혼의 듀오스칼라와 스파크 영혼의 듀오
스칼라와 스파크 영혼의 듀오
 
Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버
 
2015-2 MODA 두 번째 스터디
2015-2 MODA 두 번째 스터디 2015-2 MODA 두 번째 스터디
2015-2 MODA 두 번째 스터디
 
Nlp study1
Nlp study1Nlp study1
Nlp study1
 
1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)
 
Mlp logical input pattern classfication report doc
Mlp logical input pattern classfication report docMlp logical input pattern classfication report doc
Mlp logical input pattern classfication report doc
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
2012 Ds 01
2012 Ds 012012 Ds 01
2012 Ds 01
 
자료구조01
자료구조01자료구조01
자료구조01
 
자료구조01
자료구조01자료구조01
자료구조01
 
자료구조01
자료구조01자료구조01
자료구조01
 
자료구조 Project2
자료구조 Project2자료구조 Project2
자료구조 Project2
 
Linq to object using c#
Linq to object using c#Linq to object using c#
Linq to object using c#
 
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
 
JDK 변천사
JDK 변천사JDK 변천사
JDK 변천사
 
2017 tensor flow dev summit
2017 tensor flow dev summit2017 tensor flow dev summit
2017 tensor flow dev summit
 
Adversarial Attack in Neural Machine Translation
Adversarial Attack in Neural Machine TranslationAdversarial Attack in Neural Machine Translation
Adversarial Attack in Neural Machine Translation
 
DP 알고리즘에 대해 알아보자.pdf
DP 알고리즘에 대해 알아보자.pdfDP 알고리즘에 대해 알아보자.pdf
DP 알고리즘에 대해 알아보자.pdf
 
Tensorflow for Deep Learning(SK Planet)
Tensorflow for Deep Learning(SK Planet)Tensorflow for Deep Learning(SK Planet)
Tensorflow for Deep Learning(SK Planet)
 
Gpg1
Gpg1Gpg1
Gpg1
 

Effective Python, Clean Code

  • 1.
  • 3. Memoization 동일한 계산을 반복해야 할 경우, 한 번 계산한 결과를 메모리에 저장, 꺼내 씀으로써 중복계산 방지 가능. Dynamic Progamming 의핵심이 되는 기술 => 메모리라는 공간 비용을 투입 계산에 소요되는 시간 비용을 감소 f(4)= f(1) + f(0) + f(1) + f(1) + f(0) 함수 f를 호출하는 횟수는 총 9번 9번의 계산 중에 무려 4번을 중복계산 시간복잡도는 피보나치 수열의 값에 따라 폭발적으로 증가
  • 8. Tower of Hanoi Ex) n = 3 일때 Non-recursive
  • 10. Array & List Array Array 생성 시 반드시 크기를 알아야함 Array의 원소에는 index값을 이용해서 직접 access할 수 있다 Array 전체가 이미 사용 중인 경우, 원소 추가 시 크기를 늘린다 how? (=>step 1: former array 우선 두고, 새로운 크기의 array을 위한 메모리 탐색 step 2: step 1의 결과에 따라, new array assign step 3: Copy step 4: former array 삭제) ArrayList Array이다! 위의 재할당 방법을 사용 새로운 원소를 추가할 때마다, 자동으로 더 큰 크기의 array로 재할당 원소를 많이 삭제해도 크기는 줄어들지 않는다. Index를 사용하여 원소에 random access할 수 있다 LinkedList Array가 아님, list 안에서 다음 원소를 가리키는 내부 객체를 이용 Index를 이용해 원소에 access할 경우, 해당 index에 access할 때까지 List를 순회 배열 재할당 과정이 없음으로, 거기에 따른 손실 (리소스 낭비+메모리)을 막아줌 원소 개수가 계속 변경되는 상황에서 유리, 크기 에 따라 메모리 용량 결정 https://opentutorials.org/module/1335/8636
  • 11. Array & List 연산 Array Linked List Access O(1) O(n) Search O(n) – linear search O(log n) – binary search O(n) Insertion (첫번째, 마지막, 중간) O(n) O(n), O(1), O(n) O(1) O(1), O(1), O(1) Deletion O(n) O(n), O(1), O(n) O(1) O(n), O(1), O(n) Python은 list를 제공, array를 제공하지 않음(numpy에서는 제공) But Python의 list는 사실상의 array에다가 list의 기능을 합쳐놓은 것 그래서 C의 array보다는 메모리를 더 많이 필요로 한다는 단점
  • 13. LinkedList 예시 Sparse Matrix • Let us represent each column of a sparse matrix as a circularly linked list with a head node. • Also, let us represent each row of a sparse matrix similarly. • We will define two types of nodes: header node and element node. • Each column will have a head node (header) and element nodes (element). • Each row will have a head node (header) and element nodes (element). • The list of head nodes (for all columns and all rows) will also have a head node, which is an element node type. – The head of head node will contain number of rows (row), number of columns (col), and number of element nodes (value).