logo sapienza

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

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


Program

Definition of algorithm, examples of algorithms.

Introduction to complexity. Computation models: Random Access Machine, Pointer Machine, Turing Machine.

Analisys of algorithm's complexity, Landau notations. Intrinsic complexity, lower bound for sorting by comparisons.

Divide and conquer, master theorem. Merge sort, Quick sort, k-selection. K-selection in linear time.

The concept of data structure and its definition as Abstract Data Type. Elementary data structures (lists, stacks, queues, trees).

The dictionary problem (10 hours) Binary search trees, red-black trees, B-Trees, hash tables.

Priority queues, union-find structures. The heap ADT, heap sort algorithm.

Graph algorithms. Depth first and breadth first visits, minimum spanning tree, single source shortest path tree (SSSP), minimum distances between all vertex pairs (APSP). Algorithms for maximum flow problems.

Implementation in Python language of the data structures and algorithms studied.

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 at github under the GNU Free Documentation License

A more advanced textbook on Python, including implementation of algorithms on lists, trees, graphs is:
Basant Agarwal and Benjamin Baka,
Hands-On Data Structures and Algorithms with Python,
second edition
Packt Editor

A portable version of Thonny (a simple and free Python IDE) for Windows, Mac or Linux, including a Python 3 interpreter, can be downloaded here.


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 2021-2022

28 February 2022 2 March 2022
7 March 2022 9 March 2022
14 March 2022 16 March 2022
21 March 2022 23 March 2022
28 March 2022 30 March 2022
4 April 2022 6 April 2022
11 April 2022 13 April 2022
Easter holydays 20 April 2022
holydays 27 April 2022
2 May 2022 4 May 2022
9 May 2022 11 May 2022
16 May 2022 18 May 2022
23 May 2022 25 May 2022

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).

28 September 2022
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 sum, route in a map, sort a sequence, solve a polynomial equation by bisection
Resources Unfortunately, the first part of today's lesson has not been recorded.
  • Introductory lesson given in 2020-2021 is available at this Zoom link Passcode: H42F6ug&
  • the second part of today's lesson is available at this Zoom link Passcode: snTW=e^0
This videos are for personal use only, and are restricted to students of Algorithms and Data Structures course of Statistics Dept., Sapienza.

back to lessons list

2 March 2022
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, lower bound, exact bounds.
  • Containment among simple classes of functions.
  • How to derive complexity: code inspection.
Resources Lesson recording is available at this Zoom link Passcode: @ph+.PV1
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 March 2022
Topics
  • Complexity of algorithms vs. (intrinsic) complexity of problems.
  • Lower bound for minimum/maximum selection, lower bound for comparison-based sorting algorithms
  • Sorting without comparing: examples for sorting n elements in a universe U in Θ(n+|U|)
  • Sorting by comparison in optimal time: Merge Sort
Resources Lesson recording is available at this Zoom link Passcode: ?5JKhmPh
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

9 March 2022
Topics

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

  • using the interpreter
  • variables, expressions, assignments
  • type conversions
  • input() and print() functions
  • the if: ... else: ... statement
  • boolean expressions
  • using Thonny
Resources

Thonny IDE for Windows, Mac or Linux, including a Python interpreter, can be downloaded here.


Lesson recording is available at this Zoom link Passcode: 1^6D#mUW
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 March 2022
Topics

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

  • defining functions with def
  • lists, slicing on sequences
  • while statement
  • for statement: scanning positions vs. scanning elements in a list
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 at this Zoom link Passcode: 6$ZQjz4A
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

16 March 2022
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 at this Zoom link Passcode: ^t7TKw5*
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 March 2022
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).

Code
  • KaratsubaProduct.py
  • mergeSort.py
  • Resources Lesson recording is available at this Zoom link Passcode: yQQj^^%6
    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

    23 March 2022
    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).

    Resources Lesson recording is available at this Zoom link Passcode: 3cQ!U+Cw
    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 March 2022
    Topics

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

    Primitives on pointer based lists: insertion, deletion, search

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

    Resources Lesson recording is available at this Zoom link Passcode: YH9$+8kJ
    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

    30 March 2022
    Topics

    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.

    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.

    Resources Lesson recording is available at this Zoom link Passcode: 9jZC^?93
    the lesson starts at minute 4:30
    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

    4 April 2022
    Topics

    Dictionaries: implementation via lists, sorted lists, arrays, sorted arrays.

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

    for the number of (re)-insertions.

    Resources Lesson recording is available at this Zoom link Passcode: HChU=0C.
    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

    6 April 2022
    Topics

    Resizing the hash table, doubling and halving the table. Amortized analysis

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

    Managing deletions in open probing.

    Trees: basic definitions. Binary trees.

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

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

    Resources Lesson recording is available at this Zoom link Passcode: rr==+iS3
    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

    11 April 2022
    Topics

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

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

    Insertion and deletion in a binary search tree.

    Python implementation of Binary Search Tree.
    Code available in bstFirst.py (some methods must be written).

    Resources Lesson recording is available at this Zoom link Passcode: Np5g*!8t
    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

    13 April 2022
    Topics

    Python implementation of Binary Search Tree with dummy leaves.
    Code available in bstDummy.py (with rank and print_tree methods)

    Resources Lesson recording is available at this Zoom link Passcode: fjNKR7!%
    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

    20 April 2022
    Topics

    Rotations in binary search trees

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

    Resources Lesson recording is available at this Zoom link Passcode: SE7SZ%uY
    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

    27 April 2022
    Topics

    The external memory model of computation: block transfer, I/O efficiency

    B-trees and B*-trees: definition, height bound, searching in a B*-tree

    Insertion and deletion in a B*-tree

    Resources This lesson has not been recorded. Some pdf notes are available here.

    back to lessons list

    2 May 2022
    Topics

    Priority queues. Primitives.

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

    Heaps: definition. Implementation by arrays.

    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 at this Zoom link Passcode: 1#r5HL6z
    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

    4 May 2022
    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 at this Zoom link Passcode: *2*=BUSL
    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

    9 May 2022
    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 at this Zoom link Passcode: $?6g5jwA
    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

    11 May 2022
    Topics

    Graphs: definitions and basic properties

    • Paths, simple paths, walks in a graph
    • 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

    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 at this Zoom link Passcode: zcrh3!Q0
    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

    16 May 2022
    Topics

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

    Pseudocode of 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.

    Python implementations of BFS visit: Graph.py (DFS and the subclass concept will be discussed in next lesson)

    Resources Lesson recording is available at this Zoom link Passcode: 1*7SM99@
    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

    18 May 2022
    Topics

    Subclasses in Python, inheritance

    Python implementations of 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.

    Python implementation of Dijkstra's algorithm: updated version of Graph.py using a min priority queue that implements primitive decrease_priority PriorityQueue.py

    Complexity of Dijkstra's algorithm

    The All Pairs Shortest Paths problem: relation to matrix multiplication.

    Resources Lesson recording is available at this Zoom link Passcode: Q6=x$$pB
    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

    23 May 2022
    Topics

    Minimum spanning tree and minimum spanning forest.

    Definition of cut. The cut rule.

    Prim's algorithm.

    Outline of Kruskal's algorithm. Complexity of Kruskal's algorithm: O(n log n) variant.

    Code is available in Graph.py

    Resources Lesson recording is available at this Zoom link Passcode: n3f?6Dv&
    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

    25 May 2022
    Topics

    Python implementation of Kruskal'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).

    Description and complexity of Boruvka's algorithm

    Basic notions on symmetric and asymmetric cryptography. Digital signatures, public key certificates.

    Resources Lesson recording is available at this Zoom link Passcode: y3&?.tJ?
    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

    -->