Skip to content
VUBuddy

CS502 Subjective Notes

Fundamentals of Algorithms PDF 655 KBUpdated 23 Oct 2026
Subjective CS502 Subjective Notes PDF 655 KB
vubuddy.com
Type
Subjective
Course
CS502 Fundamentals of Algorithms
Size
PDF 655 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 655 KB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 1, 2, 3 of 10. Download the file for all 10 pages.

 MUHAMMAD FAISAL  · MIT 4th Semester · Al-Barq Campus (VGJW01) Gujranwala · Reference Short Questions for MID TERM EXAMS · CS502– Design and Analysis of Algorithms · Divide and Conquer Strategy (Page#27)

The ancient Roman politicians understood an important principle of good algorithm design (although they were probably not thinking about algorithms at the time). You divide your enemies (by getting them to distrust each other) and then conquer them piece by piece. This is called divide-and-conquer. In algorithm design, the idea is to take a problem on a large input, break the input into smaller pieces, solve the problem on each of the small pieces, and then combine the piecewise solutions into a global solution. But once you have broken the problem into pieces, how do you solve these pieces? The answer is to apply divide-and-conquer to them, thus further breaking them down. The process ends when you are left with such tiny pieces remaining (e.g. one or two items) that it is trivial to solve them. Summarizing, the main elements to a divide-and-conquer solution are

Divide: the problem into a small number of pieces Conquer: solve each piece by applying divide and conquer to it recursively Combine: the pieces together into a global solution.

Selection Problem (Page#34)

Suppose we are given a set of n numbers. Define the rank of an element to be one plus the number of elements that are smaller. Thus, the rank of an element is its final position if the set is sorted. The minimum is of rank 1 and the maximum is of rank n.

Consider the set: {5, 7, 2, 10, 8, 15, 21, 37, 41}. The rank of each number is its position in the sorted order.

position Number

Sieve Technique (Page#34)

The reason for introducing this algorithm is that it illustrates a very important special case of divide-and-conquer, which I call the sieve technique. We think of divide-and-conquer as breaking the problem into a small number of smaller subproblems, which are then solved recursively. The sieve technique is a special case, where the number of subproblems is just 1.

The sieve technique works in phases as follows. It applies to problems where we are interested in finding a single item from a larger set of n items.

Slow Sorting Algorithms (Page#39)

There are a number of well-known slow O(n2) sorting algorithms. These include the following:

Bubble sort: Scan the array. Whenever two consecutive items are found that are out of order, swap them. Repeat until all consecutive items are in order.

Insertion sort: Assume that A[1..i − 1] have already been sorted. Insert A[i] into its proper position in this sub array. Create this position by shifting all larger elements to the right.

Selection sort: Assume that A[1..i − 1] contain the i − 1 smallest elements in sorted order. Find the smallest element in A[i..n] Swap it with A[i].

Heaps (Page#40)

A heap is a left-complete binary tree that conforms to the heap order. The heap order property: in a (min) heap, for every node X, the key in the parent is smaller than or equal to the key in X. In other words, the parent node has key smaller than or equal to both of its children nodes. Similarly, in a max heap, the parent has a key larger than or equal both of its children Thus the smallest key is in the root in a min heap; in the max heap, the largest is in the root.

Quicksort (Page#46)

Our next sorting algorithm is Quicksort. It is one of the fastest sorting algorithms known and is the method of choice in most sorting libraries. Quicksort is based on the divide and conquer strategy.

Here is the algorithm:

In-place, Stable Sorting (Page#46)

An in-place sorting algorithm is one that uses no additional array for storage. A sorting algorithm is stable if duplicate elements remain in the same relative position after sorting.

All CS502 files →
CS502 Fundamentals of Algorithms All CS502 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.