Free Essay

Greedy Algorithm

In:

Submitted By esomac
Words 387
Pages 2
GREEDY ALGORITHM
A greedy algorithm is a mathematical process that looks for simple, easy-to-implement solutions to complex, multi-step problems by deciding which next step will provide the most obvious benefit.
Greedy algorithms are similar to dynamic programming algorithms in that the solutions are both efficient and optimal if the problem exhibits some particular sort of substructure. A greedy algorithm builds a solution by going one step at a time through the feasible solutions, applying a heuristic to determine the best choice. A heuristic applies an insight to solving the problem, such as always choose the largest, smallest, etc.
Such algorithms are called greedy because while the optimal solution to each smaller instance will provide an immediate output, the algorithm doesn’t consider the larger problem as a whole. Once a decision has been made, it is never reconsidered.
Greedy algorithms work by recursively constructing a set of objects from the smallest possible constituent parts. Recursion is an approach to problem solving in which the solution to a particular problem depends on solutions to smaller instances of the same problem.
Advantages of greed algorithm * Always taking the best available choice is usually easy. * It usually requires sorting the choices. * Solutions to smaller instances of the problem can be straightforward and easy to understand. * Repeatedly taking the next available best choice is usually linear work. * But don't forget the cost of sorting the choices. * Much cheaper than exhaustive search. * Much cheaper than most other algorithms.
Disadvantages of greed algorithm * Greedy algorithms don't work for some problems. * Despite their simplicity, correct greedy algorithms can be subtle. * It's easy to fool yourself into believing an incorrect greedy algorithm is correct. * Using greed is not an automatic. * It is entirely possible that the most optimal short-term solutions may lead to the worst possible long-term outcome.
Application of greedy algorithm
The technique is used in the following graph algorithms which have many practical applications: 1. Dijkstra's algorithm for finding shortest path to all nodes given a start node.
2. Prim's algorithm for finding a minimum spanning tree.
3. Huffman trees for data compression.

 Greedy Algorithms, Chapter 17 in Introduction to Algorithms by Thomas Cormen, Charles Leiserson, and Ronald Rivest, MIT Press, 1999.
 Greedy Algorithms, Chapter 5 in Algorithms by Sanjoy Dasgupta, Christos Papadimitriou, and Umesh Vizirani, McGraw-Hill, 2008

Similar Documents

Free Essay

Introduction to Algorithm

...4. G REEDY A LGORITHMS I ‣ coin changing ‣ interval scheduling ‣ scheduling to minimize lateness ‣ optimal caching Lecture slides by Kevin Wayne Copyright © 2005 Pearson-Addison Wesley Copyright © 2013 Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on Sep 8, 2013 6:30 AM 4. G REEDY A LGORITHMS I ‣ coin changing ‣ interval scheduling ‣ scheduling to minimize lateness ‣ optimal caching Coin changing Goal. Given currency denominations: 1, 5, 10, 25, 100, devise a method to pay amount to customer using fewest number of coins. Ex. 34¢. Cashier's algorithm. At each iteration, add coin of the largest value that does not take us past the amount to be paid. Ex. $2.89. 3 Cashier's algorithm At each iteration, add coin of the largest value that does not take us past the amount to be paid. CASHIERS-ALGORITHM (x, c1, c2, …, cn)...

Words: 3591 - Pages: 15

Premium Essay

It- 3rd Year

...E-COMMERCE (TIT-501) UNIT I Introduction What is E-Commerce, Forces behind E-Commerce Industry Framework, Brief history of ECommerce, Inter Organizational E-Commerce Intra Organizational E-Commerce, and Consumer to Business Electronic Commerce, Architectural framework Network Infrastructure for E-Commerce Network Infrastructure for E-Commerce, Market forces behind I Way, Component of I way Access Equipment, Global Information Distribution Network, Broad band Telecommunication. UNIT-II Mobile Commerce Introduction to Mobile Commerce, Mobile Computing Application, Wireless Application Protocols, WAP Technology, Mobile Information Devices, Web Security Introduction to Web security, Firewalls & Transaction Security, Client Server Network, Emerging Client Server Security Threats, firewalls & Network Security. UNIT-III Encryption World Wide Web & Security, Encryption, Transaction security, Secret Key Encryption, Public Key Encryption, Virtual Private Network (VPM), Implementation Management Issues. UNIT - IV Electronic Payments Overview of Electronics payments, Digital Token based Electronics payment System, Smart Cards, Credit Card I Debit Card based EPS, Emerging financial Instruments, Home Banking, Online Banking. UNIT-V Net Commerce EDA, EDI Application in Business, Legal requirement in E -Commerce, Introduction to supply Chain Management, CRM, issues in Customer Relationship Management. References: 1. Greenstein and Feinman, “E-Commerce”, TMH 2. Ravi Kalakota, Andrew Whinston...

Words: 2913 - Pages: 12

Premium Essay

Design of Modern Hueristics

...Natural Computing Series Series Editors: G. Rozenberg Th. Bäck A.E. Eiben J.N. Kok H.P. Spaink Leiden Center for Natural Computing Advisory Board: S. Amari G. Brassard K.A. De Jong C.C.A.M. Gielen T. Head L. Kari L. Landweber T. Martinetz Z. Michalewicz M.C. Mozer E. Oja G. P˘ un J. Reif H. Rubin A. Salomaa M. Schoenauer H.-P. Schwefel C. Torras a D. Whitley E. Winfree J.M. Zurada For further volumes: www.springer.com/series/4190 Franz Rothlauf Design of Modern Heuristics Principles and Application Prof. Dr. Franz Rothlauf Chair of Information Systems and Business Administration Johannes Gutenberg Universität Mainz Gutenberg School of Management and Economics Jakob-Welder-Weg 9 55099 Mainz Germany rothlauf@uni-mainz.de Series Editors G. Rozenberg (Managing Editor) rozenber@liacs.nl Th. Bäck, J.N. Kok, H.P. Spaink Leiden Center for Natural Computing Leiden University Niels Bohrweg 1 2333 CA Leiden, The Netherlands A.E. Eiben Vrije Universiteit Amsterdam The Netherlands ISSN 1619-7127 Natural Computing Series ISBN 978-3-540-72961-7 e-ISBN 978-3-540-72962-4 DOI 10.1007/978-3-540-72962-4 Springer Heidelberg Dordrecht London New York Library of Congress Control Number: 2011934137 ACM Computing Classification (1998): I.2.8, G.1.6, H.4.2 © Springer-Verlag Berlin Heidelberg 2011 This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations...

Words: 114592 - Pages: 459

Premium Essay

North West

...A Library of Local Search Heuristics for the Vehicle Routing Problem Chris Gro¨r1 e Oak Ridge National Laboratory, 1 Bethel Valley Rd, Oak Ridge, TN 37831 cgroer@gmail.com Bruce Golden R.H. Smith School of Business, University of Maryland, College Park, MD 20742, USA, bgolden@rhsmith.umd.edu Edward Wasil2 Kogod School of Business, American University, Washington, DC 20016, USA, ewasil@american.edu The vehicle routing problem (VRP) is a difficult and well-studied combinatorial optimization problem. Real-world instances of the VRP can contain hundreds and even thousands of customer locations and can involve many complicating constraints, necessitating the use of heuristic methods. We present a software library of local search heuristics that allow one to quickly generate solutions to VRP instances. The code has a logical, object-oriented design and uses efficient data structures to store and modify solutions. The core of the library is the implementation of seven local search operators that share a similar interface and are designed to be extended to handle additional options with minimal code change. The code is well-documented, straightforward to compile, and is freely available online. The code contains several applications that can be used to generate solutions to the capacitated VRP. Computational results indicate that these applications are able to generate solutions that are within about one percent of the best-known solution on benchmark problems. Key words: vehicle routing;...

Words: 10780 - Pages: 44

Free Essay

Ds Java

...A Practical Introduction to Data Structures and Algorithm Analysis Third Edition (Java) Clifford A. Shaffer Department of Computer Science Virginia Tech Blacksburg, VA 24061 April 16, 2009 Copyright c 2008 by Clifford A. Shaffer. This document is the draft of a book to be published by Prentice Hall and may not be duplicated without the express written consent of either the author or a representative of the publisher. Contents Preface xiii I Preliminaries 1 1 Data Structures and Algorithms 1.1 A Philosophy of Data Structures 1.1.1 The Need for Data Structures 1.1.2 Costs and Benefits 1.2 Abstract Data Types and Data Structures 1.3 Design Patterns 1.3.1 Flyweight 1.3.2 Visitor 1.3.3 Composite 1.3.4 Strategy 1.4 Problems, Algorithms, and Programs 1.5 Further Reading 1.6 Exercises 3 4 4 6 8 12 13 14 15 16 17 19 21 2 Mathematical Preliminaries 2.1 Sets and Relations 2.2 Miscellaneous Notation 2.3 Logarithms 2.4 Summations and Recurrences 25 25 29 31 33 iii iv Contents 2.5 2.6 2.7 2.8 2.9 3 II 4 Recursion Mathematical Proof Techniques 2.6.1 Direct Proof 2.6.2 Proof by Contradiction 2.6.3 Proof by Mathematical Induction Estimating Further Reading Exercises Algorithm Analysis 3.1 Introduction 3.2 Best, Worst, and Average Cases 3.3 A Faster Computer, or a Faster Algorithm? 3.4 Asymptotic Analysis 3.4.1 Upper Bounds 3.4.2 Lower Bounds 3.4.3 Θ Notation 3.4.4 Simplifying...

Words: 30587 - Pages: 123

Free Essay

Innovation and Erp Systems

...Scheme and Syllabus of B.E. (Computer Science and Engineering) 3 rd th TO 8 Semester 2014-2015 University Institute of Engineering and Technology, Panjab University, Chandigarh DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING VISION: To be recognized as an international leader in Computer Science and Engineering education and research to benefit society globally. MISSION: · · · · To move forward as frontiers of human knowledge to enrich the citizen, the nation, and the world. To excel in research and innovation that discovers new knowledge and enables new technologies and systems. To develop technocrats, entrepreneurs, and business leaders of future who will strive to improve the quality of human life. To create world class computing infrastructure for the enhancement of technical knowledge in field of Computer Science and Engineering. PROGRAMME: B.E. CSE (UG PROGRAMME) PROGRAMME EDUCATIONAL OBJECTIVES: I. Graduates will work as software professional in industry of repute. II. Graduates will pursue higher studies and research in engineering and management disciplines. III. Graduates will work as entrepreneurs by establishing startups to take up projects for societal and environmental cause. PROGRAMME OUTCOMES: A. Ability to effectively apply knowledge of computing, applied sciences and mathematics to computer science & engineering problems. B. Identify, formulate, research literature, and analyze complex computer science & engineering problems reaching substantiated conclusions...

Words: 23989 - Pages: 96

Premium Essay

Syllabus

... 4. 5. 6. CSE411 CSE461 CSE412 CSE462 CSE414 CSE464 Subject Title Scheme of Teaching L 3 0 3 0 3 0 T 1 0 1 0 1 0 P 0 3 0 3 0 3 Hours 4 3 4 3 4 3 Credit 4 2 4 2 4 2 University External Marks 50 50 50 CSE361 CSE313 CSE363 AS301 EC316 EC366 EC317 EC367 Data Structures (Practical) Peripheral Devices & Interfaces Hardware Lab (Practical) Engineering Mathematics – III Digital Electronics Digital Electronics (Practical) Microprocessors Microprocessors (Practical) 0 3 0 3 3 0 3 0 15 0 1 0 1 1 0 1 0 5 3 0 2 0 0 2 0 2 09 3 4 2 4 4 2 4 2 29 2 4 1 4 4 1 4 1 25 50 50 50 50 250 Internal Total Sessional Marks 50 50 50 50 50 50 50 50 50 450 100 50 100 50 100 100 50 100 50 700 7. 8. Total ASC405 CSE 415 Analysis & Design of Algorithms Analysis & Design of Algorithms (Practical) Database Management System Database Management System (Practical) Object Oriented Programming Object Oriented Programming (Practical) Cyber Law & IPR Computer Architecture & Organization Internal Total Sessional Marks 50 100 50 50 50 50 50 50 100 50 100 50 3 3 15 0 1 4 0 0 9 3 4 28 3 4 25 50 50 250 50 50 400 100 100 650 2 Scheme of Examination of B.E. in Computer Science & Engineering Third Year - Fifth Semester Sr. Paper Subject Title Scheme of Teaching Univesity Internal Sessional Code External L T P Hou Credit Marks Total Marks rs s 1. CSE511 Operating System 3 1 0 4 4 50 50...

Words: 14784 - Pages: 60

Free Essay

Blah Blha

...MC 2014-15: PGP I/PGP-ABM I MC Individual Assignment-II Release Date: 19-8-14 Submission Date and Time 04-09-14, 6:00 PM Instructions 1. This is an individual assignment (not group). 2. You are required to develop VBA solutions to the following two problems and submit the solutions as a single xlsm file on Moodle. 3. Your solution must be as general as possible – clearly state all assumptions. The VBA code must be neat, and well documented (introducing appropriate comments) 4. Submit your assignment file on Moodle well on time to avoid system congestions or break-downs during the last minute Problem 1: Tourist spots in London As a tourist in London you want to visit 7 spots and minimize the time spent on visiting these 7 spots. The details of the 7 spots including their ID, time to see the attraction, and opening time are given to you (Range A3:D9 in given spreadsheet). Note that you want to visit each spot only once. Range B13:H19 in the given spreadsheet contains the travel time (in minutes) between any two spots, 9999 stands for infinity. For example: travel from 2 to 5 (Trafalgar Square to Tower Bridge) takes 22 minutes. You can assume that all other times (wait times for transport, queues for attractions etc, are already accounted for in the sightseeing time and travel time). The subroutine calc_schedule uses this information to calculate the route to...

Words: 1351 - Pages: 6

Free Essay

Syllabus

...SCHEME OF EXAMINATION FOR MASTER OF COMPUTER APPLICATIONS (MCA) (SIX-SEMESTER Programme) |Semester – I | |Paper |Title of the Paper |Duration |Maximum Marks |Total | |No. | |Of Exam | | | | | | |Theory |Sessional* | | |MCA-101 |Computer Fundamentals and Problem Solving Using C |3 Hours |80 |20 |100 | |MCA-102 |Computer Organisation |3 Hours |80 |20 |100 | |MCA-103 |Discrete Mathematical Structures |3 Hours |80 |20 |100 | |MCA-104 |Software Engineering |3 Hours |80 |20 |100 | |MCA-105 |Computer Oriented Numerical and Statistical Methods |3 Hours |80 |20 |100 | |MCA-106 |Software Laboratory - I |3 Hours | | |100 | | |C (Based on MCA-101) |...

Words: 13848 - Pages: 56

Premium Essay

Pt1420 Final Exam

...Final: Algorithms Spring 2016 I _(your name)____________ did not collaborate with any person on this exam. I understand that doing so will result in a 0 for the Final Exam. • You can use online references, but write answers in your own words! Cite any references used. Answer the question in your own words, no credit will be given for answers copied from any source. • No collaborating with other people; a 0 will be given if any collaboration evidence is found. Ask me for a hint if you are stuck on any particular problem. • I am looking for very specific, detailed, correct, and complete answers. • Most answers found on the Internet (especially Wikipedia) are generic answers for people without a networking background and...

Words: 1249 - Pages: 5

Free Essay

Advanced Algorithms

...Approximation Algorithms Springer Berlin Heidelberg NewYork Barcelona Hong Kong London Milan Paris Singapore Tokyo To my parents Preface Although this may seem a paradox, all exact science is dominated by the idea of approximation. Bertrand Russell (1872–1970) Most natural optimization problems, including those arising in important application areas, are NP-hard. Therefore, under the widely believed conjecture that P = NP, their exact solution is prohibitively time consuming. Charting the landscape of approximability of these problems, via polynomial time algorithms, therefore becomes a compelling subject of scientific inquiry in computer science and mathematics. This book presents the theory of approximation algorithms as it stands today. It is reasonable to expect the picture to change with time. The book is divided into three parts. In Part I we cover a combinatorial algorithms for a number of important problems, using a wide variety of algorithm design techniques. The latter may give Part I a non-cohesive appearance. However, this is to be expected – nature is very rich, and we cannot expect a few tricks to help solve the diverse collection of NP-hard problems. Indeed, in this part, we have purposely refrained from tightly categorizing algorithmic techniques so as not to trivialize matters. Instead, we have attempted to capture, as accurately as possible, the individual character of each problem, and point out connections between problems and algorithms for solving them...

Words: 140657 - Pages: 563

Premium Essay

Pdf. Input Out Files

...something what we call System Analysis and Design programmers do to understand a problem. Many diagrams including "Work Break Down Structure", "Workflow Diagram" and "Class Diagrams" are some of the most common ones are used. Question 2. What is Pseaudocode? Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. Pseudocode typically omits details that are not essential for human understanding of the algorithm, such as variable declarations, system-specific code and some subroutines. The programming language is augmented with natural language description details, where convenient, or with compact mathematical notation. The purpose of using pseudocode is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and scientific publications that are documenting various algorithms, and also in planning of computer program development, for sketching out the structure of the program before the actual coding takes place. Question 3 computer programmers normally perform what 3 steps? 1. Input is received. 2. Some process is performed on the input. 3. Output is produced. Question 4 What does user friendly mean? 2. user friendly"...

Words: 330 - Pages: 2

Free Essay

Initial Sizing of an Airplane

...CONSTRAINT ANALYSIS The two parameters (i) wing loading and (ii) power loading are the most important parameters that affect the airframe design and its performance. Wing loading and power loading are interconnected for a number of design parameters and because of this interconnection it is difficult to use historical data to independently select these values. Hence a different approach needs to be followed. The team decided to use sizing matrix plots to find the optimum value of the two parameters. For calculating the optimum values, the most important design requirements must be decided. The design requirements that have the highest weightage are: (i) (ii) (iii) (iv) Stall speed Take off distance Landing distance Sustained turn All the above design requirements were written in terms of wing loading and power loading. Since in the design requirements parameters are given in the inequality form, hence a region of point is obtained instead of single point of intersection. This region of favorable points is known as design space. On putting values of all parameters and then plotting in matlab, design space is obtained. The code for plotting the sizing matrix plot is given in Appendix A(a). In the design space the optimum design point is obtained by calculating the score of the point based on its weightage. (The weightage of various design parameters is given in Appendix A(b). REGRESSION ANALYSIS A regression analysis was done to find out the statistical relation between...

Words: 582 - Pages: 3

Premium Essay

Cause and Effect of Computer Revolution

...ENC 1101 February 13 2013 Causes and Effects of the Computer/Information Revolution By illustrating the lifestyle of the computer revolution through advancements in human society whether it be medicine, school or businesses, computers paints a vivid image of a world that is interconnected providing further advancement upon our society; only to create a bigger, faster and more efficient world. The 21st century is known as the information and or computer revolution. As Hamming states, "the industrial revolution released man from being a beast of burden; computer revolution will similarly release him from slavery to dull, repetitive routine" (Hamming 4). The revolution began after World War II and to this day continues evolving at a rapid pace enhancements made to it’s speed and size, has led to more and more information being found and processed on a daily basis.  According to Linowes, more information has been produced in the last thirty years than in the previous five thousand. Changes to the lifestyle of the everyday human are quite prevalent. Nowadays, people have access to what seems to be an endless pool of information, whether it is social networks, instant messaging, electronic libraries while businesses use the internet and information technology to operate their organizations. People communicate every day and transfer data every day at an alarming rate. The computer revolution has shaped or current environment into one where the internet is central to todays society...

Words: 1488 - Pages: 6

Free Essay

How to Write a Computer Program

...need to determine how you are going to take your input information and turn it into your output information. An example problem is that you want to determine the price of items before and after tax. Your inputs would be: the price of the item, expressed as ItemPrice; the amount of tax, expressed as TaxRate; and the amount of that item, expressed as ItemQuantity. The output would then be the amount of the item before and after tax has been included, expressed as OriginalPrice and TaxPrice respectively. One way to solve this would be to use the following equations: ItemPrice * ItemQuantity = OriginalPrice and then OriginalPrice * TaxRate + OriginalPrice = TaxPrice. Once the problem has been analyzed, the variables identified, and the algorithm has been determined, it is time to design the program. Designing the program is no more than creating a set of step by step instructions,...

Words: 1031 - Pages: 5