100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
College aantekeningen

College aantekeningen Data Structures and Algorithms (X_400614) Final Term

Beoordeling
-
Verkocht
-
Pagina's
29
Geüpload op
15-12-2022
Geschreven in
2020/2021

Alle College aantekeningen voor Data Structures and Algorithms (na de midterm)











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Documentinformatie

Geüpload op
15 december 2022
Aantal pagina's
29
Geschreven in
2020/2021
Type
College aantekeningen
Docent(en)
Mehrabi
Bevat
Alle colleges

Onderwerpen

Voorbeeld van de inhoud

Trees and AVL tress
The height of a node:

- If the node has no children: -1
- If the node is a parent: 0
- Height of a random node is the max height (left subtree , right subtree) + 1
- Balance is (the height of the left subtree – height of the right subtree) is smaller or equal to 1

If the equation of the balance is positive: left-heavy. If it is negative: right-heavy.

If the tree is left-heavy:

- Right rotation
- Left-right rotation

If the tree is right-heavy:

- Left rotation
- Right-left rotation

Trees important points
- A node without children is a leaf (external node)
- Each node with children is an internal node
- The depth of a node is the length of the path from that node to the root
- The height of a node is the length of the longest path from that node to a leaf

A Binary tree: each node has AT MOST 2 children

A full Binary tree: all internal nodes have 2 children OR 0 children. The following holds if the tree is a
binary tree: the amount of leaves = the amount of internal nodes + 1

Running time of 3 traversal algorithms: Big Theta of n. Each node will be visited exactly 2 times ( in
preorder and inorder) and three times in postorder. Total number of inorder and preorder is 2n and
postorder 3n  Theta(n). Each visit is Theta(1)

AVL trees
Height-Balanced property: for every internal node v, the heights of its children differ at most 1

The height of an AVL tree storing n keys = O(log(n))

Running time of search operation assuming the size of the input tree is n? Big O of log(n)

Running time of insertion operation assuming the size of the input tree is n? Big O of log(n)

Running time of deletion operation assuming the size of the input tree is n? Big O of log(n)



Hash tables
In general: hash tables are able to perform every dictionary operation in O(1) time, in average
(expectation)

,Preventing collisions by chaining
Worst case search time could be Theta(n), because than it is just a linked list

Simple Uniform Hashing: the hash function maps a key to a uniform choice  each of the slots is
equally likely to be hashed to

For a set of n keys and slots we have: the expected (average) length of each chain is n/m (load
factor)

If Simple Uniform Hashing is applied: each dictionary operation will take O(1 + load factor)

Open addressing
In a has table with load factor alpha in which collisions are resolved by open-addressing, the
expected runtime of an unsuccessful search is theta (1/(1-alpha)), under the assumption of simple
uniform hashing.

In a hash table with load factor alpha in which collisions are resolved by open-addressing, the
expected runtime of a successful search is theta ((1-alpha) * log(1/1-alpha)), under the assumption
of simple uniform hashing.

If you want to delete an item in hashtable, write a special character once the deletion has been
performed. If you search for new items to delete, the algorithm to delete an item will assume “it is
full” and will continue searching for the to-delete item.

What is the space complexity of a hash table of size m storing n items, in which collisions are
resolved using chaining?

Theta(n+m)

What is the space complexity of a hash table of size m storing n items, in which collisions are
resolved using open-addressing?

Theta(m)

Suppose we wat to store a set S of n keys in a hash table T with size m, with m = n + 2, and a hash
function that behaves uniformly. Should we resolve collisions with chaining or with open-
addressing?

, Hash-table using open addressing from hashtable with m slots to 2m slots is expanding. (If the
amount of elements cannot suit the amount of slots). From 2m slots to m slots is shrinking.



Lecture 6: AVL trees and Hash Tables
AVL trees
Data structure that is an efficient data structure for implementing dictionary ADT. AVL trees are able
to perform every dictionary operation in O(log(n)) worst-case time.

Ideally we wish to have BSTs that have always a small height, no matter how the sequence of
insertion/deletion is. This would result in having fast dictionary data structures! AVL trees are BSTs
that have always a small height.

Height-Balanced Property: For every internal node v of T, the heights of children of v differ by at
most 1. Any binary search tree T that satisfies the height-balanced property is called an AVL tree.

The promise is that the heights of siblings don't differ by more than 11. In other words,
the promise is that for every node pp, the heights of the children of pp differ by at
most 11 from each other.

The height of an AVL tree storing n keys is O(logn)

If you perform an insertion, this might violate the height-balance property of T. If it violates, how to
“repair”?

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
gideonrouwendaal Universiteit van Amsterdam
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
49
Lid sinds
2 jaar
Aantal volgers
22
Documenten
17
Laatst verkocht
6 maanden geleden

5,0

1 beoordelingen

5
1
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen