Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Homework 2 : First Unique Number in Data Stream Design and implement a data structure for efficiently tracking the first unique number in a data
Homework : First Unique
Number in Data Stream
Design and implement a data structure for
efficiently tracking the first unique number in a
data stream.
Submission Deadline: March at : PM
Challenge Overview
In many realworld applications, such as network data monitoring or sales
tracking, identifying unique events or items dynamically as data continuously
arrives is crucial. This assignment focuses on designing and implementing a
data structure that efficiently tracks the first unique number in a stream of
nonnegative integers. Your task is to implement a system capable of adding
numbers to the stream and identifying the first unique number at any moment.
Problem Statement
Your implementation should support two primary operations:
addnumber: Adds a number to the data stream.
showFirstUnique: Returns the first number that appears only once in the
data stream. If there is no such number, return
Key Requirements
Utilize a Hashmap to track the counts and positions of each number within a
linked list, efficiently managing duplicates and their occurrences.
Implement a Doubly Linked List to maintain numbers that currently have a
unique occurrence, preserving the order they were added.
Aim for O average time complexity for both add and showFirstUnique
operations, ensuring optimal performance as the data stream grows.
Implement the add and showFirstUnique methods as specified.
Ensure your code is functional, as nonfunctional code will result in a zero
score.
Example Workflow
add Stream:
showFirstUnique Returns
add Stream:
showFirstUnique Returns
add Stream:
showFirstUnique Returns
add Stream:
showFirstUnique Returns
add Stream:
showFirstUnique Returns
Academic Integrity and Usage of Tools
This assignment is designed to assess your understanding and ability to apply
key concepts learned in this course. As such, it is crucial that the work you
submit is entirely your own. To uphold the standards of academic integrity:
No Cheating: Collaboration on the design and implementation of your
solution is not allowed.
No Plagiarism: You must not "copy" the code from any source.
Usage of AI Tools: The use of AI programming assistants like ChatGPT for
converting your algorithmidea into real code is okay However, if that's
the case, you must cite its usage. We encourage you to make use of external
resources as necessary to solve this problem, just do not completely rely on
it for everything. Come up with your own plan to solve this problem, since
this homework will likely help you prepare for the midterm exam.
Referencing Sources: If you use any external resources like
StackOverflow for understanding the concepts, you must cite these sources.
Submission Instructions
Submissions are accepted in Python, Java, C C and JavaScript. Python
submissions are preferred due to compatibility with the autograder software.
Submit your source code with the correct file extension such as pyc
java etc. as a single file through the designated submission platform.
Include comments in your code to explain your logic and data structure
choices. If you choose to attach a documentation file which is optional for
your code, please submit a zip file containing both the source code and the
documentation file. Remember, the documentation is for reference only and not
considered for grading.
Your implementation will be graded based on specific method signatures
provided in the template file. Do not modify the method names or parameters.
Ensure your add function accepts only one parameter the new integer to be
added and the showFirstUnique function returns only the result the first
unique number in the data stream or if there are no matches
Evaluation Criteria
Correctness: The implementation accurately identifies and returns the first
unique number in the stream.
Efficiency: The implementation maintains O average time complexity for
operations.
Code Quality: The code should be wellcommented, easy to read, and logically
organized.
Autograder Script: autograder.py
import importlib.util
import sys
def loadsubmissionpath:
Dynamically loads the student's submission given the file path."""
spec importlib.util.specfromfilelocationsubmission path
submission importlib.util.modulefromspecspec
spec.loader.execmodulesubmission
return submission.FirstUnique
def runpublictestsFirstUniqueClass:
printRunning Public Test Cases"
tests
# Test Case : Basic functionality
addadd
# Test Case : Adding a unique number after nonuniques
add
# Test Case : Empty initialization
add
# Test Case : Repeatedly adding the same number
addadd
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started