GithubHelp home page GithubHelp logo

algo-datastructures-course's Introduction

Algorithms and Data Structures master class Notes:

BIG O Notation:

Objectives:

- Motivate the need for something like Big O Notation
- Describe what Big O Notation is
- Simplify Big O Expressions
- Define "Time Compleixty" and "Space Complexity"
- Evalutate time complexity and space compexity  on different algoritms using Big O Notation
- Describe what a logarithm is.

What is the idea here?

How will we know what is best to use? Imagine we have several solutions to a problem.  EX: One uses a loop the other uses a list
BIG o helps us determines which solution is best based on time and space.


Example question: 
Write a funciton that accepts a given string and returns a reversed version of that string?

We could use several different solutions and big o helps us decide which one is better than another. It will provide a numerical value to how it:

Who Cares?
    Shouldn't it only matter that the code works? depends on hte project but really the yes it does because one implementation may save an hour over another:

    - Its important to have a precise vocab to talk about how aour code prefomrs
    - Usefule for disucssing trade-offs between different approaches
    - when your code slows down or crashes, identifying parts of the code that are inefficient cna help us find pain points in our applications.
    - it comes up in interviews quite a bit!

- An Example:
Suppose we want to write a funciton taht calculates the sum of all numbers from 1 up to (and including) some number n.
(index.js - ln 1 - 14 )

``` 
const addUpTo = (n) => {
// simplest solution a cumulator
let total = 0
for (let i = 0; i <= n; i++){
    total += i
}
console.log(total)
}

addUpTo(3)

const addUpToTwo = (n) =>{
retrun n* (n + 1)/2
}
```

What doees beter mean?
- ist it faster?
- does it take less memory?
- is it esaier to read?

Right now  we are going to focus on faster and less memory intensive - this also casues a little bit of a sacrifcie for readability.

How will we evaluate Speed?
by using built in timer functions ex:
```
let t1 = preformance.now()
addUpTo(10000000)
let t2 = prefomrance.now()
console.log(`Time Elapsed: ${(t2-t1) / 1000} seconds.`)
```

This process isnt very reilable as we have to add track this ourselves.

The problem with time:
- Different machines will record different times
- The same machine will record different times
- For fast algorithims speed measurements may not be precise enough.

algo-datastructures-course's People

Contributors

kmarks2013 avatar

Watchers

 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.