04 Datastructures
04 Datastructures
1 Material
• Alternatives:
– Learning Videos:
• 02_data.clj
2 Learning Outcomes
After completing this unit you should be able to
• recall the runtime characteristics of various operations on lists, vectors, sets and maps.
• identify possibilities for structural sharing for given data structures and operations.
• decide which calculations in Clojure are evaluated immediately and which are (or can be) delayed.
• differentiate between implicit and explicit laziness and explain the difference.
3 Highlights
• Immutability
• Structural sharing
• Laziness
4 Exercises
Exercise 4.1 (Hash Trie)
In this exercise we consider a hash trie with a branching factor of 4, meaning every node has at most 4
children. Assume the following hash values for this exercise:
hash(:a)= 00 10 00 00 hash(:e) = 10 01 11 01
hash(:b)= 10 00 00 10 hash(:new) = 00 01 01 10
hash(:c)= 01 11 10 10 hash(:ouch)= 11 01 11 01
hash(:d)= 11 00 01 00
key: :e
val: 12
b) How many bits are needed for determining the position in an array?
c) Insert the value :ez under key :new. Which nodes can be referenced in the previous trie and which
have to be copied?
d) Insert the value :almost-a-collision under key :ouch. Which nodes can be referenced in the
previous trie and which have to be copied?
Exercise 4.2 (Matrix)
In the following exercise, we consider a matrix as a vector of row vectors. For example:
b) Write a function trans, which transposes the matrix, i.e. swaps the rows and columns:
Questions
If you have any questions, please contact Philipp Körner ([email protected]) or post it to the Rocket.Chat
group.