Problem Solving/Algorithms 4/3/2014

advertisement
Problem Solving/Algorithms
4/3/2014
Today
Today we will solve some programming problems
to mentally prepare for the programming
competition
Problem 1
Write a method that returns the n-th row of
Pascal's tree for a given n. (The 0-th row is
[1] )
Pascal's tree looks like the following:
1
1
1
1
1 4
2
3
6
1
1
3
4
1
1
Problem 2
We have an interface “GraphNode”:
public interface GraphNode {
public String getName();
public void addChild();
public GraphNode[] getChildren();
}
Problem 2 cont.
• GraphNode defines an acyclic graph
• If a GraphNode has no children, getChildren()
returns an array of size 0
• All children nodes returned by getChildren()
are not null
Problem 2 cont.
Implement a method with the following
signature:
public ArrayList<GraphNode>
visitGraph(GraphNode);
This should return an ArrayList<GraphNode> that
contains every GraphNode in the graph (each
node should be visited only once)
Problem 3
Implement a method with the following
signature:
public ArrayList<ArrayList<GraphNode>>
allPossiblePaths(GraphNode node);
This methods returns an ArrayList with all the
possible paths through the graph starting at
the root node.
Problem 4
Last one but most challenging:
Given an array of integers, find the continuous
sequence with the greatest value and return the
value.
Some Strategies
• When in doubt, test
• One person to solve it and one person to test
it (switch roles if time allows)
Have fun!
Try to have fun at the competition. Remember,
trophy or no trophy, you are still great!
Download