| title | ELI5: Big O |
|---|---|
| author | Sarah Lim |
| date | 24 April 2016 (edited 23 April 2017) |
To measure an algorithm's efficiency, one intuitive idea is to consider the amount of time it takes to solve a problem (transform the input into the desired output).
| #![allow(dead_code)] | |
| extern crate rand; | |
| use rand::Rng; | |
| use std::sync::{Arc, Mutex}; | |
| // use std::time::Duration; | |
| use std::thread; | |
| use std::sync::mpsc; | |
| fn partition(arr: &mut [i32]) -> usize { |
Sarah Lim (slim at u.northwestern.edu)
Last updated 24 April 2016
To measure an algorithm's efficiency, one intuitive idea is to consider the amount of time it takes to solve a problem (transform the input into the desired output).
Unfortunately, it's difficult to measure the exact runtime of an algorithm. In practice, runtimes are influenced by a lot of factors unrelated to the algorithm itself. For instance, the same function might run quickly on a state-of-the-art gaming PC, and much more slowly on an ancient Windows 98 machine.
| use std::sync::{Arc, Mutex}; | |
| use std::thread; | |
| use std::sync::mpsc; | |
| fn main() { | |
| let v = vec![1, 2]; | |
| println!("{:?}", v.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" ")); | |
| let mut iter = (0..4).zip((0..6)); | |
| for (x, y) in iter { |
| struct Tree<'a> { | |
| pawns: Vec<usize>, | |
| rolls: Vec<usize>, | |
| pawns_iter: std::slice::Iter<'a, usize>, | |
| rolls_iter: std::slice::Iter<'a, usize>, | |
| } | |
| impl<'a> Tree<'a> { | |
| fn new(pawns: Vec<usize>, rolls: Vec<usize>) -> Tree<'a> { | |
| Tree { |
| // http://loremipsumgenerator.com | |
| // in an extension background script | |
| // endpoint.target is the current debugging target | |
| // triggers 'Aw, Snap' | |
| chrome.debugger.sendCommand(endpoint.target, 'DOM.getDocument', {}, ({ root }) => { | |
| chrome.debugger.sendCommand(endpoint.target, 'DOM.querySelector', { nodeId: root.nodeId, selector: 'footer' }, ({ nodeId }) => { | |
| chrome.debugger.sendCommand(endpoint.target, 'CSS.getMatchedStylesForNode', { nodeId: nodeId }, (styles) => { | |
| console.log(styles); | |
| }); |
Sarah Lim (http://sarahlim.com/eecs-111)
In most countries, the age of majority is 18. Some countries have different laws. In Scotland, for instance, the age of majority is 16.
Suppose we want to write a program to determine whether someone is a legal adult. We'll write a global version that works for most countries, and a Scotland-specific version.
This README provides general instructions for installing Node.js and npm ecosystem projects from GitHub.
Many project READMEs assume a baseline level of user knowledge, but the following "Getting Started" section isn't very helpful to an absolute beginner:
npm install
| Argument | Example | Notes |
|---|---|---|
cmd |
['python', '-m', '$project'] |
Required if shell_cmd is empty; overridden by shell_cmd; searched in PATH |
shell_cmd |
yarn build |
Required if cmd is empty; overrides cmd |
working_dir |
?? | Temporarily change to directory before executing cmd |
env |
{ EDITOR: 'vim' }? |
Can merge in a dictionary before passing to cmd; expands environment variables. |
shell |
true |
Runs cmd through the shell if true; noop if shell_cmd is used |
path |
/User/sarah/git |
Used by cmd; expands environment variables. |
| \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$} | |
| $if(beamerarticle)$ | |
| \usepackage{beamerarticle} % needs to be loaded first | |
| $endif$ | |
| $if(fontfamily)$ | |
| \usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$} | |
| $else$ | |
| \usepackage{lmodern} | |
| $endif$ | |
| $if(linestretch)$ |