logo sapienza

Algorithms and Data Structures
Master degree in Statistical Methods and Applications
academic year 2020-2021

Teacher: Paolo Franciosa
6 CFU


Lessons can be attended on Zoom at this link during lesson time.
Students are kindly required to log in using Sapienza credentials (....@studenti.uniroma1.it).

Contents Program Teaching material
Lessons timetable Exams and sample tests
Lessons topics and resources

Contents

The course covers algorithmic programming techniques. The primary goal is to study algorithms and data structures that efficiently solve problems that would require very high computational resources (time or space) using trivial approaches.

We will address problems frequently arising in practical applications and real-world situations, such as sorting, searching, and graph traversal, as well as general design techniques including divide and conquer, greedy algorithms, and dynamic programming.

The course will cover the entire algorithm engineering cycle, addressing the design, theoretical analysis, implementation, and experimental evaluation of algorithms and data structures. The students will practice solving computational problems, designing new algorithms, and implementing efficient solutions in Python.

top


top


Texts

Introduction to the Design and Analysis of Algorithms
Anany Levitin, Pearson

resources are available on the web, an alternative textbook is
Algorithms Design, by Goodrich and Tamassia

A more comprehensive text is:
Introduction to Algorithms
T. Cormen, C. Leiserson, R. Rivest, and C. Stein, McGraw-Hill.

top

An introductory textbook on Python is:
Allen Downey,
Thinking in Python - How to Think Like a Computer Scientist,
second edition
pdf available on github under the GNU Free Documentation License


Exams

The exam consists in a written test, a programming exercise, and possibly a colloquium.

Samples of exam tests are available in this zipped folder

top


Lessons 2020-2021

22 February 2021 24 February 2021
1 March 2021 3 March 2021
8 March 2021 lesson is cancelled 10 March 2021
15 March 2021 17 March 2021
22 March 2021 24 March 2021
29 March 2021 31 March 2021 lesson is cancelled
Easter holydays 7 April 2021
12 April 2021 14 April 2021
19 April 2021 21 April 2021
26 April 2021 28 April 2021
3 May 2021 5 May 2021
10 May 2021 12 May 2021
17 May 2021 19 May 2021
24 May 2021

For any need, contact me at
paoloA_DOT_HEREfranciosaAN_"at"_HEREuniroma1A_DOT_HEREit

top


Lessons are available on Zoom at this link during lesson time.
Please log in using Sapienza credentials (....@studenti.uniroma1.it).

22 September 2021
Topics
  • Introduction, material -- book, software -- exams
  • Definitions: problem, instance, algorithm
  • The concepts of "resource", "executor", "operation"
  • Models of computation: RAM vs Pointer Machine
  • Examples: find maximum, check duplicates
Resources Lesson recording is available on this Zoom link Passcode: H42F6ug&
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

24 September 2021
Topics
  • Deriving the complexity of an algorithm: exact evaluation, best case, worst case
  • Examples: find maximum, check duplicates
  • Landau notations (O, Omega, Theta) to express complexity.
  • Complexity of an algorithm: upper bound, exact bounds.
  • Containment among simple classes of functions.
  • How to derive complexity: code inspection.
Resources Lesson recording is available on this Zoom link Passcode: !7A$Mw1a
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

1 March 2021
Topics
  • Complexity of algorithms vs. (intrinsic) complexity of problems.
  • Lower bound for minimum/maximum selection, lower bound for comparison-based sorting algorithms
Resources Lesson recording is available on this Zoom link Passcode: =*!PcZ7q
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

3 March 2021
Topics

A brief introduction to Python language (see here for a basic textbook on Python)

  • using the interpreter
  • variables, expressions, assignments
  • type conversions
  • input() and print() functions
  • using Thonny
Resources A portable version of Thonny for Windows, including a Python interpreter, can be downloaded here.
Just unzip the thonny-3.zip compressed folder and execute file thonny.exe

Lesson recording is available on this Zoom link Passcode: ?i.0TaRu
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

10 March 2021
Topics

A brief introduction (II) to Python language (see here for a basic textbook on Python)

  • precedence between operators
  • conditional statements, boolean expressions and operators
  • lists, slicing on sequences
  • while statement
  • input() and print() functions
  • defining functions with def
  • exercises:
    • find maximum between 3 numbers
    • primality test in O(n) e O(√n)
Resources A portable version of Thonny for Windows, including a Python interpreter, can be downloaded here.
Just unzip the thonny-3.zip compressed folder and execute file thonny.exe

Lesson recording is available on this Zoom link Passcode: D^^q0+mF
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

15 March 2021
Topics

Divide and Conquer. Recursive implementation of D&C algorithms. Identify base cases, build subinstances, recursive calls, combine subsolutions.

Complexity of & algorithms: recurrence equations.

Master Theorem

Integer multiplication, matrix multiplication (Strassen algorithm)

Sorting via D&C: Merge Sort.

Resources Lesson recording is available on this Zoom link Passcode: &RE8NVU@
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

17 March 2021
Topics

A brief introduction (III) to Python language (see here for a basic textbook on Python)

  • for loop
  • range()

Examples of recursive algorithms in Python

Resources Lesson recording is available on this Zoom link Passcode: !Gq?Djy4
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

22 March 2021
Topics

Quick sort, analysis of quick sort: best case, worst case (find the code of Quick sort here).

Randomized Quick Sort: analysis of average case.

Quick sort vs. Merge sort: stability, in-place

k-th element selection algorithm, complexity analysis(find the code of k-selection here).

Resources Lesson recording is available on this Zoom link Passcode: J66A30.l
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

24 March 2021
Topics

Linear time k-th element selection algorithm, (Blum et al., 1973)

The concept of Abstract Data Type. Information hiding.

Introduction to OO programming in Python.

Implementation of a simple class Number_set (find it in numModule.py), with an example of use (find it in useNumberSet.py).

complexity analysis(find the code of k-selection here).

Pointer based structures: linked lists vs. Python lists (arrays)

Resources Lesson recording is available on this Zoom link Passcode: &27%syUW
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

29 March 2021
Topics

Primitives on pointer based lists: insertion, deletion, search

Python implementation of linked lists linkedListClass.py. Use of linked lists in useLinkedList.py

Last In First Out (LIFO) and First In First Out (FIFO) policies: Stacks and Queues

Implementation of a stack by a linked list StackModule.py.

Resources Lesson recording is available on this Zoom link Passcode: yd@8kUsr
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

7 April 2021
Topics

Implementation of a queue (FIFO) by a linked list QueueModule.py, uses class headTailLinkedListClass.py.

Implementation of arrays, map functions for uni-dimensional and bi-dimensional arrays.

Dictionaries: time vs. space tradeoffs, trivial mapping from key to integers.

Hash tables: definition, INSERT/SEARCH/DELETE operations. Hash functions, collisions. External chaining

Resources Lesson recording is available on this Zoom link Passcode: q&Qn5ff6
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.
12 April 2021
Topics

Hash tables: external chaining vs open probing. Sequential/linear probing, quadratic probing, double hashing.

Managing deletions in open probing.

Resizing the hash table, doubling and halving the table. Amortized analysis for the number of (re)-insertions.

Trees: basic definitions. Binary trees.

Binary search trees: definition, searching in a binary search tree.

Resources Lesson recording is available on this Zoom link Passcode: NayY3w@#
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

14 April 2021
Topics

Binary tree visits: pre-order, in-order. post-order visits

Height of a binary tree: worst case and best case. Complete binary trees.

Max, min, predecessor and successor search in binary search trees.

Insertion and deletion in a binary search tree.

Resources Lesson recording is available on this Zoom link Passcode: B@6N7u$s
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

19 April 2021
Topics

Python implementation of Binary Search Tree.
Code available in bstNoRank.py (rank and print_tree methods must be written).

The implementation in bstNoRank.py must be modified as follows:

  • nodes of the BST contain both a "key" value and an "info" value;
  • items are organized according to the "key" value;
  • insert operation has three parameters (self, key, info);
  • search operation has only the (self, key) parameters, and returns the "info" value associated to "key";
  • Delete operation has only (self, key) parameters;
  • Rank operation has to be written;
  • Print_tree operation has to be written.

Resources Lesson recording is available on this Zoom link Passcode:$1Z5dU8G
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

21 April 2021
Topics

Representing binary search trees with dummy leaves. An implementation is available in bstDummy.py

Rotations in binary search trees

Balanced trees: red-black trees. Definitions, insertions. Worst case performances.

Resources Lesson recording is available on this Zoom link Passcode:e+z13x1Y
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

26 April 2021
Topics

Priority queues. Primitives.

Complexity of priority queues primitives on linked lists or balanced search trees

Heaps: definition. Insertion and pop_max operations. Complexity.

Implementation of heapify.

Building a heap in O(n) time

An implementation is available in prioritySimple.py

An example of use is in UsePrioritySimple.py

Resources Lesson recording is available on this Zoom link Passcode:2aAUgAn#
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

28 April 2021
Topics

Implementation of heaps, with O(n) make_heap priority.py

Algorithm heap sort. Complexity analysis of heap sort. Implementation available in heapSort.py

Animation of several sorting algorithms can be seen at https://www.toptal.com/developers/sorting-algorithms

Resources Lesson recording is available on this Zoom link Passcode:C1+5CaS1
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

3 May 2021
Topics

Graphs: definitions and basic properties

  • directed, undirected
  • sparse vs dense graphs
  • multigraph
  • subgraph, induced subgraph
  • path, cycle, clique, bipartite, complete bipartite
  • planar graph, embedding, faces
  • characterization of planar graphs (Kuratowsky theorem)
  • relation among the number of vertices, edges and faces of a (connected) planar graph
Resources Lesson recording is available on this Zoom link Passcode:$hPMd&a9
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

5 May 2021
Topics

Graphs: definitions and basic properties

  • transitive closure of a relation: reachability (directed, undirected) as transitive closure of edges
  • connected graph, connected components
  • directed graphs: strongly connected components
  • acyclic graphs, DAGs, DAG of strongly connected components
  • trees, forests
  • number of edges in a tree
  • spanning trees
Resources Lesson recording is available on this Zoom link Passcode:6=PH4n@=
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

10 May 2021
Topics

Paths, simple paths, walks in a graph

Graphs traversals: Depth First search (DFS) and Breadth First search (BFS)

Pseudocode of DFS and BFS

DFS trees and BFS tree, BFS trees as Single Source Shortest Path (SSSP) trees for unweighted graphs.

Hamiltonian paths and Eulerian tours/paths: definitions.

Existence of Eulerian tours/paths by vertices degrees.

Complexity theory: definition of classes P and NP. The P vs NP conjecture.

Resources Lesson recording is available on this Zoom link Passcode:DdkJ0+r3
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

12 May 2021
Topics

Dictionaries in Python

Representing graphs: adjacency matrix vs. adjacency lists.

A Python class implementing graphs by dictionaries: basic version in basicGraphs.py

Exercise: add methods for deleting vertices or edges

Resources Lesson recording is available on this Zoom link Passcode:?1P2JbE?
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

17 May 2021
Topics

Subclasses in Python, inheritance

Python implementations of BFS visit and DFS visit: Graph.py

See the recursive implementation of DFS visit and DFS tree in Graph.py

Single source shortest path trees for non-negative weighted graphs: Dijkstra algorithm.

Resources Lesson recording is available on this Zoom link Passcode: du.2+x#D
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

19 May 2021
Topics

Python implementation of Dijkstra's algorithm: updated version of Graph.py

using a min priority queue that implements primitive decrease_priority PriorityQueue.py

Minimum spanning tree and minimum spanning forest.

Definition of cut. The cut rule.

Prim's algorithm.

Outline of Kruskal's algorithm and Boruvka's algorithm.

Resources Lesson recording is available on this Zoom link Passcode: HQ0Ri4*e
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

24 May 2021
Topics

Python implementation of Prim's algorithm for minimum spanning forest: Graph.py

Complexity analysis of Kruskal's algorithm

Python implementation of Kruskal's algorithm for minimum spanning forest (same Python source code as above).

Resources Lesson recording is available on this Zoom link Passcode: 2$M&bA$@
this video is for personal use only, and is restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

-->