0% found this document useful (0 votes)
10 views2 pages

Algorithms

Algorithm notes

Uploaded by

John Irving
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Algorithms

Algorithm notes

Uploaded by

John Irving
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Algorithms

An algorithm is a finite sequence of well-difined, comuper-implementable


instructions:
Defined: there is a specific sequence of steps that performs a task
Unambiguous: there is a "correct"and 'incorrect' interpretation of the steps.
Implementable: it can be executed using software and hardware.

Algorithms are typically written in pseudocode, as algorithms are high-level


description of a solution to a problem. Language used does not matter.
ex) 1. Start with an original string called "S" and a new empty string called
"R."
2. Loop through "S" from its last character to its first character, and
for each one, add it to the end of "R."
3. Once you've processed all the characters, return "R."

Big O Notation:
Big O is a characterization of algorithms accorfing to their worst-case
growth rates.
They are written "0(Formula)"
Formula above describes how an algorithm's run time or space requirements gor
as the input size grows:
0(1) - constant
0(n) - linear
0(n^2) - squared
0(2^n) - exponential
0(n!) - factorial

If two variables are important/useful to track seperatley, the notation may


be written differently.
ex) O(nm) is essentially identical to O(n^2), but makes it clear that
the two variables are important to track seperately.

Constants don't matter as Big-O notation only describes the theoretical


growth rate of algorithms.

Sorting:
Quick sort is an efficient, widely used divide-and-conquer algorithm.
It divides by selecting a pivot (ideally one that will end up toward the
center of the sorted pack)
moves everything into either the less than or greater than side of
pivot
when the pivot is in its final position it recursively calls it self on
either side of the pivot.

While some quick sorts will perform at O(n*log(n)) speeds, if the list is
already sorted it will slow down to O(n^2).
This can be solved by randomizing the list before running the sort.
Another aproachg is to use the median of beginning, middle, and end of
each partition, as the pivot.

Quick sort is very fast and low in resource overhead, but is unstable,
recursive, and will perform poorly with a poorly selected pivot.

Algorithms can be sorted into two categories: Polynomial time and exponential time.
An algorithm grows in polynomial time if its runtime does not grow faster
than n^k where k is any constant.
ex) O(n^2), O(n^3), O(n*log(n))
Exponential time algorithms are generally too slow to be useful (except in
cryptography et c. )

Polynomial time is represented by "P".


Problems that fall under P are practical to solve on computers
Problems that don't are hard, slow, and impractical.

P: Problems that can be solved quickly (in polynomial time).


NP: Problems for which a given solution can be verified quickly, even if
finding that solution from scratch may not be quick.

Some, but not all problems in NP are also NP-complete.

A problem in NP is also NP-complete if every other problem in NP can be


reduced to it in polynomial time.

Any problem, let's call it Problem A, can be reduced to a different problem


which is already solved, Problem B, if there is an algorithm (called a reducer)
that turns an algorithm that solved Problem B into an algorithm that will solve
Problem A.

Algorithm to solve B -> reducer -> Algorithm to solve A

However, the reducer itself needs to be fast. "Problem A is reducible to


Problem B" if the reducer can run in polynomial time.

A problem is NP-hard if every problem in NP can be reduced into it in


polynomial time.

A problem is NP-complete if it is in NP and every other problem in NP can be


reduced into it in polynomial time.

P: This is the set of decision problems (problems with yes/no answers) that can
be solved quickly (in polynomial time) by a deterministic machine.

NP: This refers to decision problems where, given a "yes" answer, that solution
can be verified quickly (again, in polynomial time), even if finding the solution
isn't necessarily fast.

NP-hard: These problems are at least as hard as the hardest problems in NP.
Interestingly, solving an NP-hard problem quickly means you could quickly solve all
NP problems, but they aren't necessarily verifiable quickly.

NP-complete: These are the problems that are both in NP and as hard as any
problem in NP. An efficient solution for one NP-complete problem would solve all NP
problems efficiently.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy