Git Product home page Git Product logo

intro-to-algorithms's Introduction

Intro-to-Algorithms

Access Code 2.2 - Algorithms Cheat Sheet

Summarization and Examples of algorithms taken from: http://www.scifac.ru.ac.za/javabook/ch02.htm

An algorithm is a set of rules that can be obeyed to solve a problem. Here are some simple restrictions on algorithms:

  • The set of rules must be finite.
  • The rules must be followed in some definite sequence, until a satisfactory result is achieved.
  • The rules must cover any awkward situations that arise.
  • Only one rule may be obeyed (that is, only one operation may be performed) at a time.

Now that the fundamentals are out of the way, Let's take a look at an exanple of a basic problem and how we would create an algorithm that solves it using our definition.

###Example Problem: How does one get to see the film "Quantum of Solace"?

Let's start by creating a list of steps that we would take to solve this sepcific problem.

####Solution:

	Go to the cinema
	Buy a ticket
	Watch the film
	Go home again

We have just created an algorithm to solve our problem.

However, often times when coming up with an algorithm as a solution to a problem, we need to also put in checks that test certain cases that we think might arise frequently. For example, how would our algorithm change if we took into account the possibility that for whatever reason the film "Quantum of Solace" was not showing at the cinema?

Let's take a look at an example of a more complete algorithm, which takes into account a couple of test cases, that can be applied to the same problem.

####Solution with Test Cases

begin  // Algorithm for going to see the film "Quantum of Solace"
      if "Quantum of Solace" is not showing
        then
          find something else to do
        else
          go to the cinema
          if there is a queue
            then
              join it at the back
              repeat
                shuffle forward
              until everyone in front of you has been served
          if seats are still available
            then
              buy a ticket
              find the corresponding seat and sit down in it
              repeat
                gaze at the screen and listen to the soundtrack
              until the film is over
            else
              mutter quietly
          leave the cinema
          go home again
    end.

intro-to-algorithms's People

Contributors

pinnockf avatar

Watchers

Mike Kavouras avatar James Cloos avatar Alex Qin avatar  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.