22
Introduction to Introduction to HKOI HKOI

Introduction to HKOI

  • Upload
    kerryn

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to HKOI. Self Introduction. Ice Breaking Game. Ice Breaking Game. Level 1 Form a big circle The person holding the deck of cards will start the game, by introducing himself, and then passes the deck of cards to his left. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to HKOI

Introduction to Introduction to HKOIHKOI

Page 2: Introduction to HKOI

Self IntroductionSelf Introduction

Page 3: Introduction to HKOI

Ice Breaking Ice Breaking GameGame

Page 4: Introduction to HKOI

Ice Breaking GameIce Breaking Game Level 1Level 1 Form a big circleForm a big circle The person holding the deck of cards will The person holding the deck of cards will

start the game, by introducing himself, and start the game, by introducing himself, and then passes the deck of cards to his left.then passes the deck of cards to his left.

In each preceding turn, the person holding In each preceding turn, the person holding the deck of cards will repeat what the the deck of cards will repeat what the previous person has said, and then previous person has said, and then introduces himself. After that, he will introduces himself. After that, he will passes the deck to his left.passes the deck to his left.

The game ends when the deck of cards The game ends when the deck of cards return to the first person.return to the first person.

Page 5: Introduction to HKOI

Ice Breaking GameIce Breaking Game Level 2Level 2 Form a big circleForm a big circle The person holding the deck of cards will start the The person holding the deck of cards will start the

game, by introducing himself and drawing a card game, by introducing himself and drawing a card from the deck. After that, he will pass the deck of from the deck. After that, he will pass the deck of cards to the kcards to the kthth person on his left, where k is the person on his left, where k is the number written on the card he draw.number written on the card he draw.

In each preceding turn, the person holding the deck In each preceding turn, the person holding the deck of cards will repeat what the previous person has of cards will repeat what the previous person has said, and then introduces himself. After that, he will said, and then introduces himself. After that, he will draw a card from the deck and pass the deck of cards draw a card from the deck and pass the deck of cards to the kto the kthth person on his left, where k is the number person on his left, where k is the number written on the card he draw.written on the card he draw.

The game ends when the deck runs out of cards.The game ends when the deck runs out of cards.

Page 6: Introduction to HKOI

ProblemsProblems Just like in Final EventsJust like in Final Events Usually starts with a story or a situation in Usually starts with a story or a situation in

daily life.daily life. e.g. A group of people is playing an ice-breaking e.g. A group of people is playing an ice-breaking

gamegame Specifies a set of well-defined inputs, and the Specifies a set of well-defined inputs, and the

corresponding outputscorresponding outputs What can be the input and output of the ice-What can be the input and output of the ice-

breaking game we played?breaking game we played? Sometimes, there may be more than one correct Sometimes, there may be more than one correct

output, and the problem only requires you to output, and the problem only requires you to output any one of the them.output any one of the them.

Be careful of the format of the input and output!Be careful of the format of the input and output! Example: sortingExample: sorting

Page 7: Introduction to HKOI

AlgorithmsAlgorithms ““Informally, an algorithm is any well-defined Informally, an algorithm is any well-defined

computational procedure that takes some value, or set computational procedure that takes some value, or set of values, as input and produces some value, or set of of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the computational steps that transform the input into the output.output.”” [CLRS] [CLRS]

An algorithm (An algorithm (算法算法 ) is a method to solve a problem.) is a method to solve a problem. There may be more than one algorithms corresponding There may be more than one algorithms corresponding

to a problem.to a problem. Take sorting as an example. Bubble sort and insertion sort are Take sorting as an example. Bubble sort and insertion sort are

algorithms that solves the problem.algorithms that solves the problem. We usually regard algorithms as language independent.We usually regard algorithms as language independent. An algorithm, by definition, must eventually terminates.An algorithm, by definition, must eventually terminates. Many important algorithms are named after Computer Many important algorithms are named after Computer

Scientists.Scientists.

Page 8: Introduction to HKOI

AlgorithmsAlgorithms Tree-Search algorithmsTree-Search algorithms

Depth-First SearchDepth-First Search Breath-First SearchBreath-First Search

Graph algorithmsGraph algorithms DijkstraDijkstra’’ss Floyd-WarshallFloyd-Warshall Bellman-FordBellman-Ford PrimPrim’’ss KruskalKruskal’’ss

Convex Hull algorithmConvex Hull algorithm GrahamGraham’’s scans scan

WA

NT

SA

Q

NSW

V

T

Page 9: Introduction to HKOI

Data StructuresData Structures Data structures (Data structures ( 數據結構數據結構 ) are how we organize ) are how we organize

and store the input data, or intermediate results of and store the input data, or intermediate results of computationcomputation

HHelps to speed up algorithmselps to speed up algorithms Different data structures have different propertiesDifferent data structures have different properties

different types of datadifferent types of data different types of operations different types of operations

ExamplesExamples ArrayArray StackStack QueueQueue HeapHeap Binary Search TreeBinary Search Tree

Page 10: Introduction to HKOI

ComplexityComplexity

We want to know how well an algorithm We want to know how well an algorithm ““scalesscales”” (i.e. when there is a large input). (i.e. when there is a large input).

Usually, minor improvements are not Usually, minor improvements are not critical in competitions.critical in competitions. A reasonable implementation can pass.A reasonable implementation can pass. So, we want to hide the lower order terms.So, we want to hide the lower order terms.

We do not know the exact time each We do not know the exact time each operation takes.operation takes. So, we want to measure the time by counting So, we want to measure the time by counting

the number of basic operations.the number of basic operations.

Page 11: Introduction to HKOI

ComplexityComplexity

0

600

1200

1800

2400

3000

0 5 10 15 20 25 30 35 40 45

f(n)=10n f(n)=30n f(n)=30n log n f(n)=n̂ 2 f(n)=n̂ 3 f(n)=2̂ n f(n)=3̂ n f(n)=n!

Page 12: Introduction to HKOI

ComplexityComplexity

Big-O notationBig-O notation DefinitionDefinition

We say thatWe say that

f(x) is in O(g(x))f(x) is in O(g(x))

if and only ifif and only if

there exist numbers xthere exist numbers x00 and M and M such that such that

|f(x)| ≤ M |g(x)| for x > x|f(x)| ≤ M |g(x)| for x > x00

Page 13: Introduction to HKOI

ComplexityComplexity Bubble sortBubble sort For i := 1 to n doFor i := 1 to n do

For j := 2 to i doFor j := 2 to i doif a[j] > a[j-1] then swap(a[j], a[j-1]);if a[j] > a[j-1] then swap(a[j], a[j-1]);

Worst case number of swaps = n(n-1)/2Worst case number of swaps = n(n-1)/2 Time Complexity = O(nTime Complexity = O(n22)) Total space needed = size of array + space of Total space needed = size of array + space of

variablesvariables Space Complexity = 32*n +32*3 = O(n) +O(1) = Space Complexity = 32*n +32*3 = O(n) +O(1) =

O(n)O(n)

Page 14: Introduction to HKOI

ComplexityComplexity Binary searchBinary search While a<=b doWhile a<=b do

m=(a+b)/2m=(a+b)/2If a[m]=key, Then return mIf a[m]=key, Then return mIf a[m]<key, Then a=m+1If a[m]<key, Then a=m+1If a[m]>key, Then b=m-1If a[m]>key, Then b=m-1

Worst case number of iterations = lg nWorst case number of iterations = lg n Time Complexity = O(log n)Time Complexity = O(log n) Total space needed = size of array + space Total space needed = size of array + space

of variablesof variables Space Complexity = O(n)Space Complexity = O(n)

Page 15: Introduction to HKOI

ComplexityComplexity Usually, the time complexity of the algorithm gives us a Usually, the time complexity of the algorithm gives us a

rough estimation of the actual run time.rough estimation of the actual run time. O(n) for n ~ 10O(n) for n ~ 1088-10-1099

O(n log n) for n ~ 5x10O(n log n) for n ~ 5x1055

O(nO(n22) for n ~ 1000-10000) for n ~ 1000-10000 O(nO(n33) for n ~ 100~1000) for n ~ 100~1000 O(nO(n44) for n ~ 50-100) for n ~ 50-100 O(kO(knn) (k>1) or O(n!) for very small n, usually < 20) (k>1) or O(n!) for very small n, usually < 20

Keep in mindKeep in mind The constant hidden by Big-O notation (including the The constant hidden by Big-O notation (including the

algorithm and the details implementation)algorithm and the details implementation) Computers vary in speeds, so the time needed will be Computers vary in speeds, so the time needed will be

different. In fact, computers are getting faster these days.different. In fact, computers are getting faster these days. Read the instructions carefully for the time limit.Read the instructions carefully for the time limit. Test the program/computer before making assumptions!Test the program/computer before making assumptions!

Page 16: Introduction to HKOI

Training SessionTraining Session Topics are divided into two categories, Topics are divided into two categories,

such that students may master the such that students may master the necessary skills after two years of trainingnecessary skills after two years of training Intermediate: designed for students who have Intermediate: designed for students who have

never entered training team in the pastnever entered training team in the past Advanced: designed for students who are Advanced: designed for students who are

familiar with intermediate topicsfamiliar with intermediate topics All topics are open to all trainees.All topics are open to all trainees. We strongly recommend that students We strongly recommend that students

make sure they have the necessary make sure they have the necessary background knowledge before they attend background knowledge before they attend a training session.a training session.

Page 17: Introduction to HKOI

Training SessionTraining Session On Saturdays (including some public holidays)On Saturdays (including some public holidays) VenueVenue

HW312(Intermediate) and HW311(Advanced), Haking Wong HW312(Intermediate) and HW311(Advanced), Haking Wong Building, The University of Hong KongBuilding, The University of Hong Kong

AM SessionAM Session regular training topicsregular training topics 10:00am 10:00am –– 1:00pm 1:00pm

LunchLunch Questions and discussionsQuestions and discussions Making friendsMaking friends

PM SessionPM Session 2:00pm 2:00pm –– 5:00pm 5:00pm

Detailed schedule is available in the official website (Detailed schedule is available in the official website (http://www.hkoi.org/))

Training notes will be uploaded after each training Training notes will be uploaded after each training session.session.

Page 18: Introduction to HKOI

Training TopicsTraining Topics

Algorithms and Data StructuresAlgorithms and Data Structures LinuxLinux

Free, popular and powerfulFree, popular and powerful Competition environmentCompetition environment

C++C++ Advantage of Stardard Template Advantage of Stardard Template

Library (STL)Library (STL)

Page 19: Introduction to HKOI

Training ReferencesTraining References

BooksBooks ““Introduction to AlgorithmsIntroduction to Algorithms”” by Cormen, by Cormen,

Leiserson, Rivest, Stein [CLRS]Leiserson, Rivest, Stein [CLRS] Heapsort, Quicksort, Sorting in Linear Time, Heapsort, Quicksort, Sorting in Linear Time,

Elementary Data Structures, Binary Search Elementary Data Structures, Binary Search Trees, Dynamic Programming, Greedy Trees, Dynamic Programming, Greedy Algorithms, Data Structures for Disjoint Sets, Algorithms, Data Structures for Disjoint Sets, Elementary Graph Algorithms, Minimum Elementary Graph Algorithms, Minimum Spanning Trees, Single-Source Shortest Path, Spanning Trees, Single-Source Shortest Path, All-Pairs Shortest PathAll-Pairs Shortest Path

OnlineOnline Wikipedia (Wikipedia (http://en.wikipedia.org/))

Page 20: Introduction to HKOI

Online JudgeOnline Judge

HKOI Judge (HKOJ)HKOI Judge (HKOJ) https://judge.hkoi.org After each training, some problems After each training, some problems

are open for practice.are open for practice. Update your personal information.Update your personal information. Take attendance on your own every Take attendance on your own every

training.training. Rank, score and attendance are for Rank, score and attendance are for

reference only. reference only.

Page 21: Introduction to HKOI

Team Formation TestTeam Formation Test

29 May 201029 May 2010 Trainees with outstanding Trainees with outstanding

performance can represent Hong performance can represent Hong Kong in international and national Kong in international and national competitionscompetitions

The delegation selection algorithm The delegation selection algorithm is based on the score of the Team is based on the score of the Team Formation Test (TFT)Formation Test (TFT)

Page 22: Introduction to HKOI

External CompetitionsExternal Competitions

International Olympiad of International Olympiad of Informatics (IOI)Informatics (IOI)

http://www.ioi2010.org/ 14-21 August 2010 @ Canada14-21 August 2010 @ Canada

National Olympiad of Informatics National Olympiad of Informatics (NOI)(NOI)

全國信息學奧林匹克競賽全國信息學奧林匹克競賽