SlideShare a Scribd company logo
Basic Data Structures(2)
2016. 3. 24
장 홍 준
Contents
• Stack
• Queue
• Time Complexity
• Binary Heap
• Binary Indexed Tree
Stack
• LIFO(Last In First Out)
• push(), pop(), top(), size()
#include <stack>
using namespace std;
• Recursive Structure
• Keeps a property(DFS, Convex hull, Convex hull Trick)
Queue
• FIFO(First In First Out)
• push(), pop(), front(), end()
#include <queue>
using namespace std;
• BFS (너비우선탐색)
Time Complexity
Big O notation
다항 시간, 지수 시간, 로그 시간
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) k = i+j;
}
: O(n^2)
Time Complexity
for (int i = 0; i < n; i++) {
for (int j = i; j < i+k; j++) {
O(1) process.
}
}
: O(nk)
Time Complexity
for (int i = 0; i < m; i++) {
for (int j = 0; j < log(n); j++) {
O(1) process.
}
}
: O(mlog(n))
Binary Heap
• Tree Structure
A binary heap is a complete binary tree which satisfies the heap ordering property.
The ordering can be one of two types:
1) the min-heap property: the value of each node is greater than or equal to the value of its parent, with the minimum-value element at the root.
2) the max-heap property: the value of each node is less than or equal to the value of its parent, with the maximum-value element at the root.
Binary Heap
How to implement with an array
: https://www.cs.cmu.edu/~adamchik/15-121/lectures/Binary%20Heaps/heaps.html
이 수업에서는 STL을 이용해서 어떻게 사용하는지를 알아보겠습니다.
Binary Heap
#include <queue>
using namespace std;
------------------------
priority_queue <int> Q;
Q.push(1); Q.push(9); Q.push(7); Q.push(5); Q.pop();
int x = Q.top(), y = Q.size();
x = ?, y = ?
Binary Indexed Tree(Fenwick Tree)
• 구간에 대한 최소/최대/합
• 많은 양의 질문 / 갱신 : 시간복잡도를 줄이자!...
Binary Indexed Tree(Fenwick Tree)
Binary Indexed Tree(Fenwick Tree)
• 1~7까지의 합
• 4, 6, 7
• 1~8까지의 합
• 8
• 가장 오른쪽의 1
Binary Indexed Tree(Fenwick Tree)
• 5를 갱신
• 5, 6, 8
• 3을 갱신
• 3, 4, 8
• 가장 오른쪽의 1
Binary Indexed Tree(Fenwick Tree)
• 어떻게 구현…?
• 가장 오른쪽의 1을 어떻게 알 수 있을까?
• 2의 보수!
cin >> x;
int y = x & -x;
cout << y;
Binary Indexed Tree(Fenwick Tree)
• https://www.acmicpc.net/blog/view/21
• 연습문제를 직접 풀어보다가 모르는 게 생기면 질문합시다.

More Related Content

PPTX
Coding convention
PDF
TF.data & Eager Execution
PDF
Intro to Apache Storm
PPTX
PDF
Storm introduction
PDF
tf.data: TensorFlow Input Pipeline
PDF
Use the Matplotlib, Luke @ PyCon Taiwan 2012
PDF
Coding convention
TF.data & Eager Execution
Intro to Apache Storm
Storm introduction
tf.data: TensorFlow Input Pipeline
Use the Matplotlib, Luke @ PyCon Taiwan 2012

What's hot (20)

PDF
Åsted .Net (CSI .Net)
PDF
Lo14
PDF
確率的プログラミングライブラリEdward
PPTX
Performance
PPTX
DCC2014 - Fully Online Grammar Compression in Constant Space
PDF
Gnuplot 2
PPTX
I Believe I Can See the Future
PPTX
Queue oop
PPTX
SPIRE2013-tabei20131009
PDF
Wasserstein GAN Tfug2017 07-12
PDF
Garbage collector in python
PDF
pdb like a pro
PDF
Python NumPy Tutorial | NumPy Array | Edureka
PPTX
CPM2013-tabei201306
PDF
Clojure Intro
PPTX
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
PDF
Pollyfills in JavaScript
PDF
DeepLearning ハンズオン資料 20161220
DOCX
งานย่อยที่ 6
PDF
Java program-to-calculate-area-and-circumference-of-circle
Åsted .Net (CSI .Net)
Lo14
確率的プログラミングライブラリEdward
Performance
DCC2014 - Fully Online Grammar Compression in Constant Space
Gnuplot 2
I Believe I Can See the Future
Queue oop
SPIRE2013-tabei20131009
Wasserstein GAN Tfug2017 07-12
Garbage collector in python
pdb like a pro
Python NumPy Tutorial | NumPy Array | Edureka
CPM2013-tabei201306
Clojure Intro
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Pollyfills in JavaScript
DeepLearning ハンズオン資料 20161220
งานย่อยที่ 6
Java program-to-calculate-area-and-circumference-of-circle
Ad

Viewers also liked (11)

PPTX
Sqrt decomposition
PDF
Problem Solving GuideBook
PPTX
4. dynamic programming(1)
PPTX
2. basic data structures(1)
PDF
Network flow
PDF
Teamwork in programming contests
PPTX
1. alps c c++
PDF
ALPS & AlKor Intro Slides
PPTX
2016 고려대학교 신입생 프로그래밍 경시대회 해법
PDF
COCI 2006/2007 contest #1 solution
PDF
Baekjoon Online Judge 1492번 풀이
Sqrt decomposition
Problem Solving GuideBook
4. dynamic programming(1)
2. basic data structures(1)
Network flow
Teamwork in programming contests
1. alps c c++
ALPS & AlKor Intro Slides
2016 고려대학교 신입생 프로그래밍 경시대회 해법
COCI 2006/2007 contest #1 solution
Baekjoon Online Judge 1492번 풀이
Ad

Similar to 3. basic data structures(2) (20)

PDF
Happy Go Programming
PDF
Modern C++
PPT
Python redis talk
PPTX
DA_02_algorithms.pptx
PPT
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
KEY
JavaOne 2012 - JVM JIT for Dummies
PDF
Python高级编程(二)
PDF
C# - What's next
PDF
Migrating from matlab to python
KEY
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
PDF
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
PPTX
An Introduction to gensim: "Topic Modelling for Humans"
PPTX
04 standard class library c#
PDF
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
PPTX
Gpu programming with java
PDF
Fantastic DSL in Python
PPT
linked list in c++
PPTX
Python
KEY
R for Pirates. ESCCONF October 27, 2011
PDF
Scaling Deep Learning with MXNet
Happy Go Programming
Modern C++
Python redis talk
DA_02_algorithms.pptx
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
JavaOne 2012 - JVM JIT for Dummies
Python高级编程(二)
C# - What's next
Migrating from matlab to python
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
An Introduction to gensim: "Topic Modelling for Humans"
04 standard class library c#
Tajolabigdatacamp2014 140618135810-phpapp01 hyunsik-choi
Gpu programming with java
Fantastic DSL in Python
linked list in c++
Python
R for Pirates. ESCCONF October 27, 2011
Scaling Deep Learning with MXNet

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Sports Quiz easy sports quiz sports quiz
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Institutional Correction lecture only . . .
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
Pharma ospi slides which help in ospi learning
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Complications of Minimal Access Surgery at WLH
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Sports Quiz easy sports quiz sports quiz
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
TR - Agricultural Crops Production NC III.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
01-Introduction-to-Information-Management.pdf
Institutional Correction lecture only . . .
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pre independence Education in Inndia.pdf
Pharma ospi slides which help in ospi learning

3. basic data structures(2)

  • 1. Basic Data Structures(2) 2016. 3. 24 장 홍 준
  • 2. Contents • Stack • Queue • Time Complexity • Binary Heap • Binary Indexed Tree
  • 3. Stack • LIFO(Last In First Out) • push(), pop(), top(), size() #include <stack> using namespace std; • Recursive Structure • Keeps a property(DFS, Convex hull, Convex hull Trick)
  • 4. Queue • FIFO(First In First Out) • push(), pop(), front(), end() #include <queue> using namespace std; • BFS (너비우선탐색)
  • 5. Time Complexity Big O notation 다항 시간, 지수 시간, 로그 시간 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) k = i+j; } : O(n^2)
  • 6. Time Complexity for (int i = 0; i < n; i++) { for (int j = i; j < i+k; j++) { O(1) process. } } : O(nk)
  • 7. Time Complexity for (int i = 0; i < m; i++) { for (int j = 0; j < log(n); j++) { O(1) process. } } : O(mlog(n))
  • 8. Binary Heap • Tree Structure A binary heap is a complete binary tree which satisfies the heap ordering property. The ordering can be one of two types: 1) the min-heap property: the value of each node is greater than or equal to the value of its parent, with the minimum-value element at the root. 2) the max-heap property: the value of each node is less than or equal to the value of its parent, with the maximum-value element at the root.
  • 9. Binary Heap How to implement with an array : https://www.cs.cmu.edu/~adamchik/15-121/lectures/Binary%20Heaps/heaps.html 이 수업에서는 STL을 이용해서 어떻게 사용하는지를 알아보겠습니다.
  • 10. Binary Heap #include <queue> using namespace std; ------------------------ priority_queue <int> Q; Q.push(1); Q.push(9); Q.push(7); Q.push(5); Q.pop(); int x = Q.top(), y = Q.size(); x = ?, y = ?
  • 11. Binary Indexed Tree(Fenwick Tree) • 구간에 대한 최소/최대/합 • 많은 양의 질문 / 갱신 : 시간복잡도를 줄이자!...
  • 13. Binary Indexed Tree(Fenwick Tree) • 1~7까지의 합 • 4, 6, 7 • 1~8까지의 합 • 8 • 가장 오른쪽의 1
  • 14. Binary Indexed Tree(Fenwick Tree) • 5를 갱신 • 5, 6, 8 • 3을 갱신 • 3, 4, 8 • 가장 오른쪽의 1
  • 15. Binary Indexed Tree(Fenwick Tree) • 어떻게 구현…? • 가장 오른쪽의 1을 어떻게 알 수 있을까? • 2의 보수! cin >> x; int y = x & -x; cout << y;
  • 16. Binary Indexed Tree(Fenwick Tree) • https://www.acmicpc.net/blog/view/21 • 연습문제를 직접 풀어보다가 모르는 게 생기면 질문합시다.