100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

College aantekeningen Data Structures and Algorithms (X_400614) Final Term

Rating
-
Sold
-
Pages
29
Uploaded on
15-12-2022
Written in
2020/2021

All College notes for Data Structures and Algorithms (after midterm)

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
December 15, 2022
Number of pages
29
Written in
2020/2021
Type
Class notes
Professor(s)
Mehrabi
Contains
All classes

Subjects

Content preview

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”?

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
gideonrouwendaal Universiteit van Amsterdam
Follow You need to be logged in order to follow users or courses
Sold
49
Member since
2 year
Number of followers
22
Documents
17
Last sold
6 months ago

5.0

1 reviews

5
1
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions