Docsity

sworld mapping assignment, Exercises of Combinatorics

Toggle sidebar
bg1
->
-
Linear
Behavior
example
10
arithmic
behavior
the
complexity
and
In
Find
largest
Max
value
in
array
Algorith
with
run
time
+(a)=nlogh
requires
A
=
[0,
7,
9,
1,
5,33
1024
x
10
=
10,200
time
spent
for
*
Worst
case
-
Maximum
Linear
search
Time
Complexity
(N
-
number
of
operation
that
are
Total
time
complexity
=
Length
of
Input
n
=
1024
necessary
to
preform
for
a
given
array.
↳
Problem
size
quadratic
behavior
for
Amplex
Algorithm
running
time
time
=
<
Input
S12e
if
n
=
1024
Then
max
of
Operation)
ITAIN)
=
Max
#
of
operations
When
n
=
1020
Is
1024
x
102d=
1048,32
->
number
of
the
algorithm
A
-
I
LoreTnOrmirror
a
of
operations
of
the
problem
silent
Algorithm
analys
2.
109
function
second
best
-
<
Big-OH
Notation
Big-OH
(upper
bound)
↳
is
Big-0
if:
TIN
=
OfIN)
***U
rules
if
there
are
positive
constants
rule
#1
-
c
and
no
such
that
TIN)
=CfIN)
if
TIN
=
0
HIN)
and
T2
IN)
=
0(g
(n)),
then
N
When
I
no
(a)
T,
(N)
+
T2IN)
=
0
max
f
(N),
9
(n7)
oldis
owes
ologn)
Big
-oh:
State
a
claim
about
the
->
greatest
amount
of
resources
(TiMe)
(b)
T,I N* T2 IN )= 0DfI*
9(47)
I
0
(max
SN2
N3,
09.
NB)
=
0/N3)
that
is
required
by
an
algorithm
⑧
#
#2:
Polynomial
##1
is
a
polunomial
of
degree
K,
TIN
=
106N
=
TIN)
IS
OINO
if
TheN
TIN
=
0/NY
#3
Exponent
VUIe
#3
TIN)=
10925
N
-
If
TIN3
=OlogN
+
3(logr)"
+
IN+3N4
+6N2
In
ever
case:
TIN)
=
OIN)
Erratfioricra
i9vaD
eOrted.
Arom
rule
#4:
if
/e1s8
↓
-
array
running
time
never
more
than
the
A
=
[2,
5,
7,
9,
11,
15]
running
time
of
the
test
condition
1)
Insert
(1):
worst
case
all
elements
need
to
be
shifted
one
right
(worst
case)
&
M
run
time
iiiiiieftainin
size
by
a
fraction
(which
is
usually
1/27
·usually
assume
is
pre-read
(sorted
#gorithms:
Binary
search
is
sorted,
Find
the
Index
1Such
that
Alex
or
input
for
liz0;injitt)
Best
solution
binary
search:
a
[i]
=
0
go
left
half
it
x
<A
[mid]
for
(i=0;
;H++)
the
following
program
Fragment
at
also
OIN?
go
right
half
if
X>A
[mid
Erepent
for
(p=0;)
<n;
5
+
+
worst
case:
Ollogn)
acIS+=
[5>
+
Best
case:
OID
Found
in
the
middle
run
time:
Olcoqu).
Find
operation
in
sorted
array:
&liogn)
worstcase
all
other
operations
ON)
time.
**
pf3
pf4
pf5
pf8

Partial preview of the text

Download sworld mapping assignment and more Exercises Combinatorics in PDF only on Docsity!

Linear Behavior example 10 arithmic

behavior thecomplexity and

In

Find largest Max value in

array

Algorith with run time +(a)=nlogh requires A =

[0, 7, 9, 1, 5,

1024

x

= 10, time spent

for

Worst case

Maximum

Linear search Time Complexity

(N

number

of operation

that

are

Total time complexity =

Length

of

Input

n

1024

necessary

to

preform

for a

given array. Problem size quadratic

behavior

forAmplex

Algorithm running time time = < Input S12e if n = 1024 Then max of

Operation)

ITAIN)

= Max

of

operations When n = 1020 Is 1024 x 102d= 1048, -> number of the algorithm A

I

LoreTnOrmirror

a

of operations of the problem silent Algorithm

analys

109 function second best

Big-OH Notation Big-OH

(upper

bound) is Big- if: TIN = OfIN) ***U rules if there are

positive

constants rule

c and no such that TIN) =CfIN) if

TIN

= 0 HIN)and

T

IN)

0(g

(n)),then N When Ino

(a)

T,

(N) + T2IN) =

max f (N), 9 (n7) oldis owes ologn) Big -oh: State a claim

about

the

greatest amount of resources (TiMe) (b) T,INT2IN)=0DfI 9(47) I

(max

SN2 N3,

NB)

0/N3)

that

is required by

an

algorithm

⑧

Polynomial

is

a polunomial of degree

K,

TIN

= 106N =

TIN) IS

OINO if TheN TIN = 0/NY

Exponent

VUIe # TIN)=

10925 N

If

TIN

=OlogN

3(logr)" + IN+3N +6N In ever case:

TIN)

=

OIN)

Erratfioricra

i9vaDeOrted.

Arom rule

if

/e1s

↓

array

running time never more than

the

A

= [2,5, 7, 9, 11,

15]

running time of the test

condition

Insert

worst case all

elements

need to be shifted one

right

(worst

case) &M run time

iiiiiieftainin

size by

a fraction

(which is usually 1/

·usually assume

is pre-read (sorted

#gorithms:

Binary search is

sorted, Find

the Index 1Such that Alex or input

for

liz0;injitt)

Best

solution binary search: a [i] = 0 go left

half

it x A [mid Erepent for (p=0;)

Best

case: OID Found

in the middle

run time: Olcoqu).

Find

operation in sorted array: &liogn) worstcase all other operations ON) time. **

List interface in

Java.

Util

Abstract

data minerations it again obtain is interinarianiserimridities rantar initivar &es Sinsertion

of new elemental

It disadvantage of linked list

ADT · removing of existing

element,

not easily indexable, get expensive. List: Linear sequence of

arbitrary

#'s is expensive.

Important:

size of

the LISN

-> quere

ADT

some

operations. not

-Pandap "*8@Eron T Deavere ~St

-> OIN

t quare ADT:Ol F1r5+-1H-FIUS-OUt · make empty · find-returns position -> O(N) Worst case

OperatIONS:

· Insert and remove

->O(N) worst case

↓ endaveve: Insert at lend ⑭ · Find Kth

-> Oll)

ertionand deletions occur overt event dedueve:

delete the

most recent inserted element Important

note:

**

S

Better.

I

Printlist

->

OIN)

↑ WarevatgesAndotrran I

⑭List

FindKth -> No longer as efficient as an array

implementation

⑧ 17 time and works

by

traversing

down

the list

ere

Special

cases

AList, stacks, averes ↑ Add to Front remove First:

Old if

a link to #Out is kept Add to end: O(l) it link to last node kept

mentation

of arere

#on ICTs in back removing last item:

O(n)

An

array-TheArray

position

Front back

represent end

of the

queue ↑ ↑Beagining number of elements in

quere:

currentsize.

ADT

stack

-> ISTO:

Last-1-First-out.

& time complexity operations: push-insert (on+op)

pop-delelet

recently deleted. access:

0 (n)

search:

(n) 2 NATION

Of StaCKS

I InSerTIOn: 0(

Linked list

implantation of

StUCK:

Delete:

0( push:

insert

at the Fort &

POP:

delete

element

at the Font A

KS

< Peek (TOp):

examine element

at the Front, retuns It value.

T

2 h of stack Array list implementation

of

stalk:

Notes post Fix expression:

top

of stack -- for empty stacks · the time to evaluate Is

01N)

processing

each

push some element into

X

onto stack: we increment topstalls and set

element

in the input

consit

of stalk operations The Array Stop

Stack]

= x pop-we return the

Array

stop

stack)

the

decrement

topstack and

thus takes constant

time

Pop and

push are preformed In very

fast

constant time. · If expression is given in

post

Fix

notation

them

no need to know any precedence rule;

this

is an Disadvantage

PriOrHU Implementation

&

aveves

Ime

complexity

A

data

structure

that

allows

The ·

priority

dreve

In

Linked

list (unsorted)

following

two

operations: ·Sert

In Front

IS 01)

· Insert (add

-deletemin

0D)

·

deletMin,

which Finds,

returns and

I

· priority

avere

in sorted

linked

list

removes

the

element

in

priority

Greve -insert

is old

is

deletemin

Main I

dea

GrnhaveOAFLFonda

restructure

that

serves

I

·

priority

arere in

Binary

sear on tree

insert in

(average

case)

Ollogn)

-deleterin in

(average

case)

ollogn)

·

each (ten has

a

"profity"

ex. Min

element has

greatest

priority ↓

norityare

rededth

deletemin:

percolate

down

Theorem: A heap

storing

N modes

&

mentat

IOn

~

queves

has

neight

ollogn)

Implementation

for

priority

deve

try

heap

mi

hedp:

T

run

time

of

deletemin is

Oliogn)

Structure property:

A

complete binary

ree

that

completly

filled with

possible

executions of the bottom

priority operations

D

level,

which

is filled

from left to

right Implementations

(min

heap

property:

The

priority

of

every

non-root

deceteMin:

percolate

down

hode is less

important

then the

priority

of Its parents

keep

comparing

phority

of stem

with both children

t

t

· If

priority

is less than, swap

with

the most important

child

and

go

down one level

&

a

node the

keys

of

the

child

↑

·

done

of both

children

are

less

important

than

the tem

or

were

reached a

leaf

node.

Insert/ddd:

general

strategy

torso

inept

Noir

re

add

a

value

to

the

tree

treate

a

hode

in

the

next available

location,

since

otherwise

the tree

will

not be complete

· Focus

on restoring

the heap

order

properity.

Not

a

binary

search tree

on

average

case

oil.

Formiasareas

is a

te

Basically

a

priority

is a grere

that

priorities

things

in orderbased on data

given

therefore

if

not

have ...

ex

eX.

④

key

of

anode the

key

of the children

oDierIs e [11output

·Go

swap

OOGOOLOOOOO

therefore y

< & On problem

HaSH

TaDle

ADT

Hast table

supports only a subset of operation

allowed

by binary search

tree. nash

table

not operations like max and min are

not supported

AED Ewen two key map to the same location in the Hashing: Insertions,

deletemin,

and search. In constant time.

COIIISIon

resolution: seprate chaining · assume that all

the key

are the first 10

squares

2

general

Idea

and the hash function:

hash(x)=xmod

The Ideal hash

table

data structure is merely an array

of some

fixed

size, coulding

items.

⑭ main a ndeasseparate chang the

lume

tape

table: LE advantage/disavantage Index=

hash-Function

(ke

problem: "The collision problem Disadvantage: parts of the table array might never be used. key Med tables -> nonemannermania is immediationar

erationS Increases to 0) worst case

if Input

key

are integers, Hash Function:

good Idea to make table she prime* 2 dressing

Use

empty space in

table

Important

Points: All Items are stored in

hashtable

&Chaining. The load

factor

·each sell keeps

one of these three states: EMptY, · While (MS**, If

collision,

alternative

cells are tred Until empty is found.

0Clopied,

DeleteD.

I internationanometripinnainai ·

Deletion

(Lazn): Key

deleted

-> S10+ Marked

Deleted ↑

·Probe

sequence: sequence

of

array

maxes that probing

follow

in search for an

empty

cell during insertion, · IS a COlIISION

reSOlUtIOn

or seaching for

akey

during

find or delete

operations. Method that

elimates

primary age/advantage ↓

clustering

by changing the prode unsuccessful search:

#o+

hodes to exam is

on are open adress function:

Ukey)- key'.

tablesize successful search:

#Othodes

to exam is 712 0 rg.

It)

Advantage: All items

are stored in the

probe sequence: has its self. No other structure

required

(n (13ey)

%. Tables12e nashing Find a position:

hIke)

= Ke . tablesize

It

Disadvantage: The

keys

of the

object

(n) ken)

Table ske probe sequence: (olkey)

  • (2xIken)) tablesize to be

hashed

must

be distint · Dependent on choosing a

proper

table size Inciien)+i=).

tablesize

1v(key)

(2*U)

K24) 7

table size requires the use of three stage (OEMpt,

Important

points

good news 10

(Key)

+i* U lkey)

tablesize

occupied, pefeted ( . earate Probing better enter it how thatthIS (are dress ↓ primary Clustering

· UIK24)

= KCUYP. eVIIseU) -9-lsey. He Linear probing

Bad NEWS

·

2x9

Ographs · A graph (hE

KUvET

CONSIStOf

a Set Of *gical sort ·topological sorting is not vertices, and a set of edges A topological sort of a

directed acyclic

possible if the

graph

has a · each edge is a pair (v,w), wherev,wEV.If graph

(DA(z)

is a linear ordering of its vertices

cucle,

since

for two

vertices the pair

is ordered,the the

graph

is directed. such that for

every

directed edge

(v/v)

in E,

the vertexsince

hand won the cucie, v precede

Directed

graph

are sometime refered to as diagraph ↓ come before in topological

ordering.

wand w

prcedes

v · edges in the diagraphs have a direction and in general ·ordering is not necessary is for every (v,v)

@E-(v,UICE.

The Vertex vis the source and the vertex

the destination · in-degree of a vertex: edges where the vertex is the destination QBNOCF ·OUR OF INTERN out-degree of a vertex: edge where

the

vertex is the source

·A

cucle is a path that begins

and ends

at the

same

node.

(v

Vis) itnlucle whou cc causes *al sort First AlgOUIM

cal sort Algorthm

A IgoUHM #1: -mark each vertex with Its

in-degrees

#he artifice is to

avoid searching

reftexidegree for a zero degree vertex ever the a 0

OtOtOf t time spending

"zero

degree vertex NadPUpotRAVENOS Athat Itaddandremove it 9

O(,

Total: 0 (IVI

In a

queue,

stack ect... Error rates and PCR te

OnEriom'olaointadawetvonma rations

·SOIDFS) recursively explore

one part before going back to the other parts not

yet

explored ·(BFS) explores area close to start node First mong

Algorithms

Of

The

DESRB' Olvit O WeWelgHtedPAt oth ⑰S

The problem:

Grenagraph with non-negative edge weight,

= (,E), way to a leaf before backtraking nearest to the root before and a distinguished source vertex in v

·DFS

explores

a path

all the

Determine the distance and

shortest

path from source vertex to every and exploring

another path

exploring further

away

· After searching

A,

then

B,

then D,

vertex in the grostra Algorithm The search

back

tracks and tries

marked

as either known or unknown. A tentative distance another path from B

each vertex is ·Node are explored in order: OD'E ON TOO Or -drll kept for each verterrepath length from to using only known vertise

as Intermediates

ABDEHLMNIODCFG

KO

  • We

recor, which is the last vertex to cause achangetod or

resets

a veterans Algorithm v, which has the smallest do amoung all

unknown

vertices, and

declares

that ·

Based

on expanding

cloud

of know vertices path from stor is knowseason)

I

greedy

strategy

Basic

Idea:

Finds

msp on

seleting edges GOOD OELOA oFloOORooTodor originatio Its starts

with

tree,

T,

consisting

of the roSKal AlgOrIHMthis

method

is based

on expanding cloud are from graphone-by-one as follows atree formed from

graph

edge starting

vertex, v, vis any

in v

·The basic idea of the Kruskal's

algorithm

connects all the vertices of Gat. Then It adds the shortest edge) = edge

nth

minimum cost emanating from that connects to

  • continually

to select the edge in

order

of

smallest

weight

loWe total COSt.

-Accept

an edge if it

does

not caves a

cycle.

The nest of the graph. = ol then moves to

the added

vertex and

repeats

the process. OOO M Bonamed O CiaraMithortneaps or case research

is dominated

application

of

mSp

Cable and road next work

with min lost.

d

Data

structure

set

terms

three

operations

of

Intrest:

Makeset(x)

create

a

new set with only

X. Assume

X

( not

already

·Find(x)

Vetons

the

rep