What is Java?
Java
Originally for intelligent consumer-electronic
devices
Then used for creating Web pages with
dynamic content
Now also used to:
Develop large-scale enterprise applications
Enhance WWW server functionality
Provide applications for
Graph Theory - I
Todays Plan
Introduction
Special Graphs
Various Representations
Depth First Search
Solve a problem from GCJ
Breadth First Search
Solve a problem from SPOJ
Dijkstras Algorithm
Solve a problem from SPOJ
Special Graphs
Undirected G
Its Good to Be Greedy
(well.sometimes)
When can we be greedy ?
- Greedy algorithms are generally used in optimization
problems
- There is an optimal substructure to the problem
- We do at each step what seems best without planning ahead
- We must be able
Aim and Clarications
Common Problems
Parsing a problem
Standard Template Library
Using Bitwise
Problems
Introductory Lecture
Topics: basics, resources, stl, bitwise tricks
League of Programmers
ACA, IIT Kanpur
October 5, 2013
League of Programmers
Introdu
Segment Trees
Longest Non Decreasing Subsequence
(Revisited)
1
2
5
2
8
6
3
6
9
7
4
4
5
6
6
Length of LNDS ending at ith Loc
1
2
3
3
4
This runs in O(n2). Can we do better?
Challenge: Given a value of a[i] we need to find the maximum length possible among
Graphs
League of Programmers
ACA, IIT Kanpur
League of Programmers
Graphs
Outline
League of Programmers
Graphs
Basics
What are Graphs?
League of Programmers
Graphs
Basics
What are Graphs?
An abstract way of representing connectivity using nodes (or
vertic
Maths
Probability
Problems
Maths
League of Programmers
ACA, IIT Kanpur
October 22, 2012
League of Programmers
Maths
Outline
1
Maths
2
Probability
3
Problems
Maths
Probability
Problems
League of Programmers
Maths
GCD
Maths
Probability
Problems
gcd(a, b): g
Game theory
Impartial Games
Two-person games with perfect information
No chance moves
A win-or-lose outcome
Impartial games
Set of moves available from any given position is
the same for both players
partizan games
Each player has a different set of pos
Essential Tools
Segment Trees
Segment trees for Rooted Trees
Problems
Segment Trees
League of Programmers
ACA, IIT Kanpur
League of Programmers
Segment Trees
Outline
Essential Tools
Segment Trees
Segment trees for Rooted Trees
Problems
1
Essential Tools
2
Dynamic Programming
Problems
Dynamic Programming
League of Programmers
ACA, IIT Kanpur
October 22, 2012
League of Programmers
Dynamic Programming
Outline
Dynamic Programming
Problems
1
Dynamic Programming
2
Problems
League of Programmers
Dynamic Programmi
Dynamic Programming
Maximum Sum Sub-Array
Given an array
31
-41
59
26
-53
58
97
-93
-23
84
Each sub-array has a sum. What is the maximum such sum possible.
Maximum Sum for any sub Array ending at ith location
31
0
59
85
32
90
187
94
71
155
85
85
90
187
18
Maths for Programming Contests
Basics
Number Represenation in varius bases
Basic operations
Divisibility
Reading long long long numbers
Basic math functions like factorial
http:/www.spoj.pl/problems/FCTRL/
GCD of Two Numbers
If b|a then gcd(a,b) = b
Other
Dynamic Programming - II
Integer Knapsack Problem
http:/en.wikipedia.org/wiki/Knapsack_problem
Subset Sum Problem
Given a set of n numbers ai sum up to M, and any K
M, whether there is a subset of the numbers such that
they sum up to (hit) K?
Solution
clarifications
Introduction to Programming contests
Standard Template Library
Bitwise Magic
Introductory Lecture
Topics: basics,resources,stl,bitwise tricks,gdb
League of Programmers
IIT Kanpur
September 30, 2011
League of Programmers
Introductory Lecture
Some basic GUI
components.
Component
Description
JLabel
Displays uneditable text or icons.
JTextField
Enables user to enter data from the keyboard. Can also be used to
display editable or uneditable text.
JButton
Triggers an event when clicked with the m
Greedy Algorithms
Divide and Conquer
Binary Search
Problems
Greedy, Divide and Conquer
League of Programmers
ACA, IIT Kanpur
October 5, 2013
League of Programmers
Greedy, Divide and Conquer
Greedy Algorithms
Divide and Conquer
Binary Search
Problems
Outli