Code Monkey home page Code Monkey logo

greedy-algorithms's Introduction

Greedy-Algorithms

This C++ source code implements a greedy algorithm for making change using coins of different denominations. The makeChange() function takes an integer amount representing the amount of money to make change for and a vector coins representing the denominations of available coins. It returns a vector containing the coins used to make the change.

The function starts by sorting the coins vector in descending order to ensure that the largest coins are considered first. Then, it iterates through the sorted coins and, for each coin, it repeatedly adds the coin to the result vector until the remaining amount is less than the value of the current coin.

In the main() function, an example is provided where we want to make change for 67 cents using coins with denominations of 25, 10, 5, and 1 cents. The makeChange() function is called with these inputs, and the result is printed to the console, showing the coins used to make the change.

The documentation provided above describes the process of making change for 67 cents using the greedy algorithm implemented in the code. It explains each step of the algorithm and notes that while the greedy algorithm finds a solution in this case, it may not always produce the optimal solution for every problem.

greedy-algorithms's People

Contributors

svetlanasieber avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.