0% found this document useful (0 votes)
171 views4 pages

Algorithm and Process Algorithm Process

The document provides definitions and explanations of key concepts related to algorithms and data structures. It defines algorithms and processes, discusses complexity classes like P and NP, and describes common data structures and their properties including trees, heaps, graphs, stacks, queues, and lists. It also covers algorithm analysis techniques like asymptotic notation, recurrence relations, and divide-and-conquer strategies.

Uploaded by

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

Algorithm and Process Algorithm Process

The document provides definitions and explanations of key concepts related to algorithms and data structures. It defines algorithms and processes, discusses complexity classes like P and NP, and describes common data structures and their properties including trees, heaps, graphs, stacks, queues, and lists. It also covers algorithm analysis techniques like asymptotic notation, recurrence relations, and divide-and-conquer strategies.

Uploaded by

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

lOMoARcPSD|7981319

FIT1045

Algorithm and Process
Algorithm Process
A finite sequence of steps for A sequence of steps for problem
Definition
problem solving solving
Finiteness Infiniteness (not in syllabus)
Difference Þ The code must terminate after Þ The code does not have to
finite steps terminate
1. Definiteness
Þ Each step must be precise and unambiguous
2. Input
Þ Zero or more
Similarities
3. Output
Þ One or more
4. Effectiveness
Each step must be simple and can be done in a finite time

Definitions
A path that passes through every vertex exactly once
Hamiltonian Cycle
and returns back to the start
O: A subset of vertices such that every edge in the graph
has at least one vertex
Vertex Cover
S: A subset of vertices of a graph such that every edge is
connected to at least one vertex.
O: A subgraph such that there exists an edge between
every two vertices
Clique
S: Each vertex is connected to all other vertices with an
edge
P Class Decision problem that can be solved in polynomial time
Decision problems whose solutions can be verified in
NP Class polynomial time
**Solution (like certificate) is NP**
O: Original; S: Simplified
**NP is not equivalent to Non-Polynomial**

NP Certificates
Problem Certificate
1. Hamiltonian cycle
Ordered set of vertices / cities
2. TSP
1. Vertex cover
2. Clique Set of vertices
3. Independent set


lOMoARcPSD|7981319

Polynomial and Non-Polynomial


Polynomial Non-Polynomial
Can be bounded by O(Nk) Cannot be bounded by O(Nk)
Definition (can be solved in polynomial time (can’t be solved in polynomial time
– tractable) – intractable)
1. Constant – O(1) 1. Exponential – O(2N)
2. Linear – O(N) 2. Factorial – O(N!)
3. Quadratic – O(N2)
Examples
4. Cubic – O(N3)
5. Logarithmic – O(log N)
6. Superlinear – O(N log N)

Time Complexity
Type Big O Description
• All steps are performed fixed amount of times
Constant O(1)
• Algorithm doesn’t depend on N
• Problem is broken down into pieces
• Size is cut by a constant factor
Logarithmic O(log N)

E.g.: Binary search
• Each step is performed certain fixed amount of times
Linear O(N)
E.g.: Linear search
• Problem is broken down independently into pieces
• Each step cuts the size by a constant factor
Superlinear O(N log N) • Obtain final solution by combining all sub-solutions
Slower (time

complexity
E.g.: Merge sort
increase)
• Double nested loop
• Inner loop depends on outer loop
Quadratic O(N2)

E.g.: Insertion sort
• Combinational explosion
Exponential O(2N)
E.g.: Finding subset of n-bits
Factorial O(N!) E.g.: Finding permutations for N

Big O Notation
Statement: function 𝑓(𝑛) is said to be 𝑂(𝑔(𝑛)) if there exists constants k and l such that
𝑓(𝑛) < 𝑘 ∗ 𝑔(𝑛) 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑛 > 𝑙

Sorting Complexities
Type Best-case Worst-case
Selection Sort O(N2)
Insertion Sort O(N) O(N2)
Heap Sort
O(N log N)
Merge Sort
Quick Sort O(N log N) O(N2)
Binary Search (searching) O(1) O(log N)
Binary Search (inserting) O(log N) O(N)
Knapsack O(2N)
Travelling Salesman O(N!)

Downloaded by Ashwin Krishna (akri0017@student.monash.edu)


lOMoARcPSD|7981319

Terminologies
Tree Terms Height Terms


Highest: Level 4

Heap Conditions
• for max-heap, the children values must be less than or equal to the parent’s value
• for min-heap, the children values must be more than or equal to the parent’s value
• fill up children’s position from left to right

Binary Tree Conditions
• every node can have at most two children
• every subtree is a binary tree
• every empty tree is a binary tree

Balanced Binary Tree
• For every node, the | height of the left subtree – height of right subtree | ≤ 1

Stack and Queues
Stack Queue
Last In First Out (LIFO) First In First Out (FIFO)
• .pop() • .pop(0)
• .append() • .append()
• len • len

Invariance
Sort Invariant
In the kth iteration of the loop, the first k items are sorted and
Selection
have the smallest elements in the list
In the kth iteration of the loop, the first k items are sorted, but
Insertion
they are not the smallest elements in the list

List Operations
Operation Description
a.count(x) Return the number of times item x
a.index(x) Returns the first position
a.insert(k, x) Inserts item x at index k
a.reverse() Reverses all the items


lOMoARcPSD|7981319

Graph Representations


Type Description
0 1 2 3
0 0 1 0 0
1 1 0 1 1
Adjacency Matrix 2 0 1 0 1
3 0 1 1 0

For weighted: replace the 0 and 1 with the weight
0 1
1 0, 2, 3
Adjacency List
2 1, 3

3 2, 1
Edge List [(0,1), (1,2), (1,3), (2,3)]

Divide and Conquer
Divide Conquer
Conquer by solving the small instances and
Divide the instance of a problem into 2 or
General case combine solutions to obtain solution to
more smaller instances
bigger instances
Binary search Dividing the list into half It searches the target in the mid
Repeatedly merging the sub-lists to
Merge sort Divide the list into sub-lists of length 1 become a new sorted sub-list until there is
only one sorted list
Choosing one element in the list as pivot.
Partition them into a left list (for < pivot) Combine the small sub-lists until it
Quick sort
and a right list (for > pivot) until the list is becomes only one sorted list.
trivial to sort (empty or one item)

General Backtracking Algorithm
def backtracking(partialSolution, Parameters(eg: N):
possibleSolution = getPossible(partialSolution)

if possibleSolution == []:
print(partialSolution)
else:
for item in possibleSolution:
partialSolution.append(item)
backtracking(partialSolution, Parameters)
partialSolution.pop()

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