Skip to content

Commit f443850

Browse files
committed
Added Lec4 home work
1 parent 3e4734e commit f443850

14 files changed

+26
-0
lines changed

python/lec4/home/Advanced.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Task 1: Implement higher order functions map(), flatMap() and withFiler() for Option(Int).
3+
It wraps Int in a class. Each value may be either Int or Null
4+
5+
flatMap() differs from map(), since it provides data flattening. For example, if you apply map() twice to your data structure, your result should be map(map(Option(Int))) -> Option(Option(Int)), whereas flatMap(flatMap(Option[Int])) -> Option(Int)
6+
7+
withFiler() is a Higher Order Function, which takes a function on input and applies it as a filter to every element
8+
9+
Task 2: Given an implementation from Task1, build a 1000 element
10+
11+
A. Unsorted binary tree.
12+
B. Red-black tree
13+
14+
and calculate the sum of all nodes for Option(Int). Your filtering functions should be:
15+
16+
A. a % 2 == 0 (even numbers)
17+
B. (a % 3 == 0) && (a % 5 == 0) (divisible by 3 and 5)

python/lec4/home/Simple.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Task 1: Write a simple Higher Order Function map(data, f), where f() is some arith function and data is a List, Dictionary and Numpy array.
3+
map(data, f) applies function f() to every element of the data structure and returns a resulting data structure.
4+
5+
Can you make a single implementation, Overloaded for all those 3 data structures? Assume datatype is Int.
6+
Which algorithmic complexity O(n) should it be? Will it depend on the underlying data structure?
7+
8+
9+
Task 2: Implement a speed optimized function for Task 1, the fastest you can. What algorithmic complexity O(n) should it be ?
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)