Faiza1987 / example-algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example Algorithms

In this repository we have a series of example algorithms to look at.

example1.rb

Take a look at the code sample given?

Answer the following:

  • What type of algorithm is this?
  • What is it doing?
  • What is the time complexity of this algorithm?

Example 2 Job Sequencing Program

Given an array of jobs where every job has a deadline, the number of steps by which the job is due, and associated profit if the job is finished before the deadline. It is also given that every job takes single unit of time, so the minimum possible deadline for any job is 1.

How can we maximize total profit if only one job can be scheduled at a time.

This program solves this problem. Examine the code and walk through how it works.

Answer the following:

  • What type of algorithm is this?
  • Does this solve the problem in the most optimal way?
  • What is the time complexity of this solution?

Example 3 - Unique Paths

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?

grid image

Note: m and n will be at most 100.

Example 1:

Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right

Example 2:

Input: m = 7, n = 3
Output: 28

With your neighbor, come up with a pseudocode to solve this problem.

  • What type of algorithm did you come up with?
  • What is the time complexity of your algorithm?

About


Languages

Language:Ruby 100.0%