, ,

[SOLVED] Comp2521 24t3 – assignment 1

$25

File Name: Comp2521_24t3_-_assignment_1.zip
File Size: 263.76 KB

5/5 - (1 vote)

COMP2521 24T3 – Assignment 1

  1. Assignment Overview

    image Course Information: COMP2521 24T3, Data Structures and Algorithms course, School of Computer Science and Engineering, University of New South Wales

    image Assignment Contribution: Contributes 15% to the final grade

    image Submission Requirements

    image Deadline: 8 pm on Monday of Week 7

    image Files to Submit: Mset.c, MsetStructs.h, and analysis.txt

    image Submission Method: Command line ($ give cs2521 ass1 Mset.c MsetStructs.h analysis.txt) or give’s web interface

    image Notes: Multiple submissions are allowed, and only the last one will be marked. Check after submission.

    image Grading Criteria

    image Correctness (75%)

    image Includes the correctness of basic operations (such as insertion, deletion, getting size, getting total count, getting element count, printing, etc.) and advanced operations (such as union, intersection, inclusion check, equality check, getting most common elements, etc.), as well as the correctness of related operations after updating the balanced binary search tree and cursor operations.

    image Each operation has a corresponding score percentage, and there will be deductions for memory errors/leaks.

    image Complexity Analysis (15%): The correctness of the complexity analysis in analysis.txt and the quality of explanations.

    image Code Style (10%): Evaluation includes indentation, space usage, function usage, code decomposition, and comments.

  2. Assignment Content

    1. Multiset Abstract Data Type (ADT)

      Definition

      image A collection that allows duplicate elements, where each element has a count indicating the number of times it appears in the collection.

      image It is an abstract data type, and the focus is on the set of operations. The implementation

      details are not important as long as the desired behavior is presented to the user.

      Operation Requirements

      image Basic Operations (Part 1)

      image MsetNew: Creates a new empty Multiset with a time complexity requirement of O(1). image MsetFree: Frees all memory allocated to the Multiset with a time complexity of O(n). image MsetInsert: Inserts one element into the Multiset. If the element is equal to

      UNDEFINED, nothing is done. The time complexity is O(h).

      image MsetInsertMany: Inserts a given number of elements. If the element is equal to UNDEFINED or the number is 0 or less, nothing is done. The time complexity is O(h).

      image MsetDelete: Deletes one element from the Multiset with a time complexity of O(h).

      image MsetDeleteMany: Deletes a given number of elements with a time complexity of O(h).

      image MsetSize: Returns the number of distinct elements in the Multiset with a time complexity of O(1).

      image MsetTotalCount: Returns the sum of the counts of all elements in the Multiset with a time complexity of O(1).

      image MsetGetCount: Returns the count of an element in the Multiset. If the element is not in the Multiset, it returns 0. The time complexity is O(h).

      image MsetPrint: Prints the Multiset to a file. The elements are sorted in ascending order and in the format of {(element, count),…} . The time complexity is O(n).

      image Advanced Operations (Part 2)

      image MsetUnion: Given two Multisets, returns their union. The count of each element in the new Multiset is the maximum of its counts in the two original Multisets. The time complexity needs to be analyzed and written in analysis.txt. Methods like converting the tree to an array or list and then processing are not allowed.

      image MsetIntersection: Given two Multisets, returns their intersection. The count of each element in the new Multiset is the minimum of its counts in the two original Multisets. The time complexity needs to be analyzed and written in analysis.txt, and certain processing methods are prohibited.

      image MsetIncluded: Given two Multisets, determines if one is included in the other based on element counts. The time complexity needs to be analyzed and written in analysis.txt, and certain processing methods are prohibited.

      image MsetEquals: Given two Multisets, determines if they are equal based on whether the elements and counts are exactly the same. The time complexity needs to be analyzed and written in analysis.txt, and certain processing methods are prohibited.

      image MsetMostCommon: Given a Multiset, an integer, and an array, stores the most common elements in the Multiset in descending order of count into the array and returns the number of elements stored. The time complexity needs to be analyzed and written in analysis.txt.

      image Balanced Binary Search Tree (Part 3)

      image Update the implementation to use a height-balanced binary search tree so that MsetInsert, MsetInsertMany, MsetDelete, and MsetDeleteMany have a worst-case time complexity of O(logn), and ensure that the underlying binary search tree of any Multiset is always height-balanced.

      image Cursor Operations (Part 4)

      image MsetCursorNew: Creates a new cursor for a given Multiset, initially positioned at the start of the Multiset.

      image MsetCursorFree: Frees all memory allocated to a given cursor.

      image MsetCursorGet: Returns the element at the cursor’s position and its count. If the cursor is at the start or end of the Multiset, it returns {UNDEFINED, 0}.

      image MsetCursorNext: Moves the cursor to the next largest element. If there is no next largest element, it moves to the end of the Multiset. If the cursor is already at the end, it does not move. Returns false if the cursor is at the end after the operation, otherwise returns true.

      image MsetCursorPrev: Moves the cursor to the next smallest element. If there is no next smallest element, it moves to the start of the Multiset. If the cursor is already at the start, it does not move. Returns false if the cursor is at the start after the operation, otherwise returns true.

      image All cursor operations should have a worst-case time complexity of O(1) or O(logn). The design and implementation and how the time complexity requirement is met need to be explained in analysis.txt.

    2. Assignment File Description

      Initial Files

      image Makefile: A set of dependencies used to control compilation.

      image Mset.h: The interface to the Multiset ADT, which cannot be modified.

      image Mset.c: The implementation of the Multiset ADT (initially incomplete).

      image MsetStructs.h: The definition of structs used in the Multiset ADT (initially incomplete).

      image testMset.c: A main program containing some basic tests for the Multiset ADT.

      image analysis.txt: A template for entering the time complexity analysis of selected functions.

      Struct Usage Requirements

      image Must use struct node for binary search tree nodes.

      image The elements of the multiset must be stored in the elem fields of struct node , and their counts must be stored in the count fields.

      image The left and right pointers are used to connect a tree node to its left and right subtrees

      and cannot be used for other purposes.

      image The tree field must point to the binary search tree that stores all the elements of the multiset.

    3. Testing and Debugging

      image Testing

      image The testMset.c is provided as a basic test program. It can be compiled by make and run by ./testMset .

      image The tests are assertion-based, and a failed test will cause the program to exit. A test can be

      ignored by commenting out the corresponding test function.

      image It is recommended to add your own test functions.

      image Debugging

      image Students are expected to know basic debugging methods, such as using print statements, basic GDB commands, and running Valgrind.

      image The use of GDB and Valgrind can be learned in relevant lab exercises.

  3. Background Knowledge

Prerequisite Knowledge Requirements: Recursion, analysis of algorithms, abstract data types, binary search trees, balanced binary search trees (including AVL trees)

Multiset Related Concepts

image Similar to the concept of a set but allows duplicate elements, and each element has a count. image It can be represented in the form of elements and their counts enclosed in curly braces,

such as {(1, 3), (4, 2)} , indicating that element 1 appears 3 times and element 4

appears 2 times.

image Related symbolic notations are defined, such as cA(x) representing the count of element

x in multiset A , and if x is not in A , then cA(x)=0 . The empty multiset is denoted by

.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Comp2521 24t3 – assignment 1
$25