(CSE 246) Lab - Covered Topics
(CSE 246) Lab - Covered Topics
1. Binary search: Given a sorted array of n integers and a target value, determine if the
target exists in the array in logarithmic time using the binary search algorithm. If target
exists in the array, print the index of it.
Sample input Sample output
2. Reverse Binary search: Given a reverse sorted array of n integers and a target value,
determine if the target exists in the array in logarithmic time using the binary search
algorithm. If the target exists in the array, print the index of it.
3. Quick Sort: Given an integer array, sort it using the merge sort algorithm.
Sample input Sample output
Data: 12, 6, 7 6 7 12
1. Fractional knapsack: Given the weights and profits of N items, in the form of {profit,
weight} put these items in a knapsack of capacity W to get the maximum total profit in
the knapsack. In Fractional Knapsack, we can break items for maximizing the total value
of the knapsack.
2. Activity selection problem: You are given n activities with their start and finish times.
Select the maximum number of activities that can be performed by a single person,
assuming that a person can only work on a single activity at a time.
Sample input Sample output
1. GCD: Given two numbers a and b, the task is to find the GCD of the two numbers using
Euclid’s algorithm.
Sample input Sample output
a = 20 4
b = 28
2. Sieve method: Given a number n, print all primes smaller than or equal to n using sieve
method. It is also given that n is a small number.
Sample input Sample output
10 2357
3. LCM: Given two numbers a and b, the task is to find the LCMof the two numbers.
Sample input Sample output
a=4 12
b=6
East West University
Department of Computer Science and Engineering
Course: CSE246 Algorithm Topic: String and Pattern matching Lab: 04
1. Rabin-Karp: Implement a program to search for a pattern in a text using the Rabin-Karp
algorithm.
2. Naive Matching: Implement a program to search for a pattern in a text by just naively
checking.
1. 0-1 Knapsack: You are given a set of items, each with a weight and a value, and a
knapsack with a maximum weight capacity. Your task is to determine the maximum
value that can be obtained by selecting a subset of the items to fit into the knapsack
without exceeding its weight capacity.
Sample input Sample output
4 9
23
34
45
56
8
2. Coin change: You are given n types of coins and another number K. Your task is to
determine whether it is possible to generate K using those coins if
i. The number of each coin is infinite.
ii. The number of each coin is finite.
3. Coin change: You are given n types of coins and another number K. Your task is to find
the minimum number of coins required to make K if.
i. The number of each coin is infinite.
ii. The number of each coin is finite.