Introduction to HKOI Gary Wong. Ice Breaking and bond forming…

Slides:



Advertisements
Similar presentations
Introduction to Computer Science Theory
Advertisements

Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
An Introduction to Programming Concepts and OI-programming …from abstract theory to dirty tricks…
CompSci Searching & Sorting. CompSci Searching & Sorting The Plan  Searching  Sorting  Java Context.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
CS503: First Lecture, Fall 2008 Michael Barnathan.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
Discussion Section: HW1 and Programming Tips GS540.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
COMP s1 Computing 2 Complexity
1 Complexity Lecture Ref. Handout p
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Building a Real Workflow Thursday morning, 9:00 am Lauren Michael Research Computing Facilitator University of Wisconsin - Madison.
An Introduction to Programming Concepts and OI-programming …from abstract theory to dirty tricks…
Week 2 CS 361: Advanced Data Structures and Algorithms
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
Sorting HKOI Training Team (Advanced)
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
Recursion, Complexity, and Sorting By Andrew Zeng.
Searching and Sorting Gary Wong.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Introduction to HKOI. Self Introduction Ice Breaking Game.
 Pearson Education, Inc. All rights reserved Searching and Sorting.
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
THE ACT TEST Austin English 11. What’s on the Test?????? in English 1.45 minutes – 75 items 1.Tests you knowledge on: Punctuation USAGE & GrammarMECHANICS.
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
OI-style programming Gary Wong For any questions, please ask via MSN:
Building a Real Workflow Thursday morning, 9:00 am Greg Thain University of Wisconsin - Madison.
Data Structures and Algorithms Introduction to Algorithms M. B. Fayek CUFE 2006.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Data Structure Introduction.
Building a Real Workflow Thursday morning, 9:00 am Lauren Michael Research Computing Facilitator University of Wisconsin - Madison.
The Software Development Process
3.3 Complexity of Algorithms
HKOI 2005 Training Introduction to Algorithms Alan, Tam Siu Lung.
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
Reactive and Output-Only HKOI Training Team 2006 Liu Chi Man (cx) 11 Feb 2006.
Intermediate 2 Computing Unit 2 - Software Development.
HKOI Programming HKOI Training Team (Intermediate) Alan, Tam Siu Lung Unu, Tse Chi Yung.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Searching Topics Sequential Search Binary Search.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Efficiently Solving Computer Programming Problems Doncho Minkov Telerik Corporation Technical Trainer.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
1 The Role of Algorithms in Computing. 2 Computational problems A computational problem specifies an input-output relationship  What does the.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Advanced Algorithms Analysis and Design
Introduction to Algorithms
Enough Mathematical Appetizers!
Computation.
Some Basics for Problem Analysis and Solutions
Objective of This Course
Applied Discrete Mathematics Week 6: Computation
Introduction to Algorithms
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
Presentation transcript:

Introduction to HKOI Gary Wong

Ice Breaking and bond forming…

Rules Level 1Level 1 Form a big circleForm 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.The person holding the deck of cards will start the game, by introducing himself, and then passes the deck of cards to his left. In each preceding turn, the person holding the deck of cards will repeat what the previous person has said, and then introduces himself. After that, he will passes the deck to his left.In each preceding turn, the person holding the deck of cards will repeat what the previous person has said, and then introduces himself. After that, he will passes the deck to his left. The game ends when the deck of cards return to the first person.The game ends when the deck of cards return to the first person.

Rules Level 2Level 2 Form a big circleForm a big circle The person holding the deck of cards will start the game, by introducing himself and drawing a card from the deck. After that, he will pass the deck of cards to the k th person on his left, where k is the number written on the card he draw.The person holding the deck of cards will start the game, by introducing himself and drawing a card from the deck. After that, he will pass the deck of cards to the k th person on his left, where k is the number written on the card he draw. In each preceding turn, the person holding the deck of cards will repeat what the previous person has said, and then introduces himself. After that, he will draw a card from the deck and pass the deck of cards to the k th person on his left, where k is the number written on the card he draw.In each preceding turn, the person holding the deck of cards will repeat what the previous person has said, and then introduces himself. After that, he will draw a card from the deck and pass the deck of cards to the k th person on his left, where k is the number 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.

Why OI? Get medals? Love solving problems? Learn more? Make friends? … OI could be a thing to give you all these

Agenda Algorithms, Data StructuresAlgorithms, Data Structures ComplexityComplexity OI Style ProgrammingOI Style Programming Training SessionsTraining Sessions Upcoming ChallengesUpcoming Challenges

Algorithms, Data Structures the best couple…

Algorithms “Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output.” [CLRS]“Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output.” [CLRS] N.B.: CLRS = a book called “Introduction to algorithms”N.B.: CLRS = a book called “Introduction to algorithms”

Algorithms In other words, a series of procedures to solve a problemIn other words, a series of procedures to solve a problem Example:Example: –Bubble Sort, Merge Sort, Quick Sort –Dijkstra’s Algorithm, Bellman Ford’s Algorithm Common misconceptions:Common misconceptions: –Algorithm = Program –Confusion between “algorithms” and “methods to design algorithms”

Data Structures Briefly speaking, the way to organize dataBriefly speaking, the way to organize data Examples:Examples: –Binary Search Tree –Hash Table –Segment Tree Different data structures have different propertiesDifferent data structures have different properties Different algorithms use different data structuresDifferent algorithms use different data structures

Don’t worry! All the above-mentioned technical jargons will be taught laterAll the above-mentioned technical jargons will be taught later So, come to attend training!So, come to attend training!

Complexity a performance indicator…

Complexity We want to know how well an algorithm “scales” in terms of amount of dataWe want to know how well an algorithm “scales” in terms of amount of data –In BOTH time and space Only consider the proportionality to number of basic operations performedOnly consider the proportionality to number of basic operations performed –A reasonable implementation can pass –Minor improvements usually cannot help

Complexity Big-O notationBig-O notation DefinitionDefinition We say that f(x) is in O(g(x)) if and only if there exist numbers x 0 and M such that |f(x)| ≤ M |g(x)| for x > x 0 You do not need to know thisYou do not need to know this

Complexity Example: Bubble SortExample: Bubble Sort For i := 1 to n do For j := 2 to i do if a[j] > a[j-1] then swap(a[j], a[j-1]);For i := 1 to n do For j := 2 to i do 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(n 2 )Time Complexity = O(n 2 ) Total space needed = size of array + space of variablesTotal space needed = size of array + space of variables Space Complexity = 32*n +32*3 = O(n) +O(1) = O(n)Space Complexity = 32*n +32*3 = O(n) +O(1) = O(n)

Complexity Another example: Binary searchAnother example: Binary search While a<=b doWhile a<=b dom=(a+b)/2 If a[m]=key, Then return m If a[m]<key, Then a=m+1 If a[m]>key, Then b=m-1 Worst case number of iterations = lg n [lg means log 2 ]Worst case number of iterations = lg n [lg means log 2 ] Time Complexity = O(log n)Time Complexity = O(log n) Total space needed = size of array + space of variablesTotal space needed = size of array + space of variables Space Complexity = O(n)Space Complexity = O(n)

What if… An algorithm involving both bubble sort and binary search? O(f) + O(g) = max(O(f), O(g)) Take the “maximum” one only, ignore the “smaller” one Answer: O(n 2 )

Complexity Points to note: –Speed of algorithm is machine-dependent –Use suitable algorithms to solve problems E.g., if n=1000 and runtime limit is 1s, would you use: –O(n 2 )? –O(n!)? –O(n 3 )? –Constant hidden by Big-O notation –Testing is required!

OI-Style Programming from abstract theory to (dirty) tricks…

OI-Style Programming Objective of Competition… The winner is determined by: –Fastest Program? –Amount of time used in coding? –Number of Tasks Solved? –Use of the most difficult algorithm? –Highest Score Rule of thumb: ALWAYS aim to get as many scores as you can

OI-Style Programming Scoring: –A “black box” judging system –Test data is fed into the program –Output is checked for correctness –No source code is manually inspected –How to take advantage (without cheating of course!) of the system?

OI-Style Programming Steps for solving problems in OI: 1. Reading the problems 2. Choosing a problem 3. Reading the problem 4. Thinking 5. Coding 6. Testing 7. Finalizing the program

Reading the problems Problems in OI: –Title –Problem Description –Constraints –Input/Output Specification –Sample Input/Output –Scoring

Reading the problems Constraints –Range of variables –Execution Time NEVER make assumptions yourself –Ask whenever you are not sure –(Do not be afraid to ask questions!) Read every word carefully Make sure you understand before going on

Thinking Classify the problem into certain type(s) Rough works Special cases, boundary cases No idea? Give up first, do it later. Spend time for other problems.

Thinking Make sure you know what you are doing before coding Points to note: –Complexity (BOTH time and space) –Coding difficulties What is the rule of thumb mentioned?

Coding Short variable names –Use i, j, m, n instead of no_of_schools, name_of_students, etc. No comments needed As long as YOU understand YOUR code, okay to ignore all “appropriate“ coding practices NEVER use 16 bit integers (unless memory is limited) –16 bit integer may be slower! (PC’s are usually 32- bit, even 64 bit architectures should be somewhat-optimized for 32 bit)

Coding Use goto, break, etc in the appropriate situations –Never mind what Dijkstra has to say Avoid using floating point variables if possible (eg. real, double, etc) Do not do small (aka useless) “optimizations” to your code Save and compile frequently

Testing Sample Input/Output “A problem has sample output for two reasons: 1.To make you understand what the correct output format is 2.To make you believe that your incorrect solution has solved the problem correctly ” Manual Test Data Program-generated Test Data (if time allows) Boundary Cases (0, 1, other smallest cases) Large Cases (to check for TLE, overflows, etc) Tricky Cases Test by self-written program (again, if time allows)

Debugging Debugging – find out the bug, and remove it Easiest method: writeln/printf/cout –It is so-called “Debug message” Use of debuggers: –FreePascal IDE debugger –gdb debugger

Finalizing Check output format –Any trailing spaces? Missing end-of-lines? (for printf users, this is quite common) –better test once more with sample output –Remember to clear those debug messages Check I/O – filename? stdio? Check exe/source file name Is the executable updated? Method of submission? Try to allocate ~5 mins at the end of competition for finalizing

OI-Style Programming 2 nd time to ask: What is the rule of thumb? Tricks might be needed (Without violating rules, of course)

Tricks Solve for simple cases –50% (e.g. slower solution, brute force) –Special cases (smallest, largest, etc) –Incorrect greedy algorithms –Very often, slow and correct solutions get higher scores than fast but wrong solutions Hard Code –“No solution” –Stupid Hardcode: begin writeln(random(100)); end. –Naïve hardcode: “if input is x, output hc(x)” –More “intelligent” hardcode (sometimes not possible): pre-compute the values, and only save some of them

Pitfalls Misunderstanding the problem Not familiar with competition environment Output format Using complex algorithms unnecessarily Choosing the hardest problem first

Training Sessions a moment for inspiration…

Training Sessions Intermediate and Advanced ALL topics are open to ALL trainees Tips: Pre-requisites are often needed for advanced topics

Training Sessions On Saturday Room 123, Ho Sin-Hang Engineering Building, Chinese University of Hong Kong AM session: 10:00-12:30 Lunch PM session: 13:30-16:00 for more details, including latest training schedule and noteshttp://

Training Sessions A gross overview of topics covered: –Algorithms and Data Structures –Linux Free, popular and powerfulFree, popular and powerful Competition environmentCompetition environment –C++ Advantage of Stardard Template Library (STL)Advantage of Stardard Template Library (STL)

Upcoming Challenges go for it!!!

Upcoming Challenges Asia-Pacific Informatics Olympiad (7 May 2011) Team Formation Test / TFT (28 May 2011) Provided that you can get through TFT, –International Olympiad in Informatics –National Olympiad in Informatics –ACM Local

Upcoming Challenges How can I prepare for these challenges? –Attend trainings –Participate into mini-competitions –Search for learning materials in Internet –Read books –Practice, practice, practice PERFECT practice makes perfect –HKOI Online Judge: –Other online judges (UVa, POJ, etc.)

Hard sell… Intermediate Topic: “Searching and Sorting” (10:00-12:30, 22 Jan 2011) by Gary Wong

Thank you for your tolerance =P

Reference PowerPoint for HKOI 2010 Training Session 1 –“Introduction to HKOI” –“Algorithms, OI Style Programming”