(SEM VI) THEORY EXAMINATION 2021-22 DESIGN AND ANALYSIS OF ALGORITHM

B.Tech Engineering 0 downloads
₹29.00

DESIGN AND ANALYSIS OF ALGORITHM (KECZ603)

Section-wise Detailed Answers


SECTION A

(Attempt all questions – Detailed explanations)


(a) Why is Heapify called only on the first half of elements while building a heap?


While building a heap from an array, the heap property needs to be enforced only on non-leaf nodes. In an array representation of a complete binary tree, all elements from index ⌊n/2⌋ + 1 to n are leaf nodes. Leaf nodes already satisfy the heap property because they do not have children.
 

Heapify is a procedure that compares a node with its children and fixes violations of the heap property. Since leaf nodes have no children, calling Heapify on them is unnecessary and wasteful. Therefore, Heapify is applied only from index ⌊n/2⌋ down to index 1 (or 0 in 0-based indexing). This optimization reduces unnecessary operations and ensures the heap is built efficiently in O(n) time.


(b) Recurrence relation of Tower of Hanoi and its solution


The Tower of Hanoi problem involves moving n disks from a source peg to a destination peg using an auxiliary peg, following the rule that no larger disk can be placed on a smaller one.

To move n disks:
 

Move n−1 disks from source to auxiliary peg.

Move the largest disk directly to the destination peg.

Move the n−1 disks from auxiliary peg to destination peg.

This leads to the recurrence relation:

T(n) = 2T(n−1) + 1, with T(1) = 1

Solving this recurrence using substitution:

T(n) = 2(2T(n−2) + 1) + 1
T(n) = 4T(n−2) + 3
Continuing this expansion gives:

T(n) = 2ⁿ − 1

Thus, the time complexity of Tower of Hanoi is exponential, O(2ⁿ), making it impractical for large values of n.


(c) Properties of Binomial Trees


A binomial tree of order k, denoted as Bₖ, has specific structural properties. It contains exactly 2ᵏ nodes and has a height of k. The root of the binomial tree has k children, which themselves are roots of binomial trees of orders k−1, k−2, ..., 0.


Each binomial tree is defined recursively and has the property that the number of nodes at depth d is equal to C(k, d). These properties make binomial trees suitable for implementing binomial heaps, which support efficient merging operations.


(d) Proof that a Red-Black tree with n internal nodes has height at most 2log(n+1)


A Red-Black tree is a balanced binary search tree with specific coloring properties. One crucial rule is that no two red nodes can be adjacent, meaning every red node must have black children.


Let bh be the black height of the tree. The minimum number of nodes in a Red-Black tree with black height bh is at least 2ᵇʰ − 1. Since the height h of the tree is at most twice the black height (because red nodes can only appear between black nodes), we have:
 

h ≤ 2bh

Since n ≥ 2ᵇʰ − 1
⇒ bh ≤ log(n + 1)

Therefore:

h ≤ 2log(n + 1)

This proves that Red-Black trees are height-balanced and guarantee logarithmic time operations.


(e) Why a shortest path cannot contain a cycle
 

A shortest path between two vertices must be the path with minimum total weight. If a path contains a cycle, it means that some vertices are revisited.
 

If the cycle has positive weight, removing it will reduce the total path cost, contradicting the assumption that the path was shortest. If the cycle has zero weight, removing it keeps the cost the same but simplifies the path. If the cycle has negative weight, the path can be reduced indefinitely, meaning no shortest path exists.
 

Hence, a shortest path never contains a cycle.
 

(f) Difference between adjacency list and adjacency matrix
 

An adjacency matrix represents a graph using a two-dimensional array where rows and columns represent vertices. It allows fast edge lookup but consumes O(V²) space, making it inefficient for sparse graphs.
 

An adjacency list stores each vertex along with a list of its adjacent vertices. It uses O(V + E) space and is efficient for sparse graphs. Traversal is also faster in adjacency lists for most graph algorithms.
 

(g) Branch and Bound technique
 

Branch and Bound is an optimization technique used to solve combinatorial problems. It systematically explores solution spaces by branching into subproblems and uses bounds to eliminate subproblems that cannot produce better solutions than the current best.
 

This method significantly reduces computation compared to brute force. It is commonly applied in problems like the Traveling Salesman Problem and Knapsack Problem.
 

(h) Dynamic Programming vs Divide and Conquer
 

Divide and Conquer breaks a problem into independent subproblems, solves them recursively, and combines results. Subproblems do not overlap, as seen in merge sort.
 

Dynamic Programming is used when subproblems overlap. It stores intermediate results to avoid recomputation, improving efficiency. Examples include Fibonacci, LCS, and Matrix Chain Multiplication.


(i) Complexity of naïve string matching algorithm
 

The naïve string matching algorithm compares a pattern of length m with a text of length n by shifting the pattern one position at a time.
 

In the worst case, it performs m comparisons for each of the n−m+1 shifts, resulting in a time complexity of O(nm).
 

(j) Difference between NP-Hard and NP-Complete
 

NP-Hard problems are at least as hard as the hardest problems in NP but may not belong to NP. NP-Complete problems are both in NP and NP-Hard.
 

Every NP-Complete problem can be verified in polynomial time, while NP-Hard problems may not have verifiable solutions in polynomial time.
 

SECTION B

(Attempt any three – Detailed solutions)
 

(a) Counting Sort on array {2,0,2,3,5,7,6,3,0,2,1,3}
 

Counting sort works by counting occurrences of each element. First, an auxiliary array C is created to store frequencies. The maximum element is 7, so C has indices 0 to 7.
 

After counting frequencies, cumulative counts are computed. Then the output array is built by placing elements in their correct positions using cumulative counts.
 

This algorithm runs in O(n + k) time and is stable, making it efficient for integers in a limited range.


(c) Minimum Cost Spanning Tree and Prim’s Algorithm

A Minimum Cost Spanning Tree (MST) connects all vertices of a graph with minimum total edge weight and no cycles.
 

Prim’s algorithm starts from an arbitrary vertex and repeatedly adds the minimum-weight edge that connects a vertex in the tree to a vertex outside it. This process continues until all vertices are included.

Using a priority queue, Prim’s algorithm runs in O(E log V) time.
 

(e) Approximation Algorithm and Vertex Cover
 

An approximation algorithm produces solutions close to optimal within a known factor. A P(n) approximation algorithm guarantees a solution within P(n) times the optimal.
 

For the vertex cover problem, a 2-approximation algorithm repeatedly selects an edge and includes both its endpoints in the cover. This guarantees the solution is at most twice the optimal size.
 

SECTION C

(Attempt any one – Detailed explanation)
 

(a) Merge Sort Algorithm and Time Complexity
 

Merge sort follows the divide and conquer approach. It divides the array into halves until single-element arrays are obtained. Then, it merges these arrays in sorted order.
 

The recurrence relation is:

T(n) = 2T(n/2) + O(n)

Using the Master Theorem, the time complexity is O(n log n) in all cases. Merge sort is stable and efficient but requires additional memory.
 

(b) Quick Sort with Example
 

Quick sort selects a pivot, partitions the array around the pivot, and recursively sorts subarrays.

Applying quick sort to:
12, 13, 10, 5, 7, 3, 2, 17, 23, 16

After successive partitions, the sorted order becomes:
2, 3, 5, 7, 10, 12, 13, 16, 17, 23

The average time complexity is O(n log n), but the worst case is O(n²). Proper pivot selection reduces the likelihood of worst-case behavior.

File Size
160.19 KB
Uploader
SuGanta International
⭐ Elite Educators Network

Meet Our Exceptional Teachers

Discover passionate educators who inspire, motivate, and transform learning experiences with their expertise and dedication

KISHAN KUMAR DUBEY

KISHAN KUMAR DUBEY

Sant Ravidas Nagar Bhadohi, Uttar Pradesh , Babusarai Market , 221314
5 Years
Years
₹10000+
Monthly
₹201-300
Per Hour

This is Kishan Kumar Dubey. I have done my schooling from CBSE, graduation from CSJMU, post graduati...

Swethavyas bakka

Swethavyas bakka

Hyderabad, Telangana , 500044
10 Years
Years
₹10000+
Monthly
₹501-600
Per Hour

I have 10+ years of experience in teaching maths physics and chemistry for 10th 11th 12th and interm...

Vijaya Lakshmi

Vijaya Lakshmi

Hyderabad, Telangana , New Nallakunta , 500044
30+ Years
Years
₹9001-10000
Monthly
₹501-600
Per Hour

I am an experienced teacher ,worked with many reputed institutions Mount Carmel Convent , Chandrapu...

Shifna sherin F

Shifna sherin F

Gudalur, Tamilnadu , Gudalur , 643212
5 Years
Years
₹6001-7000
Monthly
₹401-500
Per Hour

Hi, I’m Shifna Sherin! I believe that every student has the potential to excel in Math with the righ...

Divyank Gautam

Divyank Gautam

Pune, Maharashtra , Kothrud , 411052
3 Years
Years
Not Specified
Monthly
Not Specified
Per Hour

An IIT graduate having 8 years of experience teaching Maths. Passionate to understand student proble...

Explore Tutors In Your Location

Discover expert tutors in popular areas across India

Hotel Management Course Near Sector 93A Gurugram – Build a Successful Career in Hospitality Sector 93, Gurugram
SEO Training Near Noida Sector 95 – Learn Search Engine Optimization and Build a Digital Career Noida
Spoken English Classes Near By Vikaspuri Improve Fluency, Build Confidence & Unlock Career Opportunities in 2026 Vikaspuri, Delhi
Spoken English Classes Near By Najafgarh Improve Fluency, Build Confidence & Open New Career Opportunities in 2026 Najafgarh, Delhi
German Language Classes Near Central Park 2 – Learn German for Career, Study & Global Opportunities Central Park 2, Gurugram
Maths Coaching Near By Dwarka Mor – Build Strong Concepts & Score Higher Dwarka Mor, Delhi
Personal Fitness Training Near Sector 134 Greater Noida – Achieve Your Fitness Goals with Expert Guidance Sector 134, Noida
Music Production (Laptop-Based) Near DLF Cyber City – Learn Professional Music Creation DLF Cyber City, Gurugram
Hindi Coaching Classes Near By Dwarka Mor Build Strong Language Skills Dwarka Mor, Delhi
🇯🇵 Japanese Language Classes Near Sector 54 Gurugram – Learn Japanese with Expert Guidance Gurugram
Financial Advisor Near Sector 104 Gurugram (Dwarka Expressway) – Smart Planning for a Secure Future Dwarka Expressway in Sector 104, Gurugram
Yoga Classes Near By Greater Kailash Achieve Strength, Flexibility & Mental Peace with Expert Yoga Training in 2026 Greater Kailash, Delhi
App Development Course Near Sector 60 Gurugram – Build Android & iOS Apps with Industry Experts Gurugram
Financial Advisory Near By Dwarka Mor Professional Financial Planning, Investment Guidance & Wealth Management Support Dwarka Mor, Delhi
Piano Classes Near Tilak Nagar – Learn, Play & Master Music with Confidenc Tilak Nagar, Delhi
Yoga Classes Near Sector 138 Greater Noida – Improve Health, Mind & Lifestyle Through Professional Yoga Training Noida
Web Development Classes Near Uttam Nagar – Learn to Build Modern Websites Uttam Nagar, Delhi
Public Speaking Training Near Sector 109 Noida – Improve Confidence and Communication Skills Noida
Spoken English Classes Near By Tilak Nagar Improve Fluency, Build Confidence & Unlock Career Opportunities in 2026 Tilak Nagar, Delhi
Music Production (Laptop-Based) Classes Near Sector 143 Noida – Learn Professional Music Creation Sector 143, Noida
⭐ Premium Institute Network

Discover Elite Educational Institutes

Connect with top-tier educational institutions offering world-class learning experiences, expert faculty, and innovative teaching methodologies

Réussi Academy of languages

sugandha mishra

Réussi Academy of languages
Madhya pradesh, Indore, G...

Details

Coaching Center
Private
Est. 2021-Present

Sugandha Mishra is the Founder Director of Réussi Academy of Languages, a premie...

IGS Institute

Pranav Shivhare

IGS Institute
Uttar Pradesh, Noida, Sec...

Details

Coaching Center
Private
Est. 2011-2020

Institute For Government Services

Krishna home tutor

Krishna Home tutor

Krishna home tutor
New Delhi, New Delhi, 110...

Details

School
Private
Est. 2001-2010

Krishna home tutor provide tutors for all subjects & classes since 2001

Edustunt Tuition Centre

Lakhwinder Singh

Edustunt Tuition Centre
Punjab, Hoshiarpur, 14453...

Details

Coaching Center
Private
Est. 2021-Present
Great success tuition & tutor

Ginni Sahdev

Great success tuition & tutor
Delhi, Delhi, Raja park,...

Details

Coaching Center
Private
Est. 2011-2020