Fundamentals of Computer Programming with C# HTML version

984 Fundamentals of Computer Programming with C#
techniques is to learn to approach the problem systematically and to
acquire the recipe for problem solving, we demonstrated earlier. Of course,
this is not enough, but it is a crucial step!
There is a recipe for programming-problem solving! Use a
systematical approach for better results, instead of your
sense. Even professionals, with more than 10 years of
experience, use the approach described in this chapter. Use
it yourself and you will be convinced that it works! Don’t
forget to test your solution seriously and deeply.
Finally we want to take a note on the cards shuffle algorithm. The “cards
shuffling” is well-known problem in computer science and there are classic
algorithms for solving it like the "Fisher-Yates Shuffle". Read more in
1. Using the described in this chapter methodology of solving
programming problems, solve this problem: In a plane N points are
given (N < 100,000). The coordinates of the points are integers (xi, yi).
Write a program, which finds all horizontal and vertical lines, such
that they split the plane into two parts, each containing an equal set of
points (points lying on the line are note counted).
2. Using the described in this chapter methodology of solving programming
problems, solve this problem: A set S of n integers and a positive integer
k (k n 10) are given. An alternating sequence is a sequence, which
changes its behavior from ascending to descending and vice versa after
every element. Write a program, which generates all possible sequences
s1, s2, , sk containing k different elements from S.
Example: S = { 2, 5, 3, 4 }, K = 3: {2, 4, 3}, {2, 5, 3}, {2, 5, 4}, {3,
2, 4}, {3, 2, 5}, {3, 4, 2}, {3, 5, 2}, {3, 5, 4}, {4, 2, 3}, {4, 2, 5}, {4,
3, 5}, {4, 5, 2}, {4, 5, 3}, {5, 2, 3}, {5, 2, 4}, {5, 3, 4}.
3. Using the described methodology of creating solutions to programming
problems, solve the following problem: a map of a city is given. At this
map there are given roads and crossroads. For every road a length is
given. One crossroad can connect a couple of roads. Your program must
find the shortest path from one crossroad to another (the shortest
path is measured as the sum of the lengths of all includes roads).
A sample map is given below. At this map the shortest path between the
crossings A and D has length of 70 and it is shown on the figure with
bold lines. As you can see, this is not the only path from A to D: there are
more paths with different lengths. Note that not always the first shortest
road considered as current next node leads to finding the shortest path,
neither does the lowest count of roads. Between some crossings there
may not even be a road. This creates a very interesting problem.