1.7Types of Computational Problems
Covers IGNOU MCS-211 §1.6
Although there are endless computing problems, most of them belong to a few well-studied families. If you can recognise the family, you can often reuse a known algorithm instead of inventing one. This page describes the standard problem types.
Sorting
Sorting means rearranging items into order (ascending or descending) by a key, such as sorting numbers by value or names alphabetically. Sorting is everywhere: search results, leaderboards, and as a step that makes other problems (such as binary search or finding duplicates) easier.
No single sorting algorithm is best in every situation: some are simple but slow, some are faster but complex; some do well on random data, others on nearly sorted data; some work in main memory, others suit huge files on disk.
Two properties of sorting algorithms deserve special attention:
# Students already in alphabetical order; now sort them by marks.
students = [("Asha", 3), ("Ravi", 3), ("Neha", 1)]
def selection_sort(items):
a = list(items)
for i in range(len(a) - 1):
m = i
for j in range(i + 1, len(a)):
if a[j][1] < a[m][1]:
m = j
a[i], a[m] = a[m], a[i] # long-distance swap
return a
def insertion_sort(items):
a = list(items)
for i in range(1, len(a)):
key = a[i]
j = i - 1
while j >= 0 and a[j][1] > key[1]: # strict '>' keeps equal keys in order
a[j + 1] = a[j]
j -= 1
a[j + 1] = key
return a
print("selection sort:", selection_sort(students))
print("insertion sort:", insertion_sort(students))selection sort: [('Neha', 1), ('Ravi', 3), ('Asha', 3)]
insertion sort: [('Neha', 1), ('Asha', 3), ('Ravi', 3)]Selection sort swapped Neha with Asha across the array, jumping Asha behind Ravi: it is not stable. Insertion sort only moves items past larger ones, so Asha stays before Ravi: it is stable. Both are in-place.
Searching
Searching means finding a given value, the search key, in a collection. Methods range from linear search to binary search (sorted data) to hashing and search trees. The best choice depends on whether the data is static or changes often (insertions and deletions), and on the memory available.
String processing
A string is a sequence of characters (text, DNA bases, bits). The best-known string problem is string matching: finding where a pattern occurs in a text, as in a search box, a plagiarism checker or a virus scanner. This course studies string matching algorithms (naive, Rabin–Karp, KMP) in Block 3.
Graph problems
A graph is a set of vertices (points) joined by edges (lines). Road maps, computer networks, social networks and task dependencies are all graphs. Typical problems:
- Traversal — visit every vertex (e.g. broadcasting a message in a network).
- Shortest path — the cheapest route between two vertices (e.g. routing, maps).
- Travelling salesman problem — the shortest tour visiting every vertex once.
- Graph colouring — colour the vertices with as few colours as possible so that adjacent vertices differ. Example: exam scheduling, where vertices are exams, an edge joins two exams with a common student, and colours are time slots.
Traversal and shortest paths have efficient algorithms; TSP and minimum graph colouring have no known efficient algorithm.
Combinatorial problems
A combinatorial problem asks for a permutation, combination or subset that satisfies some conditions and is often the best one (maximum or minimum). TSP, graph colouring and independent set are examples. They are hard because the number of candidate objects grows extremely fast with the input size (as in and ), and for most of them no polynomial-time algorithm is known — most computer scientists believe none exists. Shortest path is a fortunate exception: it looks combinatorial but has fast algorithms.
Geometric problems
Geometric algorithms work with points, lines and polygons, and are used in computer graphics, robotics, maps and medical imaging (tomography). Two classic problems:
- Closest pair — given points, find the two nearest to each other.
- Convex hull — find the smallest convex polygon containing all the points (like a rubber band stretched around nails).
Numerical problems
Numerical problems involve continuous mathematics: solving systems of linear equations, computing definite integrals, solving differential equations, evaluating functions and statistics. Many can only be solved approximately, because real numbers are stored with limited precision. The main danger is round-off error: small errors in each step can accumulate over many iterations and spoil the result.
Key takeaways
- Standard types: sorting, searching, string processing, graph, combinatorial, geometric, numerical.
- Comparison sorts need comparisons; non-comparison sorts can be linear for suitable keys.
- Stable = equal keys keep their order; in-place = only constant extra memory.
- Combinatorial problems explode in size (, ) and usually have no known efficient algorithm.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Run selection sort on [(P, 2), (Q, 2), (R, 1)] (sort by the number) and state whether the result shows stability.
Show worked answer
Pass 1: the minimum key is R(1) at position 3; swap with position 1 → [(R,1), (Q,2), (P,2)]. Pass 2: among positions 2–3, Q(2) and P(2) are equal, so no smaller key is found and nothing changes. Result: [(R,1), (Q,2), (P,2)]. P came before Q in the input but after it in the output, so this run shows that selection sort is not stable.