40 views

Original Title: Lecture Notes COMP3506

Uploaded by Jack

- Creating and Using a Feature in SAP HR
- Data File Stucture
- 14261_C Progbinary Search Tree
- Questions Set1
- End to End guide on getting a Job in Tech industry
- Decision Tree Clips
- splay1.prn
- Transfer Learning, Soft Distance-Based Bias, and the Hierarchical BOA
- csc
- The Usefulness of Multilevel Hash Tables with Multiple Hash Functions in Large Databases
- MongoDB Data Models Guide
- OTL Doc1
- It33- Data Structures and Algorithms
- Review_8
- Data Structures - GeeksforGeeks
- cs101_endsem_2014
- fibo
- Data Mining Technique for Preventional Analysis of Work Accidents
- Internal Tables Sap
- Cerc2016 Presentation

You are on page 1of 17

31/7/2014

Topic: Stack and heap memory

Array

Contiguous uniform storage

Pros:

Constant time access to indexed memory location: O(1)

Memory efficient

Cons:

Resizing requires copying to new array

Worst case for sorted insert is must shuffle entire array

Linked List

Pros:

Insertion: O(1)

Cons:

Does not allow access via index must traverse entire list: O(n)

Uses more memory

Types:

Single linked list

Double linked list

o Easy to insert new node before a certain node

Recursion

Linear recursion

Tail recursion

Binary recursion

Multiple recursion

31/7/2014

o Type of data stored

o Operations supported and types of parameters

Specifies what each operation does, but not how

In Java: interface

Factory Pattern can be used to allow different ADT implementations to be

instantiated at runtime

4/8/2014

Primitive Operations

Assumed to take constant time

Big-O

f ( n ) is O ( g ( n ) )

f ( n ) cg ( n )

(Big Omega)

Big-

n n0

cg ( n ) f ( n)

for

cn 0 such that

Big-

(Big Theta)

c 1 g ( n ) f ( n ) c2 g(n)

Describes a tight bound

g(n)

7/8/2014

Lecture 6:

7/8/2014

11/8/2014

The stack ADT:

Insertion/deletion: LIFO

Main operations:

o push(object)

o pop()

Auxiliary operations:

o top()

o size()

o isEmpty()

For empty stack, pop and top return null

Keeps track of chain of active methods with a stack

Performance and limitations

Let n be no. of elements, N >= n fixed sized of array

Space: O(N)

Time: O(1)

Trying to push element into full stack exception

Note: Using linked list instead would give space O(n)

14/8/2014

Queue ADT:

Insertion/deletion: FIFO

Main operations:

o enqueue(object)

o dequeue()

Auxiliary operations:

o first()

o size()

o isEmpty()

Array-based queue

Array size N

Two vars keep track of front and size

Array location

queue

push(o) adds o to the end of list

o When array is full, replace array with a larger one

Incremental strategy: Increase size by constant

Doubling strategy: double the size

o Worst time complexity: O(n). Best: O(1)

Amortized time of a push operation is the average time taken by push: T(n)/n

Turns out doubling strategy is better

Positional list ADT:

Accessor

o first()

o last()

o before(p)

o after(p)

Update

o addFirst(e)

o addLast(e)

o addBefore(p,e)

o addAfter(p,e)

o set(p,e)

o remove(p)

Natural implementation: doubly-linked list

Iterator

next()

hasNext()

Lecture 9: Trees

18/8/2014

Tree: Hierarchical structure of nodes with parent-child relation

Traversal

Preorder traversal

o A node is visited before its descendants

Postorder traversal

Binary tree

Each node has at most two children: left child and right child

Proper binary tree: each node has exactly zero or two children

Inorder traversal

o A node is visited after its left subtree and before its right subtree

22/8/2014

Evaluate Arithmetic Expressions

Euler Tour Traversal

Preorder, postorder, inorder traversals are special cases of this

Walk around tree and visit each node three times

Node stores:

o Element

o Parent node

o Sequence of children nodes

For binary tree, node stores:

o Element

o Parent node

o Left child node

o Right child node

Node implement position ADT

Node v is stored at A[rank(v)]

o rank(root) = 0

o Left child: rank(node) = 2 * rank(parent(node)) + 1

o Right child: rank(node) = 2 * rank(parent(node)) + 2

May be ok to use if every row is filled. Saves a little space by not needing

links

Priority Queue

Priority Queue ADT

Entry: pair(key, value)

Main methods:

o insert(k, v)

o removeMin(): removes and returns entry with smallest key, or null if

empty

Additional methods:

o min()

o size()

o isEmpty()

Ordering

x y y x

Comparability:

Antisymmetric property:

Transitive property:

Entry ADT

Methods:

getKey()

getValue()

x y y x x= y

x y y z x y

Comparator ADT

Compare(x,y) returns i such that:

i< 0 if a<b

i=0 if a=b

i> 0 if a>b

Unsorted:

o Insert: O(1)

o removeMin and min: O(n)

Sorted:

o Insert: O(n)

o removeMin and min: O(1)

Selection-Sort

PQ-sort function implemented with unsorted sequence

Running time

o n insert operations takes O(n)

Runs in

O ( n2 )

time

Insertion-Sort

PQ-sort function implemented with sorted sequence

Runs in

O(n2 ) time

In-place insertion-sort

Use swaps

25/8/2014

Heap

A binary tree storing keys at nodes and satisfying properties:

o

o

depth

2i

nodes at

Height of heap:

O ( log n )

Insertion: Insert after last node, then restore heap-order by swapping with

parent

Removal: Replace root with last node, then set new last node. Restore

heap-order (downheap)

Updating the last node:

o If previous left node is left child, go to right child. Otherwise:

o Go up from previous last node until left child or root

o If left child is reached, to the right child

o Go down left until a leaf is reached

o If root is reached, go left until new row

o

n

log

O

Heap-Sort

O ( n)

Space:

Heap-sort:

O ( log n )

O ( 1)

O ( n log n )

Can represent heap with n keys by array of length n

For node at rank I, left child 2i + 1, right child 2i + 2

Merging two heaps

Merge two heaps and key k by storing k as root with the two heaps as

subtrees, then perform downheap

Bottom-up heap construction

O(n)

time

29/08/2014

Adaptable Priority Queue ADT:

replaceKey(e, k)

- returns previous key of entry e

replaceValue(e, v) - returns previous value

Location-aware list

o

o

o

key

value

position (or rank)

Map

Searchable collection of key-value entries

Multiple entries with the same key are not allowed

Map

ADT

get(k)

put(k,v)

remove(k)

size(), isEmpty()

entrySet()

keyset()

values()

Hash function

Usually specified as composition of hash code and compression:

polynomial accumulation, e.g.

O(n)

Lecture 13

1/9/2014

Collision handling

Separate chaining: let each cell in table point to linked list of entries

Open addressing: place colliding item in different cell

Linear probing

o Place colliding item in next (circularly) available table cell

o Future collisions longer sequence of probes (inspections)

o remove(k): if entry (k,o) is found replace with DEFUNCT and return

element o, else return null

Double hashing

o Have secondary hash function d(k)

( h ( k ) + jd ( k ) ) mod N , j=1,2,3,

Performance of hashing

O(n)

(i.e.

=n /N

Load factor:

probes for an insertion with open addressing is

1/(1 )

O(1)

In practice hashing is very fast provided load factor is not close to 100%

10/9/2014

Set

Set ADT

S T

addAll(T):

retainAll(T):

removeAll(T):

S T

ST

Implementations

Sorted list

o

(>,<,==) run in

O ( n A +n B )

O ( 1)

Generic Merging

intersection, union

Runs in

O ( n A +n B )

Multimap

Similar to map, but can have multiple entries with same key

Skip Lists

O(1)

A series of lists

Sh

S0 , S1 , , Sh

Implementation

Quad-node: stores entry, link to nodes prev, next, below, above

Define special keys PLUS_INF, MINUS_INF

Space Usage

h

2ni n 21i 2 n O ( n )

i=0

i=0

Height

log n

O )

Time

Search time proportional to number of drop-downs + number of scanforwards.

O(log n)

O(log n)

(with high

probability)

Binary search

implemented with an array, sorted by key

At each step, the number of candidate items is halved

O(log n)

Search tables

Ordered map implemented by sorted sequence

O ( log n )

Insert/remove:

Good for small maps or when search is the most common operation

O ( n)

Binary tree storing keys/key-value entries at its internal nodes

key ( u ) v key ( w )

Deletion

Performance

For ordered map with

Space used is

O ( n)

Height is

O(n)

O ( h ) time

O(log n)

in best

case

Search Tree

8/9/2014

AVL Tree

Binary search tree with height balance: for every internal node v, heights

of children of v can differ by at most 1

n

log

O

Search Trees

11/9/2014

keys is

(2, 4) tree

A multi-way search tree with:

o Node-Size property: Every internal node has at most four children

o Depth property: All external nodes have the same depth

h log ( n+1 )

search takes

O(log n)

Splay tree

18/10/2014

Does not enforce logarithmic upper bound on tree height

o

O(n)

O ( log n )

Splaying

Move a node to root using rotation

Performed after all operations

See slides for

o Which node to splay

o Zig/zag operations. Note: easier to understand with actual numbers

for nodes

Splaying costs

o O(h) rotations, each O(1). Still O(n) worst-case

o Amortised cost is O(log n)

Time T(n) needed to perform a series of n splay operations,

divided by n, i.e. T(n)/n

Red-Black Trees

18/9/2014

search tree whose nodes are coloured red or black

o Has same logarithmic worst-case asymptotic time complexity for

search, insert, removal

o Simpler implementation with a single node type

Is a binary search tree with:

o Root property: root is black

o External property: every leaf is black

o

o

Depth property: All leaves have the same black depth

Height

Height O(log n)

o Proof: height is at most twice the height of associated (2,4) tree,

which is O(log n)

Search works the same way as for binary search tree. O(log n)

Insertion

Colour the newly inserted node red, unless root.

If there is double red,

22/9/2014

Merge-sort

Divide and conquer

Like heap-sort, has O(n log n) time

Unlike heap-sort

o Does not use an auxiliary priority queue

o It accesses data in a sequential manner (suitable for sorting data on

a disk)

Algorithm

o

Divide: partition

into

S1

each.

Conquer: merge

S 1 and

S2

and

S1

S2

and

S2

length n/2, is O(n). Height is O(log n). At each recursive call the sequence

length is halved. Thus total running time of merge-sort is O(n log n)

Quick-Sort

Algorithm

o Divide: pick a random element x (called pivot) and partition S into

L: elements less than x

E: elements equal x

G: elements greater than x

Note: each insert/remove is at beginning/end of sequence, so is

O(1). Thus partition takes O(n)

o Recur: sort L and G

o Conquer: join L, E and G

Expected height is O(log n), work done at nodes of same depth is O(n)

Expected running time of quick-sort is O(n log n)

O(n )

In-place quick-sort

See slides

Shortest Paths

13/10/2014

Dijkstras Algorithm

Solves single-source shortest path problem

Similar to uniform cost search, but no goal vertex

Used on weighted graph with non-negative edge weights

vertex with smallest distance label d

Edge relaxation:

min { d ( z ) , d (u )+ weight ( e ) } d ( z )

20/10/2014

Trie

Trie: A compact data structure for representing a set of strings, e.g. all the

words in a text

Supports pattern matching queries in time proportional to the pattern size

Standard trie: ordered tree with each node labelled with a character.

Children alphabetically ordered

Compressed trie: Every internal node is at least degree 2. Obtained from

standard trie by compressing chains of redundant nodes.

See slides for time complexity

Compact representation

Compact representation of compressed trie, store ranges of indices at

nodes instead of strings.

Suffix Trie

- Creating and Using a Feature in SAP HRUploaded byMasaki Junior
- Data File StuctureUploaded byShashank Patel
- 14261_C Progbinary Search TreeUploaded byAnkur Singh
- Questions Set1Uploaded byVina Vaizha
- End to End guide on getting a Job in Tech industryUploaded byAndreiPorfireanu
- Decision Tree ClipsUploaded bylinanofita
- splay1.prnUploaded byKakz Karthik
- Transfer Learning, Soft Distance-Based Bias, and the Hierarchical BOAUploaded byMartin Pelikan
- cscUploaded bywinGene
- The Usefulness of Multilevel Hash Tables with Multiple Hash Functions in Large DatabasesUploaded byterminatory808
- MongoDB Data Models GuideUploaded byRicardo Vercesi
- OTL Doc1Uploaded byZafar Iqbal
- It33- Data Structures and AlgorithmsUploaded byMathan Nagan
- Review_8Uploaded byWalid_Sassi_Tun
- Data Structures - GeeksforGeeksUploaded byPriyanka Yadav
- cs101_endsem_2014Uploaded byywakade
- fiboUploaded byChristina Robinson
- Data Mining Technique for Preventional Analysis of Work AccidentsUploaded byIJAERS JOURNAL
- Internal Tables SapUploaded byshankarmnish
- Cerc2016 PresentationUploaded byAnil
- proceedingsBRATS2012.pdfUploaded byRatna Raju Ayalapogu
- datosUploaded byAlberto López
- 24 TreesUploaded byVan Bao Nguyen
- Pattern Matching + HashingUploaded byJohn Erol Evangelista
- 06-CSI2101Induction.pdfUploaded byIbrahim Kanouche
- 10.1.1.115Uploaded byJuan Arteaga
- 117CC - DATA STRUCTURES.pdfUploaded byvenkiscribd444
- mba 758 database management systemUploaded byapi-241418009
- An Optimised Parallel Tree Search for Multiuser.pdfUploaded byDebasish
- 282373599-Cocos2d-Programguide.pdfUploaded byloicuoi

- ScapeUploaded bydelap05
- GI-0007.027 1994Uploaded bytimam
- First Crusade: the March of Robert of NormandyUploaded byWilliam Hamblin
- olga vorlicky cv 07 2017Uploaded byapi-376475889
- ForewordUploaded byMihaela Monica Motorca
- PHT Pipe Clamp Catalog2012AUploaded byDifa Liu
- IB-Lite Quick Guide 12-2011Uploaded byotobias999
- Plan-BUploaded bySankar Kutti
- The Tunxis Sun (November 2018)Uploaded byTunxis Sun
- 222_Social Sciences.pdfUploaded byahmad_maimun90
- Citation in LaTeXUploaded byPravin Bhole
- IMC14692-USEN-00_AARPUploaded byKarina Bernier
- Answering Critique by Truthseeker Regarding Wudu-Abulution versesUploaded byaastana.com
- SGT News Jan2012Uploaded byJesse Koroscil
- gfhfgUploaded bybeachsnow
- Ms Plate PricelistUploaded byrrpenolio
- Real Time SystemsUploaded byJayashree C Rao
- Chess_Calculation_Technique.pdfUploaded byPrem Yadav
- Arrow Et Al. BIB 1995. Economic Growth, Carrying Capacity and the EnvironmentUploaded byA B H
- 9781136243578_sample_499301Uploaded byaag0033398
- script the impact of mental health on young people documentaryUploaded byapi-295714214
- POPULARITY OF MARXIST SCHOOL OF THOUGHT IN AFRICAN LITERATURE: A CRITIQUE.Uploaded byIJCIRAS Research Publication
- Organic Act armmUploaded byIcas Phils
- on_heartsUploaded byliubartas
- The Eight Elements of TQMUploaded byatanda_shadrack
- rh+ Preposition Soruları 1.pdfUploaded byBoris
- Kotler Mm14e Im 12 GEUploaded byabdibaasid
- Time Series DecompositionUploaded byGagan Deep Singh
- Ricoh 3800c (Model K-p1, A-c2, J-p1) Technical NoteUploaded byAnonymous UslEQS
- Stepper Motor ApplicationUploaded byShanmuga Sundar