logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

write an iterator class (FibonnaciNumberIterator) which allows to iterate over the Fibonnacci numbers (possibly infinitely many …). Fibonacci numbers fib(n) for n=1,2

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Task 1: Iterators & Generators – Fibonacci Numbers (20 Points)

First, write an iterator class (FibonnaciNumberIterator) which allows to iterate over the Fibonnacci numbers (possibly infinitely many …). Fibonacci numbers fib(n) for n=1,2, … are defined as follows: fib(1)=fib(2)=1, fib(n)=fib(n-1)+fib(n-2), for n greater or equal to 3.

Second, write a generator class (FibonacciNumberGenerator) which generates (also possibly infinitely many) Fibonnaci numbers.

Write unit tests for both the iterator and the generator implementations, testing the Fibonnacci numbers for n=1,2,…,10. The tests should, of course, finish in finite time. The tests should assess all methods of the two classes, and should of course test for the correctness of the implementation.

 

Task 2: Recursion & Decorators (20 Points)

First provide a recursive implementation of a function which returns the nth fibonnacci number. This function should be named fib, then fib(1) should return 1, fib(2) should return 1, fib(3) should return 2, and so on (see the definition of the Fibonnaci numbers in Task 1).

Then, implement a decorator function trace (hint: a “higher order function”) which takes a function fun as an argument, calls the function, and both prints the arguments the function fun is called with as well as the value that function fun returns. To make the output more readable, add indentation levels to (recursive) function calls, such that an indented “|-- “ is printed for each recursive call, while increasing the “indentation depth” level by level of the recursion. As a test, use your decorator function, for tracing the function fib.

Then, as an example, fib(5) would result in something like the following output:

|--  fib  5

|     |-- fib 4

|     |     |--  fib  3

|     |     |    |--  fib  2

|     |     |    |    |--  return  1

|     |     |    |--  fib  1

|     |     |    |    |--  return  1

|     |     |    |--  return  2

|     |     |--  fib  2

|     |     |    |--  return  1

|     |     |--  return  3

|     |-- fib 3

|     |     |--  fib  2

|     |     |    |--  return  1

|     |     |--  fib  1

|     |     |    |--  return  1

|     |     |--  return  2

|     |--  return  5 5

In the file that you submit, provide some example output, calling the decorated function fib with exemplary input, e.g. using fib(5) for producing output similar to that shown above.

 

Task 3: OOP Design: Graphs and a simple Graph Generator (20 Points)

A graph generator is a program for generating random graphs (also known as random networks, or social networks) according to some models. A graph consists of nodes and edges. Edges can be undirected and directed. Implement the specific classes in good object-oriented fashion.

A simple strategy for generating graphs is the Erdos-Renyi model. In the Erdos-Renyi model, the number of nodes n is specified, in addition to an edge probability p. Then, in the graph generation, each of all possible edges in the graph are chosen with probability p. Implement a Erdos-Renyi generation strategy using the Strategy Pattern for directed and undirected graphs (each), with a generate method. Provide unit tests for the classes (instantiation), and graph generation, where you test for typical cases and difficult border cases.

For the implementation, you are not allowed to use any graph-/network-specific packages like NetworkX, etc. Numpy and SciPy are allowed.

 

 

Task 4: Optimization – Graph Generation (20 Points)

Another model for graph generation is the Barabasi-Albert model: Here, the network begins with an initial connected network of m’ nodes (initially 1). Then, new nodes are added to the network one at a time, until a maximum number of nodes max_nodes is reached. Each new node is connected to m <= m’ nodes with a probability proportional to the number of links that the existing nodes already have, i.e.

for each node i with a probability pi as follows:

where ki is the degree of node i, and the denominator sums over all the pre-existing nodes j. The degree of a node is the number of connections (edges) it has so far.

 

Implement a Graph-Generator according to the model above which returns the generated graph using the generate method, i.e. implement this in an OOP design using the Strategy Pattern. Optimize your graph generator in at least two different methodological ways (e.g. using functional programming and Numba), and test the impact (using the timeit function). Document that in your IPython Notebook. Provide unit tests for the graph generation, where you test for typical cases and difficult border cases.

For the implementation, you are not allowed to use any graph-/network-specific packages like NetworkX, etc. Numpy and SciPy are allowed.

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

665 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

722 Answers

Hire Me
expert
Husnain SaeedComputer science

832 Answers

Hire Me
expert
Atharva PatilComputer science

796 Answers

Hire Me
June
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30