logo sapienza

Algorithms and Data Structures
Master degree in Statistical Methods and Applications
academic year 2023-2024

Teacher: Paolo Franciosa
6 CFU


Contents Program Teaching material
Lessons timetable Lessons topics and resources

Lessons will be in presence and will start on Monday, February 26th 2024,
with the following calendar:
Monday 10:00-12:00 in room V (building CU002, fourth floor),
Wednesday 10:00-12:00 in room XII (building CU007, ground floor).


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

Hand-written slides on some parts of the course (not covering all topics) can be found here

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 2023-2024

Monday Wednesday
February 26, 2024 February 28, 2024
March 4, 2024 March 6, 2024
March 11, 2024 March 13, 2024
March 18, 2024 March 20, 2024
March 25, 2024 March 27, 2024
cancelled
April 1, 2024
Easter holydays
April 3, 2024
April 8, 2024 April 10, 2024
April 15, 2024 April 17, 2024
April 22, 2024 April 24, 2024
April 29, 2024
cancelled
May 1, 2024
holyday
May 6, 2024 May 8, 2024
May 13, 2024 May 15, 2024
May 20, 2024 May 22, 2024
May 27, 2024 May 29, 2024

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

top


February 26, 2024
Topics
  • Introduction, material -- book, software -- exams
  • Definitions: problem, instance, algorithm
  • The concepts of "resource", "executor", "operation"
  • Examples: find max, check duplicates, subset sum, route finding
  • The Russian Peasant multiplication algorithm

back to lessons list

February 28, 2024
Topics
  • Models of computation: RAM vs Pointer Machine
  • Example: sorting on RAM vs. sorting on Pointer Machine
  • The Turing machine, computability
  • Deriving the complexity of an algorithm: exact evaluation, best case, worst case
  • Examples: find maximum, check duplicates
  • How to derive complexity: code inspection.

back to lessons list

March 4, 2024
Topics
  • Landau notations (O, Ω, Θ) to express complexity.
  • Complexity of an algorithm: upper bound, lower bound, exact bounds.
  • Containment among simple classes of functions.
  • Complexity of algorithms vs. (intrinsic) complexity of problems.
  • Sorting without comparing: examples for sorting n elements in a universe U in Θ(n+|U|) time and Θ(|U|) space
Slides for this and next lecture can be found here

back to lessons list

March 6, 2024
Topics
  • Lower bound for minimum/maximum selection, lower bound for comparison-based sorting algorithms
  • Divide and Conquer. Recursive implementation of D&C algorithms. Identify base cases, build subinstances, recursive calls, combine subsolutions.
  • Complexity of & algorithms: recurrence equations.

back to lessons list

March 11, 2024
Topics
  • Master Theorem
  • Integer multiplication, Karatsuba's algorithm
  • Matrix multiplication, Strassen algorithm
  • Sorting via Divide & Conquer: Merge Sort.
  • Complexity analysis of Merge sort (find the code of Merge Sort here)

back to lessons list

March 13, 2024
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

Sorting algorithms animation https://www.toptal.com/developers/sorting-algorithms

Code
  • KaratsubaProduct.py
  • mergeSort.py
  • back to lessons list

    March 18, 2024
    Topics

    Find here a code showing quick sort behaviour.

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

    Worst case linear time k-th element selection algorithm, Median of Medians (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).

    back to lessons list

    March 20, 2024
    Topics

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

    back to lessons list

    March 25, 2024
    Topics

    The dictionary problem: time vs. space tradeoffs, trivial mapping from key to integers.

    Implementation using lists, sorted lists, arrays, sorted arrays.

    Efficiency of the in operator on Python list and Python dict

    Sample code used by useSequence.py

    1. an implementation using list: moduleSequence.py
    2. an implementation using dict: moduleSequenceSmart.py
    3. an implementation using set: moduleSequenceSet.py

    back to lessons list

    April 3, 2024
    Topics

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

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

    back to lessons list

    April 8, 2024
    Topics

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

    Managing deletions in open probing.

    Cryptographic hash functions. Finding collisions by brute force

    back to lessons list

    April 10, 2024
    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

    back to lessons list

    April 15, 2024
    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 module headTailLinkedListClass.py.

    back to lessons list

    April 17, 2024
    Topics

    Rooted trees: basic definitions. Binary trees.

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

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

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

    back to lessons list

    April 22, 2024
    Topics

    Searching in binary search trees.

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

    Balanced trees with respect to size or height. Fibonacci trees

    back to lessons list

    April 24, 2024
    Topics

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

    Rotations in binary search trees

    Red-black trees: definition, height of a red-black tree.

    back to lessons list

    May 6, 2024
    Topics

    Rotations in binary search trees

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

    Priority queues. Primitives.

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

    Heaps: definition. Get_min and Insert operation

    Heaps: Pop_min operation, complexity of delete_min.

    Implementation of heaps by lists

    back to lessons list