Cost Optimal Parallel Algorithm for 0-1 Knapsack Problem

Size: px
Start display at page:

Download "Cost Optimal Parallel Algorithm for 0-1 Knapsack Problem"

Transcription

1 Cost Optimal Parallel Algorithm for 0-1 Knapsack Problem Project Report Sandeep Kumar Ragila Rochester Institute of Technology Santosh Vodela Rochester Institute of Technology ABSTRACT NP-Hard problems are as hard as NP-problem. Solving these NP-Hard problems are computationally hard, one such problem that we will be looking at in this paper is 0-1 Knapsack problem. 0-1 Knapsack problems are highly used in areas like cargo loading, scoring of tests and badge processing. We will take a heuristic search approach to solve the problem by using the multicore parallel programming techniques[3]. 1. COMPUTATIONAL PROBLEM The 0-1 Knapsack problem is best expressed as the question: Given a set V of n items to be packed in a knapsack of capacity C, where each item in V has a weight and profit associated with it, the problem is to choose a subset of items such that the total weight of the items chosen does not exceed the knapsack capacity C and they give maximum profit. 0-1 Knapsack problem is a modification of the knapsack problem, here no fractions are allowed. 2. RELATED WORK 2.1 Research Paper 1 Authors of paper [4] LI Ken-Li et. al. talk about the parallel Three-List Algorithm and about the past research on solving the knapsack problem. In the Parallel three list algorithm they are two stages namely generation stage and the search stage. In the generation stage the input is divided into three parts W 1, W 2 and W 3 of sizes 7n/16, 7n/16 and 2n/16 respectively, here n is the size of the input. Next for each part, generate all possible subsets in descending order and name them as A, B, and C. In the search stage, for every possible value in C, do a binary search over A+B. If the total sum of that pair is equal to the desired solution, output that solution. The author also discusses how to parallelise this algorithm. The author based on the Three-list algorithm propose an enhanced parallel algorithm to improve speed up and also reduce the memory consumption. In the authors proposed algorithm, each of the two lists generated A and Copyright 2015 ACM X-XXXXX-XX-X/XX/XX...$ B occupy a size of O(27n/16), which can be dynamically generated by using only O(213n/48) shared memory units. In the search stage of the new algorithm, this stage is after the parallel generation stage so by now list A and B are generated in descending order. Now for each processor if A[i] + B[j] = M-c[m], then stop: solution found if A[i] + B[j] < M-c[M], then i=i+1; else j=j+1 check the above rules till i or j go more than the list sizes. In the three list generation stage, the authors discuss how to use 2k Tabes to dynamically generate two sorted lists. They use six tables T 1, T 2...T 6 in which T 1 include all subsets of W 11= (w 1,w 2,...,w 7n/48), T 3 includes subsets of W 13= (w 14n/48+1, w 14n/48+2,..., w 21n/48). Similarly for T 4 and T 6. Now T 1 is sorted in ascending order and the author mentioned about using priority queues for faster retrieval of the min sum. In the algorithm, values from T 1 and T 2 are added in order and inserted into a queue Q1, For every pair check if it is needed for the objectivity of computation, delete that sum from Q 1 and insert into successor Q 2 by adding value from T 3. This is repeated till Q 1 is empty and we have the complete list Q 2. Similarly this is done for list B that is T 4, T 5, and T 6. These generated lists are now passed to the search stage to find a possible solution. This algorithm is an efficient way to save space when computing subsets as the size of N increases, and we are likely to run out of space to store all the possible combinations. 2.2 Research Paper 2 Paper [1] V. Boyer et. al. analyzes techniques to parallelize the dynamic programming method for solving 0-1 Knapsack problem on a GPU. It mainly focuses on memory optimizations and the processing time. To achieve this goal it uses a data compression algorithm with less memory occupancy to compute large problem sizes within small processing time. The paper also provides some computational results for various experiments. As we know how to solve a knapsack problem using dynamic programming they leverage this idea using GPU architecture. Their idea is to reduce the amount of communication between CPU and the GPU and compute most of the computations on the GPU. They propose that each GPU core will calculate the subproblem of finding the items that should be included to fit a capacity c i where 0<= i <= C. The other technique in this process is to store the results of items that are included in a knapsack memory efficient way. At each stage knapsack problem has to decide whether it has to include a particular element or not. This is a Boolean decision. So in order to maintain one such decision they have previously stored the value in a single 32-bit integer but, we can store 32 item decisions in a

2 single integer variable where each bit represents if that item is included or not. This will reduce the amount of memory used by the system to store the results drastically. When an item is included in the knapsack, then they add 2 i to the output that will set the bit at an i th location indicating the item is included. They have a counter that increments for every item and when the counter hits 32 that determines all the 32 bits are set they remove the results and store in a matrix in order to store the results of the next items. So communication between CPU and GPU happens for every 32 iterations. Their analysis also shows that the computational speed is increased when the values are sorted in profit per weight ratio. 2.3 Research Paper 3 Authors of paper[2] M. E. Lalami et. al. talk about a new approach to solving the knapsack problem, which is the Branch and Bound Approach. They discuss how the algorithm can be used to reduce the number of computations and come up with a better and efficient solution. They also propose a technique to use the algorithm on a CPU-GPU system via CUDA. Branch and Bound Algorithm: The Branch and Bound algorithm follows an approach of enumerating all the possible solution but with pruning a significant amount of branches. There are several solutions that follow a greedy approach by checking all the possible branches from the root. But, Branch and Bound, at each stage decides whether to traverse down the specific path or take a different one. In this algorithm items are called nodes where branching and bounding operations will be performed on these nodes. Each node is represented as a 5 tuple (w e, p e, X e, U e, L e) where e is the current node, we is the weight of the current node, pe represents the profit of the current node, Xe is the solution subvector, U e is the upper bound and L e is the lower bound. The upper bound can be calculated by using any popular greedy knapsack algorithm, and Lower bound can be calculated in the same way but adding fractions is disallowed. Once we have represented a node as above, we compare the upper bound and lower bounds of all the current nodes, i.e., the nodes at a certain level in a tree. Then we first calculate the maximum lower bound of all the nodes then if we find that the upper bound of any node is less than the maximum lower bound we prune this node and no searching is done down this path. At each step we either go to the right or the left of the tree, so, the value on each edge will be either a 0 or 1 which indicated whether we included that node or not. If we would like to see the included nodes we traverse the final tree along the path, which has edge values 1. The authors use this kind of algorithm to divide the computation between CPU and GPU to speed up the processing. They suggest that we have a threshold on the number of nodes and if the input is less than the threshold we compute the branching and bounding operations on CPU itself. This is because, as the input size is small the communication between CPU and GPU will be higher than the computations that indeed decrease the speed. So, if the input is higher than threshold we first transfer the nodes to the device and then launch branch and bounding operations on GPU from CPU. After each step the GPU will return the tuple to the CPU where the CPU checks if it has to prune the node or include it. The authors have tested this approach with large data sets and found it was efficient in calculating them as the algorithm does not enumerate all the possible solutions. Also, the operations are done using GPU. 3. IMPLEMENTATION 3.1 Sequential Program In our sequential design, we have followed a two list algorithm discussed by the paper. The sequential algorithm has two stages Generation Stage In the generation stage, we take the input that is a list of n items say V and then we divide this list into two disjoint sets V 1 and V 2 of equal length. Now we have calculated each subset in V 1 and subsets are represented as ai. After diving the list into two sub-lists we get 2 n/2 subsets each. For each subset a i calculate its a i.w (weight sum of the subset) and a i.p(profit sum of all items in subset a i). Each subset item is represented as a triplet (a i, a i.w, a i.p) and arrange all these triplets in increasing order of weight. We do the similar thing for V 2 but the triplets are stored in non-increasing order of weight Search Stage In the search stage the two generated list are compared to check which combination of items yields the maximum profit. We have used ArrayLists to store the lists and to generate the subsets we have used the bitset class present in pj Parallel Program Our parallel program follows the same idea as the sequential program. This uses the two list algorithm but with additional algorithms which minimize the number of subsets to be compared. In the sequential approach we have compared all the enumerations of the two lists but in parallel program lot of subsets are pruned and hence we will gain a speed up. The parallel design has five stages Parallel Generation Stage In this stage we have divided the list into two lists and then used bitset class to generate the bitmap. After generating the bitmap, we send this to a parallel for and loop over all the possible combinations. So, each thread will calculate one subset and hence all the threads are used to calculate all possible subsets of n/2 elements. Using this approach we are reducing the number of subsets we generate. If we generate subsets of n items, we get 2 n subsets but if we divide n into n/2 we get (2 n/2 + 2 n/2 ) subsets. We also use an optimal merge algorithm to merge the lists generated by all the threads into one list also in sorted order. We repeat the same thing for the other list First Parallel Saving Max-value Stage In this stage we take the lists generated in the above phase (say A and B) and partition the lists into K blocks. Where K is the number of processors used. We then send these K blocks to K processors and compute max profit value among the blocks The Parallel Pruning Stage This stage is the most important stage for our parallel program as we discard most of the subsets, which does not

3 provide us the optimal solution using few lemmas. By not considering the subsets we do not compare all the possible combinations we have computed and thus increasing the computational speed. Below are the lemmas used to prune the subsets. Lemma 1: For any block pair, if sum of the first element in A and last element in B is greater than c (max weight), prune this block as the solution is not possible further. Lemma 2: For any block pair, if the sum of the last element of A and first element in B is less than c (max weight), save the max profit to further examine this pair. We do this in parallel for K threads that are the number of processors. So the full utilization of cores is being done The Second Parallel Saving Max-value Stage Before the pruning stage there were K2 number of block pairs but after pruning stage the number of block pairs is significantly reduce to at most 2k-1. We send these 2k-1 pairs to K available cores to calculate the max profit for the pruned pairs. So, each core may get at most two block pairs to execute The Parallel Search Stage This is the final stage of our parallel program. In this stage all the cores calculate the max value for the pruned block pairs and reduce to a single reduction variable to get the best max value of all the subsets 3.3 Developer s Manual We have used RIT CS department machines to test our programs. We have mainly used machines nessie and kraken as nessie has got 16 cores and kraken with 80 cores. To run the program, we first need to create a jar consisting of all the class files. Below are the steps to create the jar file. 1. Set the classpath Setting the classpath in nessie or kraken using bash shell: input line is the knapsack total capacity C and n lines follow. Each line after the first line has three numbers in it. Each represents an item where the first number is the item number, the second number is the weight of the item, and the third number is the profit for that item. export CLASSPATH=.:/var/tmp/parajava/pj2/pj2.jar Setting the classpath in nessie or kraken using csh shell: setenv CLASSPATH.:/var/tmp/parajava/pj2/pj2.jar 2. Compile the java files: javac *.java 3. Creating the jar file with class files: jar cf myprogram.jar *.class 3.4 User s Manual We have to use the jar file that was created using the above commands. To run the sequential version of the program, run: java pj2 jar=<jar file> KnapsackSeq <input file> Where <jar file> is the name of the jar file created, <input file> is the name of the input file To run the parallel version of the program run: java pj2 cores=<k> jar=<jar file> KnapsackSmp <input file> Where K is the number of cores to be used, <jar file> is the name of the jar file created, <input file> is the name of the input file The input files are in the form of.txt, generating using a random number generation program. The first line of the 4. PERFORMANCE Figure 1: Strong scaling 4.1 Strong Scaling As we can see Strong scaling performance in Table 1 data. We have tested the program with input data items ranging from 32 to 40. We can observe that as the number of cores increases the speed decreases. This is because as we increase the cores the sequential fraction of the program becomes significant and we cannot avoid that part. Initially we have a peak as we are using a two list algorithm, generating two lists on one core is not very efficient when compared to the performance on the two cores. We have observed ideal strong scaling for higher N value. 4.2 Weak Scaling Table 2 shows the weak scaling performance for input sizes 34 to 42. As the value of N increases by 2, the number of calculations increase by 22 that is 4 times the number of

4 Figure 2: Weak scaling Figure 4: speedup vs cores data size:34 Figure 5: efficiency vs cores data size:34 Figure 3: time parallel vs cores data size:32 cores. As we are generating two lists, each list will increase by 2. We were able to get good efficiency for 1,2 and 8 cores, but as the number of cores increases beyond 8 cores the sequential part plays role and our efficiency is decreasing. Also one of the factor could be that the input data is different for each input size for lower efficiency. 5. FUTURE WORK The algorithm that we have implemented has five stages and hence it takes quite some time to execute these in CPU. We can extend the same algorithm to compute the results on the GPU. Since we are calculating all possible subsets of a set and these subsets are not dependent we can execute them on different cores. This operation can be better utilized by the GPU cores, thus making the computations fast. We can also use other algorithms discussed in the research papers to get exact optimal solution rather than the heuristic approach which we have followed. 6. LESSONS LEARNED We learned about knapsack problem and different algorithms to solve the problem. The exciting thing about the project is that we learned what a heuristic search is and how to achieve a near optimal solution. The emphasize on strong scaling and weak scaling gave us a good understanding of the parallel program performance. If the input is too small and the number of cores is high, we would not achieve a high efficiency. As the number of cores increases for a large data, we get a speed up. We also learned that the two list algorithm that we have used will significantly reduce the number of subsets to be evaluated and hence gaining faster performance. Apart from all these learning s we looked into different aspects of Parallel Java 2 library. 7. TEAM CONTRIBUTION Finding the research papers and deciding the topic is a mutual task done by each team member. Sandeep has come up with the sequential design and implemented it. He also implemented two of the five algorithms in the parallel program. Santosh has designed the parallel version of our project. He has implemented three of the five algorithms in parallel

5 Figure 7: cores vs sizeup Figure 6: cores vs Time program. Measuring the strong scaling and weak scaling performances, writing the project report, documenting the code and other works were a mutual task by each team member. Figure 8: cores vs efficiency 8. REFERENCES [1] V. Boyer, D. El Baz, and M. Elkihel. Solving knapsack problems on gpu. Computers & Operations Research, 39(1):42 47, [2] M. E. Lalami and D. El-Baz. Gpu implementation of the branch and bound method for knapsack problems. In Parallel and Distributed Processing Symposium Workshops & PhD Forum (IPDPSW), 2012 IEEE 26th International, pages IEEE, [3] K. Li, J. Liu, L. Wan, S. Yin, and K. Li. A cost-optimal parallel algorithm for the 0 1 knapsack problem and its performance on multicore cpu and gpu implementations. Parallel Computing, 43:27 42, [4] L. R.-F. LI Ken-Li, ZHAO Huan and L. Qing-Hua. A parallel time-memory-processor tradeoff o(25n/6) for knapsack-like np-complete problems. pages , 2007.

Subset Sum Problem Parallel Solution

Subset Sum Problem Parallel Solution Subset Sum Problem Parallel Solution Project Report Harshit Shah hrs8207@rit.edu Rochester Institute of Technology, NY, USA 1. Overview Subset sum problem is NP-complete problem which can be solved in

More information

N N Sudoku Solver. Sequential and Parallel Computing

N N Sudoku Solver. Sequential and Parallel Computing N N Sudoku Solver Sequential and Parallel Computing Abdulaziz Aljohani Computer Science. Rochester Institute of Technology, RIT Rochester, United States aaa4020@rit.edu Abstract 'Sudoku' is a logic-based

More information

Search Algorithms. IE 496 Lecture 17

Search Algorithms. IE 496 Lecture 17 Search Algorithms IE 496 Lecture 17 Reading for This Lecture Primary Horowitz and Sahni, Chapter 8 Basic Search Algorithms Search Algorithms Search algorithms are fundamental techniques applied to solve

More information

Chapter 16 Heuristic Search

Chapter 16 Heuristic Search Chapter 16 Heuristic Search Part I. Preliminaries Part II. Tightly Coupled Multicore Chapter 6. Parallel Loops Chapter 7. Parallel Loop Schedules Chapter 8. Parallel Reduction Chapter 9. Reduction Variables

More information

FINAL REPORT: K MEANS CLUSTERING SAPNA GANESH (sg1368) VAIBHAV GANDHI(vrg5913)

FINAL REPORT: K MEANS CLUSTERING SAPNA GANESH (sg1368) VAIBHAV GANDHI(vrg5913) FINAL REPORT: K MEANS CLUSTERING SAPNA GANESH (sg1368) VAIBHAV GANDHI(vrg5913) Overview The partitioning of data points according to certain features of the points into small groups is called clustering.

More information

Analysis of Algorithms - Greedy algorithms -

Analysis of Algorithms - Greedy algorithms - Analysis of Algorithms - Greedy algorithms - Andreas Ermedahl MRTC (Mälardalens Real-Time Reseach Center) andreas.ermedahl@mdh.se Autumn 2003 Greedy Algorithms Another paradigm for designing algorithms

More information

Subset Sum - A Dynamic Parallel Solution

Subset Sum - A Dynamic Parallel Solution Subset Sum - A Dynamic Parallel Solution Team Cthulu - Project Report ABSTRACT Tushar Iyer Rochester Institute of Technology Rochester, New York txi9546@rit.edu The subset sum problem is an NP-Complete

More information

Foundation of Parallel Computing- Term project report

Foundation of Parallel Computing- Term project report Foundation of Parallel Computing- Term project report Shobhit Dutia Shreyas Jayanna Anirudh S N (snd7555@rit.edu) (sj7316@rit.edu) (asn5467@rit.edu) 1. Overview: Graphs are a set of connections between

More information

Massively Parallel Approximation Algorithms for the Knapsack Problem

Massively Parallel Approximation Algorithms for the Knapsack Problem Massively Parallel Approximation Algorithms for the Knapsack Problem Zhenkuang He Rochester Institute of Technology Department of Computer Science zxh3909@g.rit.edu Committee: Chair: Prof. Alan Kaminsky

More information

UNIT 4 Branch and Bound

UNIT 4 Branch and Bound UNIT 4 Branch and Bound General method: Branch and Bound is another method to systematically search a solution space. Just like backtracking, we will use bounding functions to avoid generating subtrees

More information

Algorithm Design Methods. Some Methods Not Covered

Algorithm Design Methods. Some Methods Not Covered Algorithm Design Methods Greedy method. Divide and conquer. Dynamic Programming. Backtracking. Branch and bound. Some Methods Not Covered Linear Programming. Integer Programming. Simulated Annealing. Neural

More information

Greedy Algorithms CHAPTER 16

Greedy Algorithms CHAPTER 16 CHAPTER 16 Greedy Algorithms In dynamic programming, the optimal solution is described in a recursive manner, and then is computed ``bottom up''. Dynamic programming is a powerful technique, but it often

More information

GPU Implementation of the Branch and Bound method for knapsack problems

GPU Implementation of the Branch and Bound method for knapsack problems 2012 IEEE 201226th IEEE International 26th International Parallel Parallel and Distributed and Distributed Processing Processing Symposium Symposium Workshops Workshops & PhD Forum GPU Implementation of

More information

Theorem 2.9: nearest addition algorithm

Theorem 2.9: nearest addition algorithm There are severe limits on our ability to compute near-optimal tours It is NP-complete to decide whether a given undirected =(,)has a Hamiltonian cycle An approximation algorithm for the TSP can be used

More information

Chapter 26 Cluster Heuristic Search

Chapter 26 Cluster Heuristic Search Chapter 26 Cluster Heuristic Search Part I. Preliminaries Part II. Tightly Coupled Multicore Part III. Loosely Coupled Cluster Chapter 18. Massively Parallel Chapter 19. Hybrid Parallel Chapter 20. Tuple

More information

CS473-Algorithms I. Lecture 11. Greedy Algorithms. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS473-Algorithms I. Lecture 11. Greedy Algorithms. Cevdet Aykanat - Bilkent University Computer Engineering Department CS473-Algorithms I Lecture 11 Greedy Algorithms 1 Activity Selection Problem Input: a set S {1, 2,, n} of n activities s i =Start time of activity i, f i = Finish time of activity i Activity i takes place

More information

Massively Parallel Seesaw Search for MAX-SAT

Massively Parallel Seesaw Search for MAX-SAT Massively Parallel Seesaw Search for MAX-SAT Harshad Paradkar Rochester Institute of Technology hp7212@rit.edu Prof. Alan Kaminsky (Advisor) Rochester Institute of Technology ark@cs.rit.edu Abstract The

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms An algorithm is any well-defined computational procedure that takes some value or set of values as input, and produces some value or set of values as output. 1 Why study algorithms?

More information

A Hybrid Recursive Multi-Way Number Partitioning Algorithm

A Hybrid Recursive Multi-Way Number Partitioning Algorithm Proceedings of the Twenty-Second International Joint Conference on Artificial Intelligence A Hybrid Recursive Multi-Way Number Partitioning Algorithm Richard E. Korf Computer Science Department University

More information

Greedy Algorithms 1. For large values of d, brute force search is not feasible because there are 2 d

Greedy Algorithms 1. For large values of d, brute force search is not feasible because there are 2 d Greedy Algorithms 1 Simple Knapsack Problem Greedy Algorithms form an important class of algorithmic techniques. We illustrate the idea by applying it to a simplified version of the Knapsack Problem. Informally,

More information

Maximum Clique Problem

Maximum Clique Problem Maximum Clique Problem Dler Ahmad dha3142@rit.edu Yogesh Jagadeesan yj6026@rit.edu 1. INTRODUCTION Graph is a very common approach to represent computational problems. A graph consists a set of vertices

More information

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq

More information

CAD Algorithms. Categorizing Algorithms

CAD Algorithms. Categorizing Algorithms CAD Algorithms Categorizing Algorithms Mohammad Tehranipoor ECE Department 2 September 2008 1 Categorizing Algorithms Greedy Algorithms Prim s Algorithm (Minimum Spanning Tree) A subgraph that is a tree

More information

Chapter 13 Strong Scaling

Chapter 13 Strong Scaling Chapter 13 Strong Scaling Part I. Preliminaries Part II. Tightly Coupled Multicore Chapter 6. Parallel Loops Chapter 7. Parallel Loop Schedules Chapter 8. Parallel Reduction Chapter 9. Reduction Variables

More information

Algorithms Dr. Haim Levkowitz

Algorithms Dr. Haim Levkowitz 91.503 Algorithms Dr. Haim Levkowitz Fall 2007 Lecture 4 Tuesday, 25 Sep 2007 Design Patterns for Optimization Problems Greedy Algorithms 1 Greedy Algorithms 2 What is Greedy Algorithm? Similar to dynamic

More information

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD 1 DESIGN AND ANALYSIS OF ALGORITHMS UNIT II Objectives GREEDY METHOD Explain and detail about greedy method Explain the concept of knapsack problem and solve the problems in knapsack Discuss the applications

More information

( ) n 3. n 2 ( ) D. Ο

( ) n 3. n 2 ( ) D. Ο CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.

More information

16 Greedy Algorithms

16 Greedy Algorithms 16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices

More information

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n) CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The

More information

Greedy algorithms is another useful way for solving optimization problems.

Greedy algorithms is another useful way for solving optimization problems. Greedy Algorithms Greedy algorithms is another useful way for solving optimization problems. Optimization Problems For the given input, we are seeking solutions that must satisfy certain conditions. These

More information

Greedy Algorithms. Informal Definition A greedy algorithm makes its next step based only on the current state and simple calculations on the input.

Greedy Algorithms. Informal Definition A greedy algorithm makes its next step based only on the current state and simple calculations on the input. Greedy Algorithms Informal Definition A greedy algorithm makes its next step based only on the current state and simple calculations on the input. easy to design not always correct challenge is to identify

More information

Search Algorithms for Discrete Optimization Problems

Search Algorithms for Discrete Optimization Problems Search Algorithms for Discrete Optimization Problems Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text ``Introduction to Parallel Computing'', Addison Wesley, 2003. 1 Topic

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS483-001) Amarda Shehu Spring 2017 1 The Fractional Knapsack Problem Huffman Coding 2 Sample Problems to Illustrate The Fractional Knapsack Problem Variable-length (Huffman)

More information

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph. Trees 1 Introduction Trees are very special kind of (undirected) graphs. Formally speaking, a tree is a connected graph that is acyclic. 1 This definition has some drawbacks: given a graph it is not trivial

More information

( ) 1 B. 1. Suppose f x

( ) 1 B. 1. Suppose f x CSE Name Test Spring Last Digits of Student ID Multiple Choice. Write your answer to the LEFT of each problem. points each is a monotonically increasing function. Which of the following approximates the

More information

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Priority Queues and Heaps

Computer Science 210 Data Structures Siena College Fall Topic Notes: Priority Queues and Heaps Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Priority Queues and Heaps Heaps and Priority Queues From here, we will look at some ways that trees are used in other structures. First,

More information

L2: Algorithms: Knapsack Problem & BnB

L2: Algorithms: Knapsack Problem & BnB L2: Algorithms: Knapsack Problem & BnB This tutorial covers the basic topics on creating a forms application, common form controls and the user interface for the optimization models, algorithms and heuristics,

More information

Parallel Computing in Combinatorial Optimization

Parallel Computing in Combinatorial Optimization Parallel Computing in Combinatorial Optimization Bernard Gendron Université de Montréal gendron@iro.umontreal.ca Course Outline Objective: provide an overview of the current research on the design of parallel

More information

Chapter 31 Multi-GPU Programming

Chapter 31 Multi-GPU Programming Chapter 31 Multi-GPU Programming Part I. Preliminaries Part II. Tightly Coupled Multicore Part III. Loosely Coupled Cluster Part IV. GPU Acceleration Chapter 29. GPU Massively Parallel Chapter 30. GPU

More information

Priority Queue: Heap Structures

Priority Queue: Heap Structures Priority Queue: Heap Structures Definition: A max-heap (min-heap) is a complete BT with the property that the value (priority) of each node is at least as large (small) as the values at its children (if

More information

General Methods and Search Algorithms

General Methods and Search Algorithms DM811 HEURISTICS AND LOCAL SEARCH ALGORITHMS FOR COMBINATORIAL OPTIMZATION Lecture 3 General Methods and Search Algorithms Marco Chiarandini 2 Methods and Algorithms A Method is a general framework for

More information

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science Entrance Examination, 5 May 23 This question paper has 4 printed sides. Part A has questions of 3 marks each. Part B has 7 questions

More information

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD UNIT 3 Greedy Method GENERAL METHOD Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset

More information

3 INTEGER LINEAR PROGRAMMING

3 INTEGER LINEAR PROGRAMMING 3 INTEGER LINEAR PROGRAMMING PROBLEM DEFINITION Integer linear programming problem (ILP) of the decision variables x 1,..,x n : (ILP) subject to minimize c x j j n j= 1 a ij x j x j 0 x j integer n j=

More information

The Size Robust Multiple Knapsack Problem

The Size Robust Multiple Knapsack Problem MASTER THESIS ICA-3251535 The Size Robust Multiple Knapsack Problem Branch and Price for the Separate and Combined Recovery Decomposition Model Author: D.D. Tönissen, Supervisors: dr. ir. J.M. van den

More information

INDIAN STATISTICAL INSTITUTE

INDIAN STATISTICAL INSTITUTE INDIAN STATISTICAL INSTITUTE Mid Semestral Examination M. Tech (CS) - I Year, 2016-2017 (Semester - II) Design and Analysis of Algorithms Date : 21.02.2017 Maximum Marks : 60 Duration : 3.0 Hours Note:

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 018 D/Q Greed SP s DP LP, Flow B&B, Backtrack Metaheuristics P, NP Design and Analysis of Algorithms Lecture 8: Greed Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Optimization

More information

CSE 417 Branch & Bound (pt 4) Branch & Bound

CSE 417 Branch & Bound (pt 4) Branch & Bound CSE 417 Branch & Bound (pt 4) Branch & Bound Reminders > HW8 due today > HW9 will be posted tomorrow start early program will be slow, so debugging will be slow... Review of previous lectures > Complexity

More information

Backtracking. Chapter 5

Backtracking. Chapter 5 1 Backtracking Chapter 5 2 Objectives Describe the backtrack programming technique Determine when the backtracking technique is an appropriate approach to solving a problem Define a state space tree for

More information

Integer Programming ISE 418. Lecture 7. Dr. Ted Ralphs

Integer Programming ISE 418. Lecture 7. Dr. Ted Ralphs Integer Programming ISE 418 Lecture 7 Dr. Ted Ralphs ISE 418 Lecture 7 1 Reading for This Lecture Nemhauser and Wolsey Sections II.3.1, II.3.6, II.4.1, II.4.2, II.5.4 Wolsey Chapter 7 CCZ Chapter 1 Constraint

More information

Chapter 11 Search Algorithms for Discrete Optimization Problems

Chapter 11 Search Algorithms for Discrete Optimization Problems Chapter Search Algorithms for Discrete Optimization Problems (Selected slides) A. Grama, A. Gupta, G. Karypis, and V. Kumar To accompany the text Introduction to Parallel Computing, Addison Wesley, 2003.

More information

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns Pruet Boonma pruet@eng.cmu.ac.th Department of Computer Engineering Faculty of Engineering, Chiang Mai University Based on Slides by

More information

CS141: Intermediate Data Structures and Algorithms Greedy Algorithms

CS141: Intermediate Data Structures and Algorithms Greedy Algorithms CS141: Intermediate Data Structures and Algorithms Greedy Algorithms Amr Magdy Activity Selection Problem Given a set of activities S = {a 1, a 2,, a n } where each activity i has a start time s i and

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

This article appeared in a journal published by Elsevier. The attached copy is furnished to the author for internal non-commercial research and

This article appeared in a journal published by Elsevier. The attached copy is furnished to the author for internal non-commercial research and This article appeared in a journal published by Elsevier. The attached copy is furnished to the author for internal non-commercial research and education use, including for instruction at the authors institution

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

Chapter 27 Cluster Work Queues

Chapter 27 Cluster Work Queues Chapter 27 Cluster Work Queues Part I. Preliminaries Part II. Tightly Coupled Multicore Part III. Loosely Coupled Cluster Chapter 18. Massively Parallel Chapter 19. Hybrid Parallel Chapter 20. Tuple Space

More information

IV/IV B.Tech (Regular) DEGREE EXAMINATION. Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation

IV/IV B.Tech (Regular) DEGREE EXAMINATION. Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation IV/IV B.Tech (Regular) DEGREE EXAMINATION Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation Maximum: 60 Marks 1. Write briefly about the following 1*12= 12 Marks a) Give the characteristics

More information

Solving a Challenging Quadratic 3D Assignment Problem

Solving a Challenging Quadratic 3D Assignment Problem Solving a Challenging Quadratic 3D Assignment Problem Hans Mittelmann Arizona State University Domenico Salvagnin DEI - University of Padova Quadratic 3D Assignment Problem Quadratic 3D Assignment Problem

More information

Chapter 17 Parallel Work Queues

Chapter 17 Parallel Work Queues Chapter 17 Parallel Work Queues Part I. Preliminaries Part II. Tightly Coupled Multicore Chapter 6. Parallel Loops Chapter 7. Parallel Loop Schedules Chapter 8. Parallel Reduction Chapter 9. Reduction

More information

Divide-and-Conquer. Divide-and conquer is a general algorithm design paradigm:

Divide-and-Conquer. Divide-and conquer is a general algorithm design paradigm: Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9

More information

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms Analysis of Algorithms Unit 4 - Analysis of well known Algorithms 1 Analysis of well known Algorithms Brute Force Algorithms Greedy Algorithms Divide and Conquer Algorithms Decrease and Conquer Algorithms

More information

What is Learning? CS 343: Artificial Intelligence Machine Learning. Raymond J. Mooney. Problem Solving / Planning / Control.

What is Learning? CS 343: Artificial Intelligence Machine Learning. Raymond J. Mooney. Problem Solving / Planning / Control. What is Learning? CS 343: Artificial Intelligence Machine Learning Herbert Simon: Learning is any process by which a system improves performance from experience. What is the task? Classification Problem

More information

Subset sum problem and dynamic programming

Subset sum problem and dynamic programming Lecture Notes: Dynamic programming We will discuss the subset sum problem (introduced last time), and introduce the main idea of dynamic programming. We illustrate it further using a variant of the so-called

More information

Chapter 6 Parallel Loops

Chapter 6 Parallel Loops Chapter 6 Parallel Loops Part I. Preliminaries Part II. Tightly Coupled Multicore Chapter 6. Parallel Loops Chapter 7. Parallel Loop Schedules Chapter 8. Parallel Reduction Chapter 9. Reduction Variables

More information

Improving Packing Algorithms for Server Consolidation

Improving Packing Algorithms for Server Consolidation Improving Packing Algorithms for Server Consolidation YASUHIRO A JIRO, ATSUHIRO TANAKA SYSTEM PLATFORMS RESEARCH LABORATORIES, NEC CORPORATION PRESENTED BY : BASIL ALHAKAMI Content Introduction. Background

More information

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1 CSE 0 Name Test Fall 00 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each t. What is the value of k? k=0 A. k B. t C. t+ D. t+ +. Suppose that you have

More information

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each CSE 0-00 Test Spring 0 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose f ( x) is a monotonically increasing function. Which of the

More information

CSE 591: GPU Programming. Using CUDA in Practice. Klaus Mueller. Computer Science Department Stony Brook University

CSE 591: GPU Programming. Using CUDA in Practice. Klaus Mueller. Computer Science Department Stony Brook University CSE 591: GPU Programming Using CUDA in Practice Klaus Mueller Computer Science Department Stony Brook University Code examples from Shane Cook CUDA Programming Related to: score boarding load and store

More information

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

( ) + n. ( ) = n 1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1 CSE 0 Name Test Summer 00 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose you are sorting millions of keys that consist of three decimal

More information

Methods and Models for Combinatorial Optimization Exact methods for the Traveling Salesman Problem

Methods and Models for Combinatorial Optimization Exact methods for the Traveling Salesman Problem Methods and Models for Combinatorial Optimization Exact methods for the Traveling Salesman Problem L. De Giovanni M. Di Summa The Traveling Salesman Problem (TSP) is an optimization problem on a directed

More information

EECS 571 Principles of Real-Time Embedded Systems. Lecture Note #8: Task Assignment and Scheduling on Multiprocessor Systems

EECS 571 Principles of Real-Time Embedded Systems. Lecture Note #8: Task Assignment and Scheduling on Multiprocessor Systems EECS 571 Principles of Real-Time Embedded Systems Lecture Note #8: Task Assignment and Scheduling on Multiprocessor Systems Kang G. Shin EECS Department University of Michigan What Have We Done So Far?

More information

Solving a Challenging Quadratic 3D Assignment Problem

Solving a Challenging Quadratic 3D Assignment Problem Solving a Challenging Quadratic 3D Assignment Problem Hans Mittelmann Arizona State University Domenico Salvagnin DEI - University of Padova Quadratic 3D Assignment Problem Quadratic 3D Assignment Problem

More information

FINAL EXAM SOLUTIONS

FINAL EXAM SOLUTIONS COMP/MATH 3804 Design and Analysis of Algorithms I Fall 2015 FINAL EXAM SOLUTIONS Question 1 (12%). Modify Euclid s algorithm as follows. function Newclid(a,b) if a

More information

3 No-Wait Job Shops with Variable Processing Times

3 No-Wait Job Shops with Variable Processing Times 3 No-Wait Job Shops with Variable Processing Times In this chapter we assume that, on top of the classical no-wait job shop setting, we are given a set of processing times for each operation. We may select

More information

Parallel Systems. Project topics

Parallel Systems. Project topics Parallel Systems Project topics 2016-2017 1. Scheduling Scheduling is a common problem which however is NP-complete, so that we are never sure about the optimality of the solution. Parallelisation is a

More information

CS 445: Data Structures Final Examination: Study Guide

CS 445: Data Structures Final Examination: Study Guide CS 445: Data Structures Final Examination: Study Guide Java prerequisites Classes, objects, and references Access modifiers Arguments and parameters Garbage collection Self-test questions: Appendix C Designing

More information

CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS

CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks UNIT-I 1. Define Algorithm. An algorithm is a sequence of unambiguous instructions for solving a problem in a finite amount of time. 2.Write a short note

More information

PRAM Divide and Conquer Algorithms

PRAM Divide and Conquer Algorithms PRAM Divide and Conquer Algorithms (Chapter Five) Introduction: Really three fundamental operations: Divide is the partitioning process Conquer the the process of (eventually) solving the eventual base

More information

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο CSE 220 Name Test Fall 20 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 4 points each. The time to compute the sum of the n elements of an integer array is in:

More information

A Fast GPU-Based Approach to Branchless Distance-Driven Projection and Back-Projection in Cone Beam CT

A Fast GPU-Based Approach to Branchless Distance-Driven Projection and Back-Projection in Cone Beam CT A Fast GPU-Based Approach to Branchless Distance-Driven Projection and Back-Projection in Cone Beam CT Daniel Schlifske ab and Henry Medeiros a a Marquette University, 1250 W Wisconsin Ave, Milwaukee,

More information

Algorithms for Integer Programming

Algorithms for Integer Programming Algorithms for Integer Programming Laura Galli November 9, 2016 Unlike linear programming problems, integer programming problems are very difficult to solve. In fact, no efficient general algorithm is

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 29 Approximation Algorithms Load Balancing Weighted Vertex Cover Reminder: Fill out SRTEs online Don t forget to click submit Sofya Raskhodnikova 12/7/2016 Approximation

More information

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa. Code No: RR210504 Set No. 1 1. (a) Order the following functions according to their order of growth (from the lowest to the highest). (n-2)!, 5 log (n+100) 10,2 2n, 0.001n 4 +3n 3 +1, ln 2 n, n 1/3, 3

More information

A Batched GPU Algorithm for Set Intersection

A Batched GPU Algorithm for Set Intersection A Batched GPU Algorithm for Set Intersection Di Wu, Fan Zhang, Naiyong Ao, Fang Wang, Xiaoguang Liu, Gang Wang Nankai-Baidu Joint Lab, College of Information Technical Science, Nankai University Weijin

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

Algorithm Design Techniques (III)

Algorithm Design Techniques (III) Algorithm Design Techniques (III) Minimax. Alpha-Beta Pruning. Search Tree Strategies (backtracking revisited, branch and bound). Local Search. DSA - lecture 10 - T.U.Cluj-Napoca - M. Joldos 1 Tic-Tac-Toe

More information

Leveraging Set Relations in Exact Set Similarity Join

Leveraging Set Relations in Exact Set Similarity Join Leveraging Set Relations in Exact Set Similarity Join Xubo Wang, Lu Qin, Xuemin Lin, Ying Zhang, and Lijun Chang University of New South Wales, Australia University of Technology Sydney, Australia {xwang,lxue,ljchang}@cse.unsw.edu.au,

More information

6. Algorithm Design Techniques

6. Algorithm Design Techniques 6. Algorithm Design Techniques 6. Algorithm Design Techniques 6.1 Greedy algorithms 6.2 Divide and conquer 6.3 Dynamic Programming 6.4 Randomized Algorithms 6.5 Backtracking Algorithms Malek Mouhoub, CS340

More information

15.083J Integer Programming and Combinatorial Optimization Fall Enumerative Methods

15.083J Integer Programming and Combinatorial Optimization Fall Enumerative Methods 5.8J Integer Programming and Combinatorial Optimization Fall 9 A knapsack problem Enumerative Methods Let s focus on maximization integer linear programs with only binary variables For example: a knapsack

More information

( D. Θ n. ( ) f n ( ) D. Ο%

( D. Θ n. ( ) f n ( ) D. Ο% CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j

More information

G205 Fundamentals of Computer Engineering. CLASS 21, Mon. Nov Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm

G205 Fundamentals of Computer Engineering. CLASS 21, Mon. Nov Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm G205 Fundamentals of Computer Engineering CLASS 21, Mon. Nov. 22 2004 Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm Greedy Algorithms, 1 Algorithms for Optimization Problems Sequence of steps Choices at

More information

Local search heuristic for multiple knapsack problem

Local search heuristic for multiple knapsack problem International Journal of Intelligent Information Systems 2015; 4(2): 35-39 Published online February 14, 2015 (http://www.sciencepublishinggroup.com/j/ijiis) doi: 10.11648/j.ijiis.20150402.11 ISSN: 2328-7675

More information

Complementary Graph Coloring

Complementary Graph Coloring International Journal of Computer (IJC) ISSN 2307-4523 (Print & Online) Global Society of Scientific Research and Researchers http://ijcjournal.org/ Complementary Graph Coloring Mohamed Al-Ibrahim a*,

More information

Analysis of Algorithms Prof. Karen Daniels

Analysis of Algorithms Prof. Karen Daniels UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 2 Tuesday, 2/2/10 Design Patterns for Optimization Problems Greedy Algorithms Algorithmic Paradigm Context

More information

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Spring 2010 Review Topics Big O Notation Heaps Sorting Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Hashtables Tree Balancing: AVL trees and DSW algorithm Graphs: Basic terminology and

More information

[ DATA STRUCTURES] to Data Structures

[ DATA STRUCTURES] to Data Structures [ DATA STRUCTURES] Chapter - 01 : Introduction to Data Structures INTRODUCTION TO DATA STRUCTURES A Data type refers to a named group of data which share similar properties or characteristics and which

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION Chendu College of Engineering & Technology (Approved by AICTE, New Delhi and Affiliated to Anna University) Zamin Endathur, Madurantakam, Kancheepuram District 603311 +91-44-27540091/92 www.ccet.org.in

More information