Cormen-Lib - An academic tool for data structures and algorithms courses

Overview

Cormen Lib

The Cormen-lib module is an insular data structures and algorithms library based on the Thomas H. Cormen's Introduction to Algorithms Third Edition. This library was made specifically for administering and grading assignments related to data structure and algorithms in computer science.

With this module students can receive progress reports on their problem sets in real time as they complete assignments. Additionally, student submission assessment is done with unit tests, instead of hand-tracing, ensuring that the grades that students receive accurately reflect their submissions.

The Cormen-lib testing suite offers extremely lightweight and flexible unit testing utilities that can be used on any kind of assignment, whether to write functions or build classes. Course administration can be easily streamlined by restricting which library data structures students are allowed to use on any particular assignment.

Cormen-lib began as a project by two Brandeis University undergraduate students to replace hand-written problem sets written in pseudocode.

Provided Data Structures

The Cormen-lib library offers a set of fundamental data structures and algorithms, with behavior as specified by H. Cormen's Introduction to Algorithms. The following structures (separated by module) are supported:

  • arrays
    • Array
    • Array2D
  • queues
    • Queue
  • stacks
    • Stack
  • sets
    • Set
  • linked_lists
    • SinglyLinkedListNode
    • DoublyLinkedListNode
  • trees
    • BinaryTreeNode
    • NaryTreeNode
    • depth(NaryTreeNode)
  • hashing
    • HashTable
  • heaps
    • PriorityQueue
    • build_min_heap(Array)
  • graphs
    • Vertex
    • Graph

Unit Testing

Along with the Cormen-lib data structures come test utilities for writing test cases. The testing framework allows a course administer to easily write test cases for either expected function output or general class behavior. Test cases can then be compiled into a testing suite which runs all test cases. The testing suite has the capability set a test case run-time timeout and two record comma-separated test results for administrative use.

Consider the example test case below:

import unittest
from cormen_lib.factory_utils import make_stack
from cormen_lib.stacks import Stack
from cormen_lib.test_utils import build_and_run_watched_suite, run_generic_test

from student_submission import student_function

# TestCase class for testing student_function
class StudentFunctionTest(unittest.TestCase):

    # A single test case
    def simple_test_case(self):
        stack = make_stack([1, 2, 3])
        expected = make_stack([1, 1, 2, 2, 3, 3])
        run_generic_test(stack, expected, student_function, in_place=True)

# Run the test cases using build_and_run_watched_suite
if __name__ == '__main__':
    build_and_run_watched_suite([StudentFunctionTest], 4)

Installation

Cormen-lib is available on PyPI, and can be installed with pip.

Cormen-lib has the following dependencies:

Python >= 3.6

Issues

We encourage you to report issues using the Github tracker. We welcome all kinds of issues, especially those related to correctness, documentation and feature requests.

Academic Usage

If you are planning to use Cormen-lib for a university course and have questions, feel free to reach out by email.

Comments
  • Addition of a Miscellaneous Utilities Module

    Addition of a Miscellaneous Utilities Module

    Is your feature request related to a problem? Please describe. In some scenarios (e.g. finding a max, initializing graph vertex priorities in Dijkstra's, priority queue insertion) users may want to make use of positive or negative infinity. This also appears in the Cormen textbook. Users may also want to make use of the floor and ceiling mathematical operations.

    Describe the solution you'd like I think a new module should be added to the library that includes (positive) infinity as a constant and implementations of the floor and ceiling operations. I believe the module should be named something like utilities or miscellaneous.

    Describe alternatives you've considered Currently, when building the starter code for a problem set, the math module is imported or an infinity constant is added in the instance where it is known they would be used. However, to allow users to have these capabilities available in any Cormen Lib code they write, these capabilities should be added to the package. This will provide a better Python implementation of the pseudocode used in the Cormen textbook. I believe these capabilities should be added in a new module in the package as they do not belong in any of the existing modules. I do not believe the new module should be called math because additional functions or constants could be added to it (e.g. functions operating on strings).

    Additional context

    enhancement 
    opened by ChamiLamelas 3
  • Feature/update dalpy to string 22

    Feature/update dalpy to string 22

    I updated dalpy_to_string to specify the object name for the following dalpy data structures:

    1. Array
    2. Array2D
    3. Queue
    4. Stack
    5. Set
    6. BinaryTreeNode
    7. NaryTreeNode

    , and added corresponding tests to test_utils_tests.

    Please review my request.

    enhancement 
    opened by wwxiao09 1
  • GraphEdgeError message does not use dalpy_to_string for vertices.

    GraphEdgeError message does not use dalpy_to_string for vertices.

    Describe the bug The GraphEdgeError class does not produce a readable output. This is because the vertices are not displayed properly with their data. An example output:

    dalpy.graphs.GraphEdgeError: graph does not have an edge from a vertex with name <dalpy.graphs.Vertex object at 0x7faa24830340> to a vertex with name <dalpy.graphs.Vertex object at 0x7faa24833670>

    To Reproduce Steps to reproduce the behavior:

    1. g = Graph()
    2. v1 = Vertex("a")
    3. v2 = Vertex("b")
    4. g.add_vertex(v1)
    5. g.add_vertex(v2)
    6. g.weight(v2, v1)
    7. Observe the error message.

    Expected behavior The output should display the Vertex objects using the data of the vertex.

    enhancement 
    opened by EitanJoseph 1
  • Fix misaligned PriorityQueue runtimes

    Fix misaligned PriorityQueue runtimes

    Is your feature request related to a problem? Please describe. Currently, PriorityQueue is backed by a sorted list. Therefore, the actual runtimes of DALPy PriorityQueue functions is misaligned with their assumed runtimes.

    Describe the solution you'd like PriorityQueue should be reimplemented using Python's base library heapq with a custom decrease_key function that mantains O(log(n)) runtime.

    documentation 
    opened by EitanJoseph 1
  • Changes to HashTable and Set

    Changes to HashTable and Set

    Is your feature request related to a problem? Please describe. Currently there is no way to iterate over the keys of a HashTable.

    Also, I believe that Set should operate more like a mathematical set versus a Java/Python set. That is, modification to the Set should be done via difference and union operations with other Sets.

    Describe the solution you'd like One should be able to get either get the keys (have HashTable have a function that returns a collection of them) or be able to iterate over the keys (e.g. for k in t).

    In regard to Set, add() should be removed and replace with union() which takes a Set. That way, Set will operate more how you would use it in pseudocode:

    S = S U {1}
    T = T - {2}
    S = S U T
    

    Describe alternatives you've considered To iterate over a HashTable now, the keys must be stored in an external data structure like an Array or Set. I also think it is best that iteration is kept to over keys to avoid confusion with tuples (like the behavior of Python dict's items()).

    For Sets the alternative is to keep add() (and possible inclue a remove()) but those operate on single elements. Since singleton Sets can be easily created, I think it is suitable to use union and difference operations in their place.

    Additional context None

    enhancement 
    opened by ChamiLamelas 1
  • Giving clear hint of the renaming

    Giving clear hint of the renaming

    Is your feature request related to a problem? Please describe. Yes it is a problem. I was installing cormen-lib today and found my code not working at all. The import cormen_lib statement threw an ModuleNotFoundError to me which led me to troubleshoot on my Python installation. After 20 minutes of configuring and reinstalling cormen-lib and Python and even my IDE back and forth, I finally saw your PyPI page and realized that the project was renamed.

    Describe the solution you'd like Giving clear hints of the renaming is much better, instead of removing all the code under the name cormen_lib and throwing ModuleNotFoundError. We could have a print statement in cormen_lib.py: print('cormen_lib is renamed to dalpy. See https://github.com/DALPy-Developers/DALPy for detail'), as well as all the names of the classes in the library. When users try to import something from cormen_lib (e.g. running their previous homework), they would know what to do to solve it.

    bug 
    opened by Zeng-Lecheng 1
  • cormen_equals and copy_stack throwing error when applied to two Stacks

    cormen_equals and copy_stack throwing error when applied to two Stacks

    Describe the bug Stack equality using cormen_equals has a bug. The __stack_equals method uses copy_stack from factory_utils which does not properly copy a stack's contents, and always throws an error stating that "one can not pop from an empty stack" unless the input stack is empty.

    To Reproduce Steps to reproduce the behavior:

    1. Create a Stack with more than one element.
    2. Call cormen_equals on that Stack with itself.
    3. See error

    Expected behavior The cormen_equals method should return true if the contents of the Stacks are equal and false otherwise.

    Solution See line 43 of the factory_utils module - it should store s.pop() in a variable and push it to the buf Stack twice.

    bug 
    opened by EitanJoseph 1
  • Enforcing No Argument Modification in Testing Utilities

    Enforcing No Argument Modification in Testing Utilities

    Is your feature request related to a problem? Please describe. For problems that require students to write functions, we sometimes want to impose that the students' functions should not modify some or all of their arguments. To currently enforce this, a copy needs to be made of the arguments that aren't meant to be modified before running the students' function. Then, after the function is run, the copy needs to be compared to the arguments that were passed to the function. This occurs in cases where the arguments are data structures of some kind (e.g. Array, Stack, etc.).

    Describe the solution you'd like Since this process is easily generalizable, I believe that this should be added to the testing utilities. In particular, it could be added to the run_generic_test function.

    The first question is how the user should specify which arguments should be checked for modification. This could be specified in a parameter enforce_no_mod:

    • By default, enforce_no_mod is False indicating that all of the arguments can be modified.
    • If enforce_no_mod is True, then none of the arguments can be modified and should all be checked.
    • Lastly, enforce_no_mod can be a list of bool of equal length to the existing params parameter. enforce_no_mod[i] = True means params[i] should be checked for modification. enforce_no_mod[i] = False means that it should not.

    The second question is how run_generic_test will know how to copy any arguments that need to be checked. This can be specified by a list copy_fns such that copy_fns[i] is a function that can be used to make a copy of params[i]. Since params can be a single value (i.e. not a list), it may be good to allow copy_fns to be a single function also. This should be provided a default value as to not have to change existing testing code (None is sufficient).

    The third question is how run_generic_test will know how to compare the argument passed to the students' function and its copy. This also can be specified by a parameter copy_eqs_fns that operates in a similar manner to copy_fns except where copy_eqs_fns[i], in the instance it's a list, is a function that checks the equality of params[i] to its copy. This should be provided a default value as to not have to change existing testing code (None is sufficient).

    Describe alternatives you've considered The alternative is the current process described in my answer to the first prompt.

    Additional context

    enhancement 
    opened by ChamiLamelas 1
  • Add a warning when students return a value from a function being evaluated with in-place=True

    Add a warning when students return a value from a function being evaluated with in-place=True

    Is your feature request related to a problem? Please describe. Some problems may take a data structure as input, passed by reference, to be updated by a function implemented by a student. In these situations, test_utils.run_generic_test offers an optional parameter in_place that if set to True causes the test case to compare the expected against the input parameter. Any returned value from the tested function will then get discarded, which can cause confusion for students who believe that the function should have a return type.

    Describe the solution you'd like In the case that a student has a function return a non-None value when the in_place flag is set to True, a warning could appear to indicate to the student that they should be updating the input parameter by reference instead of returning a new value. Another option could be to allow for the distinction between a "return comparator" and "parameter comparator", which both need to be satisfied. This could also be used for the dual purpose of ensuring that an input data structure is not altered when it should not be (for example the accidental destruction of a queue).

    Describe alternatives you've considered The only way to clarify this at the moment is to add a note to the problem description (in English) explaining that the input should be updated, and no return type is required for such problems.

    Additional context Reported by a student in Brandeis University COSI21a of Spring 2022

    enhancement 
    opened by EitanJoseph 1
  • Enhancement/dalpy to string for vertices 24

    Enhancement/dalpy to string for vertices 24

    1. Updated GraphEdgeError class: used get_name() in the output string to produce a readable output and updated its documentation.
    2. Added test_GraphEdgeError() to graph_tests.
    3. Slightly modified GraphVertexError class: added " " to the name of the vertex in the output string.
    opened by wwxiao09 0
  • Fixed PriorityQueue Runtimes + other adjustments

    Fixed PriorityQueue Runtimes + other adjustments

    removed assume runtimes, replaced with runtimes stated everywhere; updated heaps to have correct runtime; updated graphs to have O(1) edge addition; added nwe heaps test

    check if we should make comment about heap insert degrading from O(logn) -> O(n) upon list resize

    documentation 
    opened by ChamiLamelas 0
Owner
Cormen Lib
Developers of the Cormen Lib academic Python library.
Cormen Lib
Minimal examples of data structures and algorithms in Python

Pythonic Data Structures and Algorithms Minimal and clean example implementations of data structures and algorithms in Python 3. Contributing Thanks f

Keon 22k Jan 9, 2023
:computer: Data Structures and Algorithms in Python

Algorithms in Python Implementations of a few algorithms and datastructures for fun and profit! Completed Karatsuba Multiplication Basic Sorting Rabin

Prakhar Srivastav 2.9k Jan 1, 2023
zoofs is a Python library for performing feature selection using an variety of nature inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics based to Evolutionary. It's easy to use ,flexible and powerful tool to reduce your feature size.

zoofs is a Python library for performing feature selection using a variety of nature-inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics-based to Evolutionary. It's easy to use , flexible and powerful tool to reduce your feature size.

Jaswinder Singh 168 Dec 30, 2022
Genetic algorithms are heuristic search algorithms inspired by the process that supports the evolution of life.

Genetic algorithms are heuristic search algorithms inspired by the process that supports the evolution of life. The algorithm is designed to replicate the natural selection process to carry generation, i.e. survival of the fittest of beings.

Mahdi Hassanzadeh 4 Dec 24, 2022
Code for generating alloy / disordered structures through the special quasirandom structure (SQS) algorithm

Code for generating alloy / disordered structures through the special quasirandom structure (SQS) algorithm

Bruno Focassio 1 Nov 10, 2021
A command line tool for memorizing algorithms in Python by typing them.

Algo Drills A command line tool for memorizing algorithms in Python by typing them. In alpha and things will change. How it works Type out an algorith

Travis Jungroth 43 Dec 2, 2022
Nature-inspired algorithms are a very popular tool for solving optimization problems.

Nature-inspired algorithms are a very popular tool for solving optimization problems. Numerous variants of nature-inspired algorithms have been develo

NiaOrg 215 Dec 28, 2022
Repository for data structure and algorithms in Python for coding interviews

Python Data Structures and Algorithms This repository contains questions requiring implementation of data structures and algorithms concepts. It is us

Prabhu Pant 1.9k Jan 1, 2023
Planning Algorithms in AI and Robotics. MSc course at Skoltech Data Science program

Planning Algorithms in AI and Robotics course T2 2021-22 The Planning Algorithms in AI and Robotics course at Skoltech, MS in Data Science, during T2,

Mobile Robotics Lab. at Skoltech 6 Sep 21, 2022
Python Client for Algorithmia Algorithms and Data API

Algorithmia Common Library (python) Python client library for accessing the Algorithmia API For API documentation, see the PythonDocs Algorithm Develo

Algorithmia 138 Oct 26, 2022
Solving a card game with three search algorithms: BFS, IDS, and A*

Search Algorithms Overview In this project, we want to solve a card game with three search algorithms. In this card game, we have to sort our cards by

Korosh 5 Aug 4, 2022
My dynamic programming algorithms for exercise and fun

My Dynamic Programming Algorithms giraycoskun [email protected] It is a repo for various dynamic programming algorithms for exercise.

Giray Coskun 1 Nov 13, 2021
CLI Eight Puzzle mini-game featuring BFS, DFS, Greedy and A* searches as solver algorithms.

?? Eight Puzzle CLI Jogo do quebra-cabeças de 8 peças em linha de comando desenvolvido para a disciplina de Inteligência Artificial. Escrito em python

Lucas Nakahara 1 Jun 30, 2021
Algorithms and utilities for SAR sensors

WARNING: THIS CODE IS NOT READY FOR USE Sarsen Algorithms and utilities for SAR sensors Objectives Be faster and simpler than ESA SNAP and cloud nativ

B-Open 201 Dec 27, 2022
Distributed algorithms, reimplemented for fun and practice

Distributed Algorithms Playground for reimplementing and experimenting with algorithms for distributed computing. Usage Running the code for Ring-AllR

Mahan Tourkaman 1 Oct 16, 2022
Classic algorithms including Fizz Buzz, Bubble Sort, the Fibonacci Sequence, a Sudoku solver, and more.

Algorithms Classic algorithms including Fizz Buzz, Bubble Sort, the Fibonacci Sequence, a Sudoku solver, and more. Algorithm Complexity Time and Space

null 1 Jan 14, 2022
Sorting-Algorithms - All information about sorting algorithm you need and you can visualize the code tracer

Sorting-Algorithms - All information about sorting algorithm you need and you can visualize the code tracer

Ahmed Hossam 15 Oct 16, 2022
BCI datasets and algorithms

Brainda Welcome! First and foremost, Welcome! Thank you for visiting the Brainda repository which was initially released at this repo and reorganized

null 52 Jan 4, 2023
All Algorithms implemented in Python

The Algorithms - Python All algorithms implemented in Python (for education) These implementations are for learning purposes only. Therefore they may

The Algorithms 150.6k Jan 3, 2023