COMP2402 W24Lab3Specifications

华为OD机试真题 2026.11.4. 新系统 【河流水系流量评估】 华为OD机试真题 新系统【河流水系流量评估】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【河流水系流量评估】多语言题解。 阅读详情

COMP2402 W24Lab3Specifications
(Some) SSet Implementations
Prelab: due on brightspace by Friday February 16th, 3:00pm (no lates)
Programming: due on gradescope by Wednesday February 28th, 3:00pm (24h late ok)
Postlab: due on brightspace.ca by Wednesday March 6th, 3:00pm (no lates)
Topic focus: Lec 1- 11
Feedback on Lab 1 Feedback
Hi all, thank you to the 83 (!!) of you that took the time to provide feedback after Lab 1; I know
you are all very busy! I am reading over your feedback carefully, and making some adjustments
to the course in response. You can read more about your feedback and the changes I will and
not make (and why) here.
Changes from Lab 1 & Lab 2
The specifications are still highly structured in the same way as Labs 1 and 2, but as with Lab 2,
a lot of the non-programming details are just links to previous documentation. This is so that you
don’t feel you have to read such a long document unless you need the resources (in which
case, you can follow the links to them.)
I have added a section at the very end: Autograder Runtimes for Sample Solutions, which
provides screenshots of the autograder as it ran on sample solutions. This is to give you a
sense of some runtimes you might strive for. For what it’s worth, I ran this tests during Lab 2
crunch times.
Any randomization in the autograder is now “fixed,” as in, the input was randomly generated
initially by me, but then fixed for the autograder. As such, everyone is being tested on exactly
the same input every single time. Any variability in the autograder can now definitely be
attributed to load/gradescope rather than variability in the tests (which I suspect was negligible
anyways, but just to be safe.)
There are still no hidden tests. I will wait to see if the variability of the autograder is resolved
before I go hiding any tests. In some sense, the variability of the autograder is serving as a
“hidden test” in the sense that you have to sometimes look at your code and determine its
time/space complexity and decide whether it matches the desired complexity rather than relying
on the occasionally flaky tests.
The GeneSet autograder has more structured feedback; more info in Geneset.
Lab Objectives
The labs in this course are meant to give you the opportunity to practice with the topics of this
course in a way that is challenging yet also manageable. At times you may struggle and at
others it may seem more straight-forward; keep trying and practicing and you will improve.
Specifically, Lab 3 aims to improve your

  1. Implementation Skills
    Implement operations (add, remove, find, etc.) for linked-list-based data structures
    similar to the SkiplistList and SkiplistSet (and, SLList and DLList, to some extent.)
  2. Design Skills
    Use object-oriented programming concepts such as abstraction and polymorphism to
    provide flexibility in your choices of which interface implementation to use.
  3. Critical Thinking
    Demonstrate a solid understanding of the pros and cons of various implementations of
    the list (array-based, linked-list-based, and SkiplistList-based) and of the situations when
    a sorted set might be a better choice than a list. This includes considering the time- and
    space-complexity of various operations in different data structures.
  4. Algorithmic Thinking
    Apply algorithmic thinking to design efficient algorithms for common linked-list-based
    operations, such as findPredNode(i), iteration over nodes using pointers and integers,
    careful pointer manipulation, and using nested structures to store and access data.
  5. Error Handling
    Implement appropriate error handling and boundary checks to ensure the robustness of
    the data structures.
  6. Testing
    Determine the necessary tests to ensure your algorithms are correct and efficient.
  7. Planning
    Maintain or adopt good academic and programming habits through the pre-lab.
  8. Reflection
    Reflect on your choice of data structures and algorithms through the post-lab.
    Assignment Components
    Details of each component follow later in the specifications.
  9. (6.7 points) Prelab (complete on brightspace)
  10. (80 points) Programming portion (submit on gradescope.ca)
    a. (40 points) GeneSet Implementation
    b. (10 points) JumbleC implementation
    c. (10 points) Genes Implementation
    d. (10 points) GenesOrder implementation
    e. (10 points) Mutations implementation
  11. (13.3 points) Postlab (complete on brightspace)
    Grading Criteria & Submission Guidelines
    See the Grading Criteria and Submission Guidelines of Lab 1; they are the same.
    Collaboration & Academic Integrity
  12. Individual work is expected. Any collaboration should be explicitly mentioned and
    acknowledged at the top of each file. It is okay to discuss high-level approaches with
    your peers, or low-level syntax-type questions, but you must construct your solution
    on your own (as in: you have to formulate the code of your solution on your own.)
    Consider the analogy of writing an essay. You might talk with a peer about the high-level
    concepts of your thesis, or you might ask them about grammar or even phrasing of
    individual sentences. But you should not be writing the essay sentence-by-sentence with
    someone else’s help; in the end you have to sit down and write that thing on your own.
  13. Plagiarism will result in severe consequences. Ensure that all code and
    documentation are your own work. Do not send code to or receive code from any
    source except for course staff or the textbook, even if you change a thing here or there.
    It helps to keep the analogy of an essay in mind; it is not okay to take a paragraph from
    a friend and then rearrange some of the words or replace some with a thesaurus. It’s not
    even okay to paraphrase each sentence. It is not okay to send your essay to a peer.
    Similarly here, you cannot start with code that is not yours and then “make it your own”
    with minor edits. Automated tools for detecting plagiarism will be employed in this
    course.
  14. The same restrictions apply to AI programmers (such as chatGPT, copilot). You can
    use them to help with basic syntax (e.g. “spelling” and “grammar”) or to understand
    broad concepts (e.g. getting feedback on a thesis) but you have to formulate your
    solution in code on your own (e.g. you have to write that essay yourself.)
  15. Note that contract cheating sites are known, unauthorized, and regularly monitored.
    Some of these services employ misleading advertising practices and have a high risk of
    blackmail and extortion.
  16. Every student should be familiar with the Carleton University student academic integrity
    policy. Academic integrity is upheld in this course to the best of Prof Alexa’s abilities, as
    it protects the students that put in the effort to work on coursework within the allowable
    parameters. Potential violations must be reported to the Dean of Academic Integrity. If
    you ever have questions about what is or is not allowable regarding academic integrity,
    please do not hesitate to reach out to course staff. We are happy to answer.
    Copyright
    Prof Alexa is the exclusive owner of copyright and intellectual property of all course materials,
    including the labs. You may use course materials for your own educational use. You may not
    reproduce or distribute course materials publicly for commercial purposes, or allow others
    to, without express written consent.
    Workflow
    In a perfect world, this is how you would complete Lab 3:
  17. Attend or watch the relevant lectures that are listed in the heading of this document.
  18. Read the lab objectives listed on the second page of this document. For each data
    structure listed there, review its important algorithms as well as the time- and space
    complexity of its methods. This should give you some pros and cons for each.
  19. Carefully read each problem detailed in the Programming section of this document.
    a. Make sure you understand the problem.
    b. Try the given examples by hand to get a better understanding of the problem.
    c. Pay special attention to any special cases or edge cases.
    d. Try more examples of your own devising if you need them.
    e. Donot start programming yet!
    f.
    Consider attending or watching the lab’s workshop video, posted on brightspace.
  20. Once you have completed steps 1-3, you are ready to do the prelab (brightspace).
  21. Complete the programming portion of the lab.
    a. Take this one problem at a time. Any order should be okay.
    b. Remember what you learned in Steps 1-4 as you brainstorm solutions.
    c. Test locally at frequent intervals. Do not write a whole program then test it
    afterwards. See the section on Local Tests to help you here.
    d. Submit to gradescope.ca whenever you have made good progress, but do not
    use gradescope.ca as your only tests. Gradescope keeps your most recent score
    unless you select a different submission to be active. See the section on the
    Gradescope Autograder to help you debug here.
    e. If you’re stuck on a problem for more than 30 minutes, ask for help using the How
    to Get Help section. Move on to something else until help has arrived.
  22. Once the late programming deadline has passed, complete the post-lab (brightspace).
    a. If you did well on the programming portion, this is not meant to take too long.
    b. There are resources available to help you posted on brightspace under the Lab 2
    module. There is a solutions walk-through video for each part, and also a debrief
    document where I walk through the problem solving process and learning
    engagement I was hoping you would experience. You might consider looking at
    these before completing the prelab if you had trouble with any of the
    programming parts.
    c. You do not have to have completed the programming parts in order to do the
    postlab. If you were stuck on a problem, this is an opportunity to look at the
    sample solution videos, to figure out what went wrong for you, and to still learn
    what you were meant to learn.
    Coding Environment Setup
    Lab 1’s Coding Environment Setup will work with Lab 3 (replace Lab1/l1 with Lab3/l3). The
    file structure and many of the files will be the same, with new and different files as well.
    Programming Components
    Programming Notes
  23. String compareTo might be helpful to compare strings lexicographically (alphabetically).
    Comparing elements can take more time for certain types of elements than others.
    Comparing two integers or doubles is basically O(1) time, as is comparing two
    Characters. But comparing two Strings requires potentially looping through both strings
    from front to back, which takes time linear in the length of the String. While Java has
    optimized String comparison as much as possible, there is only so much it can do if two
    strings of length k are exactly the same except for one character (say, the last one.)
  24. Recall from Lab 2 that repeated String appends (i.e. the + operator) is costly and can
    often be avoided by using StringBuffer and its append method.
  25. Note that the ods SSet interface has more than just the find operation, but also findLT
    and findGT that may be of use in this lab. Also you might take a look at its iterator.
  26. AbstractList is the abstract java List interface. All of our textbook (ods) List
    implementations implement this interface (either implementing it explicitly, as the
    ArrayDeque does, or by implementing a subclass as the DLList does.) This allows us to
    choose different implementations of the same interface; we know there is a guarantee
    that we can call the methods and they will have the promised behaviour, but we do not
    need to know the inner workings of the implementation (or, which implementation you
    choose to use.) This is polymorphism and abstraction at work.
  27. In order to make a new array of type Node in java, you need to do something like this:
    next = (Node [])Array.newInstance(Node.class, h+1);
    Anytime you use this you will need to add @SuppressWarnings(“unchecked”)
    prior to the method or inner class that creates the array. You can see examples of this
    scattered throughout the GeneSet class, should you need to do it yourself.
    Implementation Practice [40 marks]
    GeneSet [40 marks]
    GeneSet represents a set of Strings (where a String can ostensibly represent a gene; no
    biology knowledge necessary for the lab). Your task is to implement the following methods
    according to the specifications below, using the starter code and lecture to guide you. The
    provided implementations are incomplete and incorrect, but should be enough to compile and
    run the (failing) local and autograder tests.
    The data structure you use is a greatly simplified version of a SkiplistSSet, with randomization
    removed. Instead of determining the heights of elements via “coin flips,” we will determine the
    heights of elements based on the pattern of search paths we construct as the SSet gets used.
    As with a SkiplistSSet, a GeneSet is a dummy Node that links to a singly-linked list of
    Nodes. Each node u has its data (String s) and an array next of u.height+1 pointers to its
    next nodes at levels 0, 1, 2, …, u.height. That is, u.next[r] represents u’s “shortcut”
    at level-r, as with the SkiplistSSet. For example, a loop that would iterate over just the level
    r shortcuts would look something like this:
    u = dummy;
    while( u.next[r] != null )
    u = u.next[r]
    As with a SkiplistSSet, not every node will have shortcuts at every level; a node’s height
    represents the highest level r for which it has shortcuts; in other words, it is
    u.next.length-1 (since heights are 0-based.)
    Generally, we want our levels and heights to satisfy the four properties below:
  28. all elements are in level 0 of our skiplist, in sorted order;
  29. the elements at level r are all contained at level r-1 (but probably not vice-versa);
  30. the number of elements at level r is about half the number of elements at level r-1; and
  31. when searching for an element x, we take at most ~1 shortcut “right” per level before
    dropping down to the next lower level.
    In lecture, we saw the first saw the “fixed/deterministic” skiplist that allowed us to maintain these
    properties, but not without some restructuring cost on an add/remove. We then saw the
    SkiplistSSet that used randomization to get properties 3 and 4 in expectation (and maintained
    properties 1 and 2 always.)
    In this lab, we will also aim to always maintain properties 1 and 2, and we will try to maintain 3
    and 4 in a “just-in-time” basis. In particular, we will focus on property 4: if, in an add, remove, or
    find operation, we take two shortcuts at some level r (in “violation” of property 4), we will
    “just-in-time” add in a shortcut to level r+1 that jumps over the two shortcuts we just took. The
    idea is that this new shortcut can’t be used on the current operation, but it can be used on future
    operations, and hopefully the cost of adding in the new shortcut can be amortized over the adds
    and removes that made the shortcut necessary.
    This is the general idea. Let’s get to some details.
    Inner Class
    Node
    String
    Node[]
    int
    Fields
    ● Node dummy
    ● int n
    ● int h
    (Represents a Node in our set.)
    s
    next
    The non-empty String in this Node.
    The Nodes to which this Node has shortcuts.
    height() Returns the height of this Node (it’s next.length-1)
    The dummy Node for the set (also known as a sentinel).
    The number of elements in the set.
    The maximum height of any element (Node)in the set.
    Implemented Methods & Constructor
    ● GeneSet()
    Initializes the fields so that this set is empty (just a dummy Node of length 32).
    Note that the length of the dummy Node is not the same as the height of the GeneSet.
    ● public int size()
    Returns the number of elements in the set.
    See the main method for examples of how to use size.
    ● public void clear()
    Clears the set so that it contains no elements.
    See the main method for examples of how to use clear.
    ● public String toString()
    Returns a String representation of the set that is helpful for debugging purposes.
    See the main method for examples of how to use the toString method.
    ● protected Node findPredNode(String s)
    Returns the Node that precedes element s in the skiplist. This is for use in the iterator,
    so please do not modify it.
    ● public Iterator iterator()
    Returns an Iterator that iterates over the elements (Strings) of the set.
    See the main method for examples of how to use the iterator.
    ● public int[] getHeights()
    Returns an array of length n+1 with the heights of the n+1 nodes (including the dummy
    node.) This is for testing purposes, so please do not modify it.
    See the main method for examples of how to use the getHeights method.
    ● public Node getNode(int i)
    Returns the ith element of our set stored in level 0 of the skiplist. This is for testing
    purposes, so please do not modify it.
    See the main method for examples of how to use the getNode method.
    Methods For You to Implement
    Note: For all of these methods, I recommend getting them to work with just level 0 and level 1.
    The autograder has tests for solutions working with just those levels. Get the kinks out for levels
    0 and 1 before proceeding to more levels. There are even some tests with just levels 0, 1, and
    2, so that is another next step to take after getting levels 0 and 1 working.
    ● public void resize(Node u, int newHeight)
    Resizes the u.next array to have length newHeight, if newHeight>u.height is
    greater than its current length. Does nothing if newHeight≤u.height.
    Update the height of the GeneSet (h) if necessary.
    This would typically be a private method, but it is public so that the autograder can test it.
    If you’ve implemented resize, it is a very good idea to test this locally and on the autograder
    before proceeding. Bugs in resize will be hard to track down later.
    The add, remove and find methods will all share similar logic that finds the predecessor node
    of input s; usually I’d recommend working on a findPredNode method whose logic you can
    reuse in add, remove and find, we would not be able to test such a method until we have an
    add method that allows us to construct a set in the first place! As such, I recommend you work
    on add first, but then remember that the logic of add may be easily transferred to the other
    methods.
    ● public boolean add(String s) throws IllegalArgumentException
    Adds the element s to the set, if it is not already there.
    Throws an IllegalArgumentException if s is the empty string or null.
    Returns true if the element is newly added; false if it was already in the set.
    At any point if you traverse two existing level-r shortcuts (i.e. next[r] pointers), add a
    shortcut over those two edges at level (r+1). This may require resizing various nodes.
    If you’ve implemented add(s), it is a very good idea to test this locally and on the autograder
    before proceeding. If your add isn’t working, none of the other methods are likely to work.
    ● public String find(String s)throws IllegalArgumentException
    Returns the smallest element in the set that is ≥ s (in alphabetical order); returns null
    if no such element exists (i.e. if s > all elements of the set.)
    Throws an IllegalArgumentException if s is the empty string or null.
    At any point if you traverse two existing level-r shortcuts (i.e. next[r] pointers), add a
    shortcut over those two edges at level (r+1). This may require resizing various nodes.
    ● public boolean remove(String s)throws IllegalArgumentException
    Removes s from the set; returns true if s was removed, false if s was not in the set.
    Throws an IllegalArgumentException if s is the empty string or null.
    At any point if you traverse two existing level-r shortcuts (i.e. next[r] pointers), add a
    shortcut over those two edges at level (r+1). This may require resizing various nodes.
    If you’ve implemented find and remove it is a very good idea to test this locally and on the
    autograder before proceeding.
    ● public boolean equals(Object o)
    Returns whether this GeneSet is equal to o’s GeneSet.
    Returns false if o is not an instance of GeneSet.
    This should not only check whether the sets contain the same elements, but also
    whether they contain Nodes of the same heights, and the same shortcuts.
    Desired Complexity
    In the following table, let
    ● ndenotethe number of elements in our set;
    ● hdenotethe maximum height of any node.
    marks
    method
    time complexity
    (extra) space
    complexity
    8
    8
    8
    resize(u,t)
    add(s)
    find(s)
    O(t)
    O(h+n/2h)A
    [O(nh) occasionally, not often]
    O(h+n/2h)A
    [O(nh) occasionally, not often]
    O(t)
    O(n)
    [occasionally]
    O(n)
    [occasionally]
    8 remove(s) O(h+n/2h)A
    [O(nh) occasionally, not often]
    O(n)
    [occasionally]
    8 equals(o) O(n) O(1)
    Examples(admiremyasciiart,please)
    Resize
    Node u u.height (pre) method t=u.height(post) Node u (post)
    _
    _ ||->
    |s||
    |->
    1 resize(u,1) 1 _
    _ ||->
    |s||
    |->
    _
    _ ||->
    |s||
    |->
    1 resize(u,0) 1 _
    _ ||->
    |s||
    |->
    _
    _ ||->
    |s||
    |->
    1 resize(u,2) 2 _
    ||->
    _ |
    |->
    |s||_|->
    Add
    GeneSet method returns GeneSet (post)
    L0: | add(A) true L0: |-A
    L0: |-A add(A) false L0: |-A
    L0: |-A add© true L0: |-A-C
    L0: |-A-C add(E) true L1: |—C-
    L0: |-A-C-E
    L1: |—C-
    L0: |-A-C-E
    add(G) true L1: |—C—
    L0: |-A-C-E-G
    L1: |—C-----
    L0: |-A-C-E-G-I
    add(I) false L1: |—C—G-
    L0: |-A-C-E-G-I
    L1: |—C—G-
    L0: |-A-C-E-G-I
    add(K) true L2: |-------G—
    L1: |—C—G----
    L0: |-A-C-E-G-I-K
    L0: |-K add(I) true L0: |-I-K
    L0: |-I-K add(G) true L0: |-G-I-K
    L0: |-A-C-E-G-I-K add(L) true L1: |—C—G—K-
    L0: |-A-C-E-G-I-K-L
    L2: |-------K
    L1: |-------K
    L0: |-C-E-I-K
    add(K) false L2: |-------K
    L1: |-------K
    L0: |-C-E-I-K
    L2: |-------K
    L1: |-------K
    L0: |-C-E-I-K
    add(L) true L2: |-------K
    L1: |-------K
    L0: |-C-E-I-K-L
    L0: |-A-C-E-G-I-K add(“”) IllegalArgumentException
    Find
    GeneSet method returns GeneSet (post)
    L0: | find(A) null L0: |
    L0: |-A find(A) A L0: |-A
    L0: |-A-C find(B) C L0: |-A-C
    L0: |-A-C-E-G-I-K find© C L1: |—C-------
    L0: |-A-C-E-G-I-K
    L1: |—C-------
    L0: |-A-C-E-G-I-K
    find(L) null L1: |—C—G—K
    L0: |-A-C-E-G-I-K
    L1: |—C—G—K
    L0: |-A-C-E-G-I-K
    find(L) null L2: |-------G—
    L1: |—C—G—K
    L0: |-A-C-E-G-I-K
    L0: |-A-C-E-G-I-K find(“”) IllegalArgumentException
    Remove
    GeneSet method returns GeneSet (post)
    L0: | remove(A) false L0: |
    L0: |-A remove(A) true L0: |
    L0: |-A-C-E-G-I-K remove(B) false L0: |-A-C-E-G-I-K
    L0: |-A-C-E-G-I-K remove(A) true L0: |-C-E-G-I-K
    L0: |-C-E-G-I-K remove(E) true L0: |-C-E-G-I-K
    L0: |-C-E-G-I-K remove(G) true L1: |—E—
    L0: |-C-E-I-K
    L1: |—E—
    L0: |-C-E-I-K
    remove(L) false L1: |—E—K
    L0: |-C-E-I-K
    L1: |—E—K
    L0: |-C-E-I-K
    remove(L) false L2: |-------K
    L1: |—E—K
    L0: |-C-E-I-K
    L2: |-------K
    L1: |—E—K
    L0: |-C-E-I-K
    remove(K) true L1: |—E-
    L0: |-C-E-I
    L2: |-------K
    L1: |-------K
    L0: |-C-E-I-K
    remove(K) true L1: |—E-
    L0: |-C-E-I
    L0: |-C-E-I-K remove(“”) IllegalArgumentException
    Equals
    GeneSet this GeneSet o method returns
    L0: | null this.equals(o) false
    L0: | “ABCD” this.equals(o) false
    L0: | L0: | this.equals(o) true
    L0: |-A L0: | this.equals(o) false
    L0: |-A L0: |-B this.equals(o) false
    L0: |-A-C L1: |—C
    L0: |-A-C
    this.equals(o) false
    Interface Practice [40 marks]
    The 4 problems in this section ask you to choose the best data structures (interfaces), if any, to
    solve each problem correctly and efficiently (with regards to time and space). As with Labs 1
    and 2, the characters generated contain any combination and number of the four characters A,
    U, C, G. Ensure your implementation is efficient and handles different scenarios gracefully.
    JumbleC (extends Jumble) (a.k.a. Jumble Returns)
    Method Signature
    public static String jumble(InputGenerator gen)
    Method Behaviour
    Returns a jumbled version of the input sequence generated by InputGenerator
    gen after it has been jumbled as follows:
  32. Initially the “cursor” is at index 0.
  33. Ascharacters are generated, add them at the cursor.
    𝑛
    2
    characters generated thus far, or to 0 if this would move the cursor left of 0.
  34. If an AUC is generated, “rewind” the cursor ⌊ ⌋ positions, where n is the number of
  35. If an AUG is generated, “fast forward” the cursor ⌊ ⌋ positions, where n is the number of
    𝑛
    4
    characters generated thus far, or to n if this would move the cursor right of n.
    Desired Complexity & Constraints
    O(n log n)A time, where n is the number of characters generated.
    O(n log n)space.
    Examples
    characters generated by gen
    output
    n
    d
    UUUAUCG UUUGAUC 7 1
    UUAUCGGGAUGUU UUAGGGAUGUCUU 13 2
    UAUCAUCAUCAUC
    AUCUAAUCAUCUC
    (no characters) “”
    Testing & Autograder
    13
    0
    4
    0
    There are limited local tests in JumbleC.main and tests/JumbleCTest.java; see Lab 1 for
    testing instructions. Submit JumbleC.java to gradescope; see Lab 1 for submission
    instructions.
    Genes
    Method Signature
    public static int genes(InputGenerator gen, int k)
    Method Behaviour
    Returns the number of different genes (substrands) of length k > 0 in the sequence generated
    by a given InputGenerator.
    Desired Complexity & Notes
    O(k2n)A time, where n is the number of characters generated.
    O(kd) space, where k is the integer input parameter, and d is the solution.
    Since there are 4 bases, d ≤ 4k and thus log d = O(k).
    Even within these bounds, do your best to minimize wasteful time or space operation in
    order to pass all the performance tests.
    Examples
    characters generated by gen
    AAAA
    k
    3
    output (d)
    1
    n
    4
    AAAAU
    UGCGAAUAUA
    UUUUCCCCAAAA
    UUUUCCCCAAA
    Testing & Autograder
    3
    3
    12
    12
    (no characters)

0
2
7
1
0
0
5
10
12
11
0
There are limited local tests in Genes.main and tests/GenesTest.java; see Lab 1 for
testing instructions. Submit Genes.java to gradescope; see Lab 1 for submission instructions.
GenesOrder
Method Signature
public static AbstractList genesOrder(InputGenerator
gen, int k)
Method Behaviour & Notes
Returns a list of the different genes (substrands) of length k > 0 in the sequence generated by
a given InputGenerator, in the order they are first encountered.
An AbstractList is an abstract java interface that is implemented by all the ods List implementations
(e.g. ArrayStack, ArrayDeque, DLList, SkiplistList, etc). Using AbstractList as the return type
means you have the flexibility to choose which of these List implementations best suits your code
and the desired complexity requirements.
Desired Complexity & Notes
O(k2n)A time, where n is the number of characters generated.
O(kd) space, where k is the integer input parameter, and d is the solution.
Since there are 4 bases, d ≤ 4k and thus log d = O(k).
Even within these bounds, do your best to minimize wasteful time or space operation in
order to pass all the performance tests.
Examples
characters generated by gen
AAAA
k
3
output (d)
AAA
n
4
AUAAA
UGCGAAUAUA
UUUUCCCCAAAA
Testing & Autograder
3
3
12
(no characters)
0
AUA,UAA,AAA
5
UGC,GCG,CGA… 10
UUUUCCCCAAAA 12
0
0
There are limited local tests in GenesOrder.main and tests/GenesOrderTest.java; see
Lab 1 for testing instructions. Submit GenesOrder.java to gradescope; see Lab 1 for
submission instructions.
Mutations
Method Signature
public static int mutations(InputGenerator gen, int k)
Method Behaviour
Returns the number of different “closest mutations” computed over all substrands of length k >
0 in the sequence generated by a given InputGenerator.
Given a strand of length k, its “closest mutation” is the nearest already-existing strand of length
k just following it alphabetically, if it exists. For example
in list [AAA] the closest mutation to AAA is non-existent
in list [AAA,CAA] the closest mutation to AAA is CAA
in list [AAA,CAA,ACA] the closest mutation to AAA is ACA
Desired Complexity & Notes
O(nk2)A time, where n is the number of characters generated.
O(kd) space, where k is the integer input parameter, and d is the number of different
strands of length k (same as in Genes).
Since there are 4 bases, d ≤ 4k and thus log d = O(k).
Even within these bounds, do your best to minimize wasteful time or space operation in
order to pass all the performance tests.
Examples
characters generated by gen
AAA
k
3
output
0
n
3
AAAA
CAAA
CAAACAAA
ACGUACGUACGU
Testing & Autograder
3
3
3
3
(no characters)
0
0
1
2
3
0
4
4
8
12
0
There are limited local tests in Mutations.main and tests/MutationsTest.java; see Lab
1 for testing instructions. Submit Mutations.java to gradescope; see Lab 1 for submission
instructions.
Local Tests
See the Local Tests section of Lab 1; be sure to replace comp2402w24l1 with
comp2402w24l3!
Gradescope Autograder
See the Gradescope Autograder section of Lab 1; be sure to replace Lab 1 with Lab 3 where
necessary.
How to Get Help
See the How to Get Help section of Lab 1. It will be updated with any new resources rather than
duplicating information here.
Common Errors & Fixes
See the Common Errors & Fixes section of Lab 1. It will be updated with any new errors rather
than duplicating information here.
Glossary
There is a glossary at the top of the Problem Solving & Programming Tips document. If you
can’t find a term listed there, please post publicly on piazza so that everyone can benefit from
the answer!
Autograder Runtimes for Sample Solutions
To give you a sense for the autograder runtimes for “perfect scores” you can see some of the
screenshots that follow.
GeneSet: I’ve made some adjustments to the autograder since making the screenshots below,
by increasing the time bound on the correctness and space tests.
● all non-performance tests now have 3 seconds, which should be plenty of time to check
for correctness (this is up from 2 seconds)
● all space performance tests now have 6 seconds, which should be plenty of time to
check for space usage without failing due to time (although they are related: frequently
an overly-space-intensive program will take too much time, as in order to use space you
take time to do so. Keep that in mind if you do fail the space test due to time.)
Resize
Add
Find
Remove
Equals
JumbleC
Genes
GenesOrder
Mutations

SpringBoot+Vue+MySQL 高校学科竞赛平台 完整可运行版(源码+文档) 本项目基于SpringBoot+Vue+MySQL构建高校学科竞赛管理平台,覆盖学生、教师、领队教师、管理员四大角色,实现竞赛发布、报名、刷题、评分、公示等全流程闭环管理。系统架构清晰,技术主流,配套完整源码、数据库脚本、万字论文、开题报告、答辩PPT及部署文档,支持一键运行,适用于毕业设计、课程设计及院系二次开发,真正实现“开箱即用”。 阅读详情

相关推荐

ESP32C6+ESP-IDF5.2实战:基于RS485的ModbusRTU从站开发与调试

本文详细介绍了基于ESP32C6和ESP-IDF5.2开发ModbusRTU从站的实战指南。涵盖硬件连接、协议实现、ESP-Modbus库移植、寄存器映射及调试技巧,帮助开发者快速构建稳定可靠的工业级RS485通信节点,并解决常见通信故障。

play7的博客 1188

InnoDB 内存结构总览:Change Buffer、AHI 与 Log Buffer

本文系统梳理InnoDB内存结构中的ChangeBuffer、Adaptive Hash Index(AHI)与LogBuffer。ChangeBuffer缓存二级索引页不在内存时的变更,减少随机IO,仅在页加载时合并;聚簇索引修改立即执行,因数据本身不可延后。AHI基于高频等值查询自动构建哈希索引,加速定位,仅支持等值操作。LogBuffer为redo log内存缓冲,配合磁盘日志实现崩溃恢复。三者均服务于性能优化,其中ChangeBuffer与AHI共享BufferPool空间,而LogBuffer独立

bksczm的博客 285

【视频编码学习】AVS3参考软件HPM-4.1简单配置运行

1、用Visual Studio2017打开HPM-4.1文件夹 2、找到文件夹目录下x86_windows文件夹,因为是在win上运行该代码 3、然后找到对应vs版本(我当时2017版)的解决方案sln文件,双击打开可以看到该解决方案下的全部项目。 4、重新生成解决方案时发现提示sdk版本问题,所以右键点击所有的项目,选择重定向项目,修改一下sdk版本。 ...

谦虚勤奋诚实感恩 3100

V8 机制、手写核心函数与 TypeScript 类型体操

或固定初始化(如数组先定长、对象先给全字段)保持类型与形状稳定;这些都比"换框架"更基础。只能处理纯数据(丢函数、Date、RegExp、循环引用报错)。生产级深拷贝要处理:原始值短路、循环引用、V8(Chrome / Node 的 JS 引擎)不是"解释一行跑一行"那么简单,它用。图:V8 执行流程——解释执行 + 热点优化,优化失败会 Deopt 回退。JS 内存自动管理,但"自动"不等于"不会漏"。是"固定间隔最多执行一次"。手写 Promise 是"懂异步"的试金石。是"停下后才执行最后一次",

qq_38468358的博客 346

从CCD数据上报看wxHOOK的封号风险与规避

本文深入分析了微信CCD数据上报机制对wxHOOK的检测逻辑与封号风险,揭示了调试器路径暴露、非白名单DLL加载和内存校验失败等关键风险点。通过实战案例和规避方案,帮助开发者理解如何安全使用wxHOOK技术,避免封号风险,包括内存镜像欺骗、内核级隐蔽和硬件辅助方案等高级技巧。

weixin_27875131的博客 629

HotSpot G1 GC 的分区记账、SATB 并发标记与停顿目标调优解析

线上GC毛刺该调停顿目标、加大新生代还是换收集器?本文从HotSpot G1的设计出发,梳理分区与巨型对象、卡表与记忆集、写屏障与细化线程、停顿预测、SATB并发标记、自适应IHOP、混合回收规则及Full GC兜底,并注明JDK8至JDK27的版本差异。文中在JDK8与JDK17上实测:停顿目标从200ms降到20ms,伊甸区缩小四成、P99下降但仍超目标;巨型对象会反复触发又撤销并发标记;JDK17并行Full GC平均停顿约为JDK8的三成。最后给出日志解读、参数清单、调优流程与选型。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 170万+

Spring Boot 数据源与 MyBatis(-Plus) 自定义配置详解

本文详解 Spring Boot 中单数据源环境下 HikariCP 与 MyBatis-Plus 的自定义配置。通过手动声明 SqlSessionFactory,实现下划线转驼峰、日志输出、一级缓存策略等精细化控制。结合 HikariCP 核心参数调优(如最大连接数、连接生命周期),确保高性能与稳定性。适用于仅需访问单一数据库的场景,避免多数据源复杂性,兼顾性能与可维护性。

BADAO_LIUMANG_QIZHI的博客 198

基于学术研究于NASA官网GPM卫星数据下载详细教程

基于学术研究于NASA官网GPM卫星数据下载详细教程

珞瑜的博客 8655

Java EE 进阶:8.MyBatis 操作数据库(入门)(第一弹)

Java EE 进阶:8.MyBatis 操作数据库(入门)(第一弹)

要努力去发光,而不是被照亮~ 128

PyQt(Python+Qt)学习随笔:PyQt界面派生类构造方法中super方法的使用

老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 在《第15.7节 PyQt入门学习:PyQt5应用构建详细过程介绍》和订阅专栏《第二章、PyQt5应用构建详细过程介绍》中,老猿介绍界面派生类的构造方法如下: class MediaPlayerWin(QtWidgets.QWidget,Ui_UI_PlayerWin): def __i...

老猿Python 2711

深度强化学习 | 基于SAC算法的移动机器人路径跟踪(附Pytorch实现)

软性演员-评论家(Soft Actor-Critic, SAC)算法是基于最大熵原理的离线策略方法,本节将基于深度强化学习中的SAC算法实现移动机器人的路径跟踪,介绍网络设计、动作空间设计和奖励函数设计,并提供Pytorch实现加深理解

FRIGIDWINTER的博客 5736

LeetCode Hot 100 二叉树专题(二)3 题(Java)

本篇文章共 3 题:543. 二叉树的直径、102. 二叉树的层序遍历、108. 将有序数组转换为二叉搜索树。 每道题都统一按「① 题目分析 & 解题思路 → ② 常见解法(附代码)及讲解 → ③ 知识点总结」的顺序组织;代码使用 Java 编写,节点定义沿用 LeetCode 默认的 TreeNode。

2401_88612756的博客 365

思博伦仪表打流测试使用总结

下图红框中的checkbox为选中状态时,表示该流会携带测试仪做一些分析,包括时延和乱序等信息时需要的一些字节,当改选项选中时,如配置IPv4的TCP流,最小字节长度必须为78字节;如果需要64字节的TCP流,改选项必须不选中;

陌上花开缓缓归以的博客 1465

【从零理解 Spring AI · 12】MCP 的两种角色:做客户端还是做服务端

上一篇讲了 MCP 的概念:标准协议、三大角色、M+N 替代 M×N。

nice_lcj520的博客 498

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

JDK 下载安装:装完 Java 提示「不是内部或外部命令」?环境变量没配

JDK 是写 Java 程序必须装的东西。它包含运行 Java 的虚拟机(JRE)和编译 Java 的编译器(javac)——装了它,能跑、.java文件能编译成可执行程序。免费,学习和小规模生产都不花钱。

科小怪的博客 633

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

java框架大全

java框架大全

qq_39326137的博客 183

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Java 多态 学习笔记

多态是面向对象编程的重要特性,指同一操作作用于不同对象时产生不同行为。其核心在于“父类引用指向子类对象”,结合方法重写实现运行时动态绑定。多态使代码更灵活、可扩展,如用Person p = new Student();统一处理各类人员注册,无需修改调用逻辑。但多态无法直接调用子类特有方法,需通过instanceof判断并强制转换。编译时看左边(类型),运行时看右边(实际对象),实现解耦与维护便利。

AA_AA114514的博客 360

SecureRandom做随机源,这个Java随机字符串工具类有3个方法

本文分享一款JDK17环境下的Java随机字符串工具类,内置3个开箱即用的方法,全部采用SecureRandom加密安全随机源,不存在弱随机、可预测、取模偏差等问题。工具类支持默认62字符集随机串、纯数字随机串、自定义字符集随机串三种生成模式,支持Unicode码点级别的字符集处理,兼容Emoji等增补字符,边界处理严格,异常信息明确,适合验证码、邀请码、盐值、随机口令、短链码等场景,源码可直接复制使用。

Java后端 | AI智能体应用实战派 | 电脑技能行家 298

IDEA 简介:从零认识 IntelliJ IDEA

IDEA 全称,是由 JetBrains 公司开发的一款主流 Java 集成开发环境(IDE)。它集代码编辑、编译、调试、测试、版本控制、构建管理等功能于一体,被大量 Java 开发者视为日常开发的首选工具。所谓 IDE(Integrated Development Environment,集成开发环境),就是把写代码所需的各类工具整合到同一个界面中。相比只用文本编辑器加命令行编译,IDE 能显著减少重复操作,让开发者把精力集中在业务逻辑上。

ztI10的博客 151

Java实现批量线段相交检测(跨积判定+扫描线优化与踩坑复盘)

【代码】Java实现批量线段相交检测(跨积判定+扫描线优化与踩坑复盘)

m0_64476639的博客 328

TRingBuffer两端都能增删(快递站版)

TRingBuffer 是一个支持两端增删、下标访问且容量动态增长的环形双端队列。它通过无符号索引的永不归零设计,利用减法自动模运算实现空满判断与元素计数,避免了传统环形缓冲浪费格子的问题。内部以票号(索引)标记首尾,扩容时重排元素为连续存储,保证 O(1) 操作与高缓存效率。虽不线程安全,但其高效性使其成为游戏开发中事件队列、命令缓冲等场景的理想选择。

u013768914的博客 227

ubuntu安装hadoop系统

本文详细介绍了基于VMware克隆虚拟机搭建三节点Hadoop分布式集群的全过程:使用同一Ubuntu镜像克隆出master、worker1、worker2三台虚拟机,依次配置主机名、固定IP(如192.168.82.10/11/12)、SSH服务及免密登录,确保节点间网络互通。随后安装Java,下载配置Hadoop并分发至各节点,最终初始化启动集群,验证其存储与计算功能,实现高效的大数据环境部署。

qq_43592674的博客 332

Mac上装了最新版本的Android Studio,但是没找到jdk的设置选项也没找到jbr的目录

新版Android Studio(2025.3.1+)因三项变更导致常见问题:一、JDK设置移至“DaemonJVM criteria”,新项目默认自动探测或下载JDK;二、JBR目录改名为带版本号的jbr-21等,需进入.app/Contents/查看,或通过About窗口确认运行时;三、命令行缺adb因platform-tools未加入PATH,需在SDK Manager中勾选并配置~/.zshrc中的ANDROID_HOME及PATH。重装或清理残留可解决缺失问题,切勿手动设JAVA_HOME或安装冲

Programming is a highly artistic endeavor 352

Spring事务和事务传播机制

3. 可重复读(REPEATABLE READ): 事务不会读到其他事务对已有数据的修改, 即使其他事务已提交. 也就可以确保同⼀事务多次查询的结果⼀致, 但是其他事务新插⼊的数据, 是可以感知到的. 这也就引发了幻读问题. 可重复读, 是 MySQL 的默认事务隔离级别.p1事务可以认为是⽗事务, 嵌套事务是⼦事务. ⽗事务出现异常, ⼦事务也会回滚, ⼦事务出现异常, 如果不进⾏处理, 也会导致⽗事务回滚.

txxzjmzlh的博客 205

Java Arrays.asList 常见坑详解|UnsupportedOperationException、数组联动、基本类型 bug

解析 Arrays.asList 常见开发陷阱,演示 UnsupportedOperationException、底层数组引用共享、基本类型数组问题,区分 Arrays 内部 ArrayList 与 java.util.ArrayList,给出数组转 List 的各种场景正确代码。

weixin_42617033的博客 473

读懂 Dart Future:从 async/await 到并发等待

Dart 中的 Future 用于处理异步操作,如网络请求、文件读取等。它表示一次可能延迟完成的计算,成功时返回指定类型值(如 Future<String>),失败时抛出异常。通过 async/await 可以同步式编写异步代码,提升可读性。await 暂停当前函数执行,但不影响事件循环。Future.wait() 可并发等待多个异步任务,timeout() 设置超时限制,catchError() 处理错误。注意:async 不自动开启新线程,耗时计算仍可能阻塞主线程;避免丢弃未处理的 Future,必要时

侯仕奇的博客 356
上一篇: CS 36CWinter 2024 Homework 3
下一篇: CS154 Lab8:PageTableWalkerinPyRTL
todcode
博客等级 码龄7年 359粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值