COMP2402 lab4

STM32CubeIDE无法连接STLinkV2的一个可能原因 前些日子买了个新的STLINKV2 , ( 老的被我家猫猫一泡尿送上西天了)刚开始还挺正常的, 后来有一天就突然间发现无法调试了.网上尝试了各种方法, 各种操作. 百度了好久. 最后好在我自己研究出来了.我使用的是 STM32CubeIDE 这个开发工具调试选项如下图其它的不需要修改, 然后点击下面的apply 按钮, 然后调试Debug, 提示 No STLink 如下图后来尝试了下载ST-LINK Utility 用它是可以正常连接STLink的, 然后也能正常进行升级操作. 阅读详情

COMP2402 W24Lab4Specifications
Trees & HashSets & Maps (& Lists)
Prelab: due on brightspace by Friday March 8th, 3:00pm (no lates)
Programming: due on gradescope by Wednesday March 13th, 3:00pm (24h late ok)
Postlab: due on brightspace.ca by Wednesday March 20th, 3:00pm (no lates)
Topic focus: Lec 1- 15
Feedback on Lab 2 Feedback
Thank you very much to the 32 of you that took the time to fill out Lab 2 feedback. I was
planning on writing up a report like last time but Life got in the way. But I’ve carefully read over
your feedback and there were some common themes:
● Talk about iterators in lecture (will do next time! I mentioned their benefits in the
in-person section but maybe my videos do not. Note to self to add that in.)
● For any local test written after I read the Lab 2 Feedback, you’ll notice that the “Expect”
comment is now in the output text as well. I hope this reduces some of your pattern
matching time. Thanks for the suggestion, mystery student
�
�
● Lab 2 took longer than Lab 1 (which is natural, but maybe some warning could be
given.) I can/should also emphasize how you should ask for help when you are stuck.
Our TAs are on piazza all. the. time. While during “deadline week” you might not get a
response right away, our average response time is 43 minutes. We’ve had over 600
posts in 6 weeks so we’ve been busy! You can’t see all the private posts we get, but if
you ask a question during “forum monitoring” times and you don’t get a response asap it
could be that the TA is busy responding to a bunch of other private posts.
● autograder: some issues remain although many of you appreciate getting feedback
before the deadline. Without the autograder you wouldn’t have any hints as to whether
you had a good data structure choice and since this course is about that choice, you
would have no idea whether your choice is good. But I know it can be frustrating to not
know where your bugs are. Sadly, this frustration will persist throughout your computer
science career in various ways. I will continue to work on naming the tests better.
Changes from Labs 1-3
The autograders have more structured feedback, so that it’s a bit better at being a “checkpoint.”
For example, many of the PhyloTree tests are for k=1, or when the Strings are not null, etc. You
can focus on these special cases first and then worry about more general cases, if you wish.
There are still no hidden tests. In a sense, the autograder variability serves as a “hidden test” in
that you sometimes have to look at your code and determine its complexity (gasp!) and decide
whether it matches the desired complexity rather than relying on the occasionally flaky tests.
Finally, I made this new flow chart to help you determine where your problems are and how to
communicate those problems to the course staff so that we can help you as quickly as possible!
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 4 aims to improve your

  1. Implementation Skills
    Implement iterative operations for tree-based data structures similar to the BinaryTree
    and BinarySearchTree (add, find, remove, iterate, traverse, rotations).
  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 SSet (randomized, expected, worst-case) and of the situations when an unsorted set
    or map might be a better choice than a sorted set or 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 tree-based
    operations, such as find(x), iteration over nodes using pointers, careful pointer
    manipulation in tree rotations, and removing recursion to avoid a big call stack.
  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. (50 points) PhyloTree Implementation
    b. (10 points) Genes implementation
    c. (10 points) GenesOrder Implementation
    d. (10 points) GenesCount 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 4:
  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 4 (replace Lab1/l1 with Lab4/l4). The
    file structure and many of the files will be the same, with new and different files as well.
    Programming Components
    Programming Notes
  23. You may use java.util.HashSet instead of ods.MultiplicativeHashSet if you want the
    fastest implementation of a HashSet. Note that HashSet has an iterator.
  24. You may use java.util.HashMap as well, for a fast implementation of a HashMap. Note
    that HashMap has an iterator over its keys or values.
  25. If you want to use Collections.sort on an array-based Collection, you can!
    e.g. ArrayDeque ad = …
    Collections.sort(ad);
    // initialize ad etc
    // now ad is sorted!
    This takes O(n log n) time, where n is the number of elements in ad.
    You can also sort a Collection using a new comparison rule (a Comparator) , eg
    e.g. Collections.sort(ad,MyComp); // sort ad using MyComp
    where you may have defined MyComp elsewhere like this
    class MyComp implements Comparator {
    public int compare(String a, String b) {
    // Fill in compare
    }
    }
    Here are some examples on geeksforgeeks. Note that sorting a linked-list-based
    Collection can be done, but java first dumps the linked list into a structure with fast
    random access, and then sorts on that better structure, then dumps the sorted thing
    back into your linked-list-based structure. Keep that in mind, I suppose.
  26. If you want to store objects of a class (of your own definition) in a sorted set, you need to
    ensure your class implements Comparable. For example, you could have
    class MyClass implements Comparable {
    int x;
    int y;
    public int compareTo(MyClass b) {
    // Fill in compareTo
    }
    }
    Here are some examples on geeksforgeeks.
  27. Note that you should not need recursion for any of the problems. You can/should run all
    tests with the-Xss144k flag (or, the smallest heap size your local machine will allow.)
    Sometimes you’ll pass such tests even with recursion.
    Implementation Practice [50 marks]
    PhyloTree [50 marks]
    PhyloTree represents a tree of distinct Strings (where a String can ostensibly represent a DNA
    sequence; no biology knowledge necessary for the lab). Your task is to implement the described
    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 is a modified BinaryTree of Strings of some fixed length k, where each String
    is either null or of some length k>0 that is fixed for the given tree. The tree represents a
    “phylogenetic tree,” which is essentially a hypothesized family tree for DNA. When a node has
    value null it means we haven’t determined that ancestor in the tree yet. Each (non-null) String
    of the tree should be distinct and of length k.
    This is the general idea. Let’s get to some details.
    Inner Class
    Node
    (Represents a Node in our tree.)
    String s
    Node
    The String of length k in this Node, or null.
    parent, left, right Theparent, left child and right child of this Node.
    boolean mark
    Helpful node-specific boolean, used in LCA.
    boolean[] set
    Fields
    ● Node r
    ● int n
    ● int k
    Helpful node-specific set, used in computeSet.
    The root Node for the tree.
    The number of nodes in the tree.
    The length of non-null Strings in the tree, k>0.
    ● HashMap<String,Node> stringsToNodes A map from each non-null String
    stored
    in the Tree to the node that contains that String.
    Used to speed up various methods.
    Implemented Methods & Constructor
    ● PhyloTree()
    Initializes the fields so that this tree is empty and k = 1.
    ● PhyloTree(int k)
    Initializes the fields so that this tree is empty and initializes k to the parameter.
    ● public int size()
    Returns the number of nodes in the tree.
    ● public void clear()
    Clears the tree so that it contains no elements.
    ● public String toString()
    Returns a list-based String representation of the tree in in-order that is helpful for
    debugging purposes.
    ● public String prettyPrint()
    Returns a tree-like String representation of the tree that is helpful for debugging
    purposes. This is only useful for smaller trees; for larger trees with missing children it can
    misrepresent the tree so use it cautiously.
    ● public int height()
    Returns the first Node in an in-order traversal. Note that his is a recursive method so use
    it with caution.
    ● protected Node firstNode()
    Returns the first Node in an in-order traversal.
    ● protected Node nextNode(Node w)
    Returns the Node that follows w in an in-order traversal.
    ● public Iterator iterator()
    Returns an Iterator that iterates over the Strings of the tree in in-order order. Note
    that the Strings are not being stored in sorted order, so it may not appear sorted.
    Constructor & Methods For You to Implement
    Implement all the following methods without recursion.
    Don’t forget to update stringsToNodes when you add a non-null String to the PhyloTree!
    Use the examples from lecture (e.g. traverse2, size2, findLastNode) to guide you here.
    ● public boolean addChild(String parent, String child) throws
    IllegalArgumentException
    Adds a Node containing child as the child of the existing parent.
    If parent is null, adds child as new root, with existing root as its left child.
    If parent has no children, add child as a left child.
    If parent has left child, add child as a right child.
    Throws an IllegalArgumentException if parent already has 2 children.
    Throws an IllegalArgumentException if parent is not null and doesn’t exist.
    Throws an IllegalArgumentException if child is not null and already exists
    Throws an IllegalArgumentException if child is not null and its length is not k.
    If you’ve implemented addChild, it is a very good idea to test this locally and on the autograder
    before proceeding. If your addChild isn’t working, none of the other tests are likely to work.
    ● public PhyloTree(ArrayStack a) // Constructor
    Initializes the tree to contain the elements of a, where a contains the elements of the tree
    in “level order” (i.e. a[0] is the root, a[1] and a[2] are the root’s children, and so forth.)
    Throws an IllegalArgumentException if non-null duplicates exist.
    Throws an IllegalArgumentException if any non-null String has length != k,
    where k is the length of the (non-null) Strings in a (they should all have same length.)
    If you’ve implemented PhyloTree, it is a very good idea to test this locally and on the
    autograder before proceeding. If this constructor isn’t working, many of the tests that depend on
    this constructor will also fail.
    ● public String LCA(String s, String t)
    Returns the “least common ancestor” (LCA) of the nodes containing s and t.
    The LCA is the first ancestor that s and t have in common (the one farthest from root r).
    Throws an IllegalArgumentException if s or t are null or aren’t in the tree.
    Note: The Node class has a mark field that can help you keep track of, say, nodes
    you’ve seen. Just remember that if you “mark” a node, you should “unmark” it before you
    return from LCA otherwise it will be “marked” the next time you call it.
    Hint: break your code into manageable parts. Perhaps separate out the logic of checking
    for exceptions from finding the nodes that contain s and t from the logic that find the
    LCA of those nodes.
    ● public void fixUp(String s)
    Performs a series of single rotations involving s until s is in a “good spot.”
    In particular, if the node containing s is not in “binary search tree” order relative to its
    parent (e.g. it’s a left child greater than its parent, or a right child less than its parent),
    use the appropriate single rotation to swap the parent-child relationship.
    Proceed up the tree as necessary until s is “good” relative to its parent.
    If s’s parent is null, it is in a “good spot”.
    Note that the rest of the tree may be completely disordered; that’s okay.
    Throws an IllegalArgumentException if s is null or is not in the tree.
    Hint: single rotations come up in Treaps and BinaryHeaps; look there for guidance.
    ● public void computeSets(int index)
    For this problem, each Node can hold a String of length k of DNABases (or is null).
    (You can use the provided class field DNABases = {A,C,G,T} here.)
    Initially, all the leaves will be non-null; the internal nodes may or may not be null.
    The given index indicates which index of the length-k String is relevant.
    This problem asks you to compute each node’s set of possible bases for the given index.
    You’ll use the node’s set field for this:
    i.e. if DNABases[b] is a possible base for the given index of node u, you’ll set
    u.set[b] = true
    (ex: if (index index) of u can be A,G then u.set=[true,false,true,false])
    Throws an IllegalArgumentException if the index<0 or index>=k.
    Throws an IllegalArgumentException if any of the leaves are null.
    Use the following algorithm to compute the sets:
    for each node v in post-order (working from leaves upwards)
    if v is a leaf
    v’s base is v’s character at given index
    else if v has one child c
    v’s set of bases is c’s set of bases
    else
    if v’s left and right children have overlapping sets
    v’s set= the overlap/intersection of left &
    right
    else (the sets do not overlap)
    v’s set = the combination/union of left & right
    Note: there are some methods for debugging and testing that will be helpful:
    setToBases(Node u)- returns a String representation of node u’s set
    allSets()- returns an ArrayStack of all node’s u’s sets, in post-order
    Desired Complexity
    In the following table, let
    ● ndenotethe number of nodes in our tree;
    ● d(s,t)denote the length of the path between nodes s and t
    ● rotations denotes the maximum number of rotations needed to fix u (which in the
    worst-case could be the length of the root → u path, but in best case could be O(1))
    marks method time complexity (extra) space
    complexity
    10 add(p,c) O(1)E O(1)
    10 PhyloTree(a) O(n) O(n)
    10 LCA(s,t) O(d(s,t)) O(1)
    10 fixUp(u) O(rotations) O(1)
    10 computeSets(index) O(n) O(1)
    Examples
    addChild
    Tree (pre) k method Tree(post)
    A 1 addChild(A,B) A
    B
    A
    B
    1 addChild(A,C) A
    B C
    A
    B
    1 addChild(B,C) A
    B
    C
    AA
    BB CC
    2 addChild(CC,DD) AA
    BB CC
    DD
    AA
    BB CC
    2 addChild(CC,null) AA
    BB CC
    null
    A
    B C
    1 addChild(null,D) D
    A
    B C
    A
    B C
    1 addChild(A,D) IllegalArgumentException
    (parent already has 2 children)
    A
    B C
    1 addChild(B,C) IllegalArgumentException
    (child already exists)
    A
    B C
    1 addChild(D,E) IllegalArgumentException
    (parent not found)
    A
    B C
    1 addChild(B,DD) IllegalArgumentException
    (child is not of length k)
    PhyloTree
    method Tree (post) k n
    PhyloTree(A,B) A
    B
    1 2
    PhyloTree(B,A) B
    A
    1 2
    PhyloTree(A,B,C,D) A
    B C
    D
    1 4
    PhyloTree(null,null,AA, BB, CC) null
    null AA
    BB CC
    2 5
    PhyloTree(A,B,C,D,E,F,G,H,null) A
    B C
    D E F G
    H null
    1 9
    PhyloTree(A,A) IllegalArgumentException
    (duplicate element}
    PhyloTree(A,BB) IllegalArgumentException
    (A and BB have different lengths)
    LCA
    Tree k method output
    A 1 LCA(A,A) A
    A
    B
    1 LCA(A,B) A
    A
    B
    1 LCA(B,B) B
    AA
    BB CC
    2 LCA(BB,CC) AA
    A
    B C
    1 LCA(D,C) A
    D E
    A
    B C
    D E
    1 LCA(D,E) B
    A
    B C
    D E
    1 LCA(E,A) A
    null
    B C
    D E
    1 LCA(E,C) null
    A
    B C
    1 LCA(A,D) IllegalArgumentException
    (input D not in the tree)
    A
    B C
    1 LCA(D,null) IllegalArgumentException
    (input cannot be null)
    A
    B C
    1 LCA(B,DD) IllegalArgumentException
    (input DD is not in the tree)
    fixUp
    Tree (pre) method Tree(post)
    A
    B
    fixUp(A) A
    B
    null
    B
    fixUp(B) null
    B
    A
    B
    fixUp(B) B
    A
    A
    B
    C
    fixUp(B) B
    A
    C
    A
    B
    C
    fixUp© C
    A
    B
    C
    B A
    fixUp(A) A
    C
    B
    D
    A B
    C
    fixUp© C
    D B
    A
    A
    B C
    fixUp(null) IllegalArgumentException
    (input is null)
    A
    B C
    fixUp(D) IllegalArgumentException
    (input not in tree)
    A
    B C
    addChild(D,E) IllegalArgumentException
    (parent not found)
    A
    B C
    addChild(B,DD) IllegalArgumentException
    (child is not of length k)
    computeSets
    Tree (pre) k method Tree with Sets
    AT 2 computeSets(0) AT[A]
    AT 2 computeSets(1) AT[T]
    null
    AC AG
    2 computeSets(0) null[A] (intersection)
    AC[A] AG[A]
    null
    A C
    1 computeSets(0) null[A,C] (union)
    A[A] C[C]
    TT
    CC GG
    AC CA AT GT
    2 computeSets(0) TT[A]
    CC[A,C] GG[A,G]
    AC[A] CA[C] AT[A] GT[G]
    A
    C
    1 computeSets(0) A[C]
    C[C]
    A
    G T
    1 computeSets(1) IllegalArgumentException
    (index >= k)
    A
    G null
    1 computeSets(0) IllegalArgumentException
    (leaf is null)
    Interface Practice [30 marks]
    Genes, Revisited
    In lab 3 the Genes problem asked you to compute the number of different strands of length k
    encountered in the input. This problem is similar in many ways, so I recommend you first review
    a sample solution (yours or ours) or the debrief before tackling this problem.
    Method Signature
    public static int genes(InputGenerator gen, int k)
    Method Behaviour
    Decodes each gene (substrand) of length k > 0 in the sequence generated by a given
    InputGenerator as follows, then returns the number of different decodings:
    For gene consisting of input characters cici+1ci+2. … .ci+k-1 we decode it as
    i·ci + (i+1)·ci+1 + (i+2)·ci+2 + … + (i+k-1)·ci+k-1
    Desired Complexity & Notes
    O(n)E time, where n is the number of characters generated.
    O(k+d)E 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).
    ● Forreference, in Java, A=65, C=67, G=71, U=85.
    ● For large n and k, it’s conceivable your decoding will have integer overflow. That’s okay,
    let it overflow. The tests will overflow as well, which is simpler than describing ways to
    prevent overflow.
    Examples
    characters generated
    by gen
    AAAA
    AAAAU
    k
    decoding of individual
    characters
    3 [A·0,A·1,A·2,A·3]
    [0,65,130,195]
    3 [0,65,130,195,340
    ]
    different decodings
    [195,390]
    output
    (d)
    2
    n
    4
    [195,390,665]
    UGCGAAUAUA
    UUUUCCCCAAAA
    3 [0,71,134,213,260,
    325,510,455,680,58
    5]
    [205,418,607,
    798,1095,1290,
    1645,1720]
    12 [0,85,170,255,268
    ,335,402,469,520,
    585,650,715]
    [4454]
    3
    8
    1
    5
    10
    12
    UUUUCCCCAAA
    12 [0,85,170,255,268
    ,335,402,469,520,
    585,650]
    … c64CGAc68… 1 […,
    C·65,G·66,A·67,…
    ]
    (no chars)
    Testing & Autograder

0
[]
[…, 4355, …]
[]
0
<n
0
11
n
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, Revisited
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 sorted order.
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).
Examples
characters generated by gen
k
output
AAAA
AUAAA
3
3
AAA
AAA,AUA,UAA
n
4
5
UGCGAAUAUA
UUUUCCCCAAAA
Testing & Autograder
3
12
(no characters)
AAU,AUA,CGA,GAA,GCG,UAU,UGC 10
UUUUCCCCAAAA
0 0
12
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.
GenesCount
Method Signature
public static AbstractList genesCount(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 order from most frequent to least frequent. When multiple genes have
the same frequency, order them alphabetically.
Desired Complexity & Notes
O(k(n+d log d))AE = O(k(n+kd))AE time.
O(kd) space.
Note: n is the number of characters generated, k is the parameter, and d is the solution.
Since there are 4 bases, d ≤ 4k and thus log d = O(k).
Examples
characters generated by gen
AAAA
k
3
output (d)
AAA
n
4
AUAAA
AUAAUAA
UGCGAAUAUA
UUUUCCCCAAAA
3
3
3
12
(no characters)
0
AAA,AUA,UAA
AUA,UAA,AAU
AUA,AAU,CGA,GAA,GCG,UAU,UGC
UUUUCCCCAAAA
5
5
10
12
0
Testing & Autograder
There are limited local tests in GenesCount.main and tests/GenesCountTest.java; see
Lab 1 for testing instructions. Submit GenesCount.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
comp2402w24l4
Gradescope Autograder
See the Gradescope Autograder section of Lab 1; be sure to replace Lab 1 with Lab 4 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.
addChild
PhyloTree
LCA
fixUp
computeSets
Genes
GenesOrder
GenesCoun

【算法设计与分析】期末复习题(超详细) 刚刚整理了一下电脑的文件,发现了这份上学期的算法设计与分析期末复习题,有需要的文后自取。 阅读详情

相关推荐

PaddleOCR实战指南:从环境搭建到自定义模型训练

本文提供了PaddleOCR从环境搭建到自定义模型训练的完整实战指南。详细介绍了使用Anaconda或Docker搭建稳定开发环境、准备与标注数据集、进行文本检测与识别模型训练的核心步骤与参数调优技巧,并分享了数据增强、模型微调及解决实际项目难题的实用方法,帮助开发者高效掌握PaddleOCR应用。

gold的博客 644

理解springboot中的lombok依赖

关键在理解:Lombok 不是运行时反射,而是通过注解处理器(APT)在直接往字节码里塞方法。这也是为什么需要:新版 IDEA 内置了 Lombok 插件开箱即用;如果你用的老版本 IDEA 报红,去插件市场装一下 Lombok 插件即可。Spring Boot 项目走 parent 管理版本,一般连<version>都不用写。

m0_59247951的博客 277

Python爬虫实战:逆向解析央视频加密参数(附完整代码)

本文详细解析了央视频加密体系的技术实现,通过Python逆向工程实战演示如何解密动态密钥、AES加密和自定义哈希算法等核心组件。文章提供完整代码示例,涵盖GUID生成、参数构造和异步请求处理,帮助开发者掌握现代视频平台的反爬机制破解方法。

weixin_42532473的博客 1130

IDEA 2026.3 远程开发迎来重磅升级

2026.3 的远程开发没有发明什么新能力,它做的是把原来散在多个工具里的流程收进 IDE 一个地方:远程项目进最近列表、SSH 接原生 OpenSSH、等待时间用 Light Mode 填上。以前是“打开一堆工具,终于连上了”。现在是“打开 IDE,连上了,顺手开始写”。少点一次鼠标,就是少骂一句脏话。

weixin_44058951的博客 109

AI驱动芯片设计的端到端验证:AI应用架构师的全流程指南

想象你要建造一座1000层的超级摩天大楼,每个房间都有独特的功能,管道、电路、电梯系统交织如迷宫。传统的检查方式是派1000个工程师逐层逐房手动检查,耗时十年且仍可能遗漏火灾隐患。这就是今天芯片设计面临的困境:7nm芯片含百亿晶体管,相当于百亿个"房间",传统验证方法(人工编写测试用例、随机仿真)已难以应对。本文的目的,是为AI应用架构师提供一份"AI驱动芯片验证导航图",范围涵盖从验证需求分析到芯片签核的全流程,包括AI模型如何融入传统验证工具链、数据如何驱动验证效率提升、以及端到端闭环系统的构建方法。

2501_92132293的博客 1241

【ROS】Nav2源码之nav2_collision_monitor(碰撞监测)详解

nav2_collision_monitor碰撞监视器是一个节点,为机器人提供了一个额外的安全级别。它使用来自传感器的数据,执行若干与避免碰撞相关的任务,绕过成本图和轨迹规划器,监测是否需要紧急停止或者减速。

郭老二 1455

免费 IDEA/DataGrip SQL优化和审核插件 PawSQL Client

PawSQLClient 0.2.1版为JetBrains IDE带来智能SQL优化与执行前审核功能,解决慢查询索引优化、误执行高危UPDATE/DELETE两大痛点。光标定位即生成可直接使用的索引创建语句与改写方案,并提供性能对比;执行前自动拦截高危语句,支持静态分析不阻塞流程。零配置绑定数据源,离线也可结构分析,匿名免登录,结果直达console面板。兼容多数据库与IDE,免费无配额限制,提升开发效率与安全性。

PawSQL的博客 276

RHCA II之路---EX442-10

这题比较耗时,可以多开2个窗口让他跑起来后先做后面的题目。

Q先生 585

IntelliJ IDEA 下载 Gradle 报 504 怎么办?华为云镜像、本地 ZIP 和代理配置(Windows)

在 Windows 上用 IntelliJ IDEA 导入 Fabric 工程时,我遇到了 Gradle Wrapper 下载发行包报 HTTP 504 的问题。本文以 Gradle 9.8.2 为例,介绍华为云镜像、本地 ZIP 和 JVM 代理三种解决方法,并说明如何校验安装包、验证 Gradle 版本及重新同步项目。最后结合实际日志,区分发行包下载失败、JDK 版本不匹配和 downloadAssets 卡住这三类问题。

exlink2012的专栏 320

[QMT量化交易小白入门]-四、如何筛选优质可转债,并进行下单操作

通过上述步骤,成功地使用Python代码完成了可转债的筛选、数据处理和下单操作。当然,这只是一个基础的示例,实际投资中还需要考虑更多因素,如市场环境、资金管理、风险控制等。希望本文能为各位投资者提供一些有价值的参考,助力大家在投资道路上走得更远。

木头大左的博客 1732

在 SAP 中,Primary Cost Element(初级成本要素)与Secondary Cost Element(次级成本要素)的核心区别、作用及业务含义可归纳如下

摘要:SAP中初级成本要素与次级成本要素的核心区别在于:初级要素必须关联FI模块的损益科目,直接影响财务报表,用于记录外部成本(如电费、薪酬);次级要素仅存在于CO模块,用于内部成本分配(如分摊、作业分配),不影响外部报表。初级要素是"外部成本入口",次级要素是"内部成本搬运工",二者共同实现成本的多维度追踪与管理。

金牌架构师 759

打开项目 0.9 秒、内存只有 IDEA 的 1/12:OpenIDEA 用 Rust 把 IntelliJ IDEA 重造了一遍

OpenIDEA 把 IntelliJ IDEA 的键位、工具窗口与处处搜索搬进 Rust 内核:打开项目 0.9 秒、内存 169MB(IDEA 2011MB)。本文拆解其 Tauri+LSP/DAP 架构、官方基准与迁移建议。

话梅糖の优快云 Blog 323

手把手教你使用 YOLOv11/v8 算法 + PaddleOCR 算法完成车牌检测和车牌识别系统,AI智能体,毛玻璃系统,包括PaddlePaddle安装、数据集预处理、模型训练、AI大模型应用等

手把手教你使用 YOLOv11/v8算法 + PaddleOCR算法完成车牌检测和车牌识别系统,AI智能体,毛玻璃系统,包括PaddlePaddle安装、数据集预处理、模型训练、AI大模型应用等。车牌识别系统支持 蓝牌、绿牌、黄牌、双层车牌等车牌识别。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 2782

第 1 章:IDEA 创建 SpringBoot3.5.16 Maven 项目

前置:环境全部就绪(JDK17 + Maven3.9.11 + IDEA 配置完成)目标:使用 IDEA 新建 Maven 类型 SpringBoot3 项目,确认包名、版本正确,项目能正常启动,完成本章启动测试两种创建方式:① IDEA 内置 Spring Initializr(推荐) ② start.spring.io 网页生成导入。我们用第一种。

qq_36158551的博客 283

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

IDEA Git 分支操作手册(后端开发版)

一页速查表(纯操作路径)——SpringBoot/Maven分支管理 创建分支:右下角分支条 → New Branch → 输入名 → 勾选Checkout 切换分支:右下角 → LocalBranches → Checkout(有未提交则SmartCheckout) 查看差异:分支弹窗 → Compare with Current / Show Diff with Working Tree 合并:切目标分支 → 选源分支 → Merge into Current(推荐 --no-ff) 变基:在功能分支

SAP ABAP开发技能记录分享 324

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

把IDEA中Gradle项目的“古法配置”交给 Gradle With Me插件

在AI时代,“古法编程”仍困扰Java后端开发——手动切JDK、配Gradle、对齐环境耗时易错。Gradle With Me插件自动化解决这些痛点:项目打开自动同步JDK/JVM/语言级别,配置共享零摩擦,版本一键升级回退,依赖查询无缝集成,版本信息一目了然。适合多分支、团队协作、新人上手场景,让开发者专注业务与架构。安装搜索“GPVP”即得,告别重复劳动,把时间留给真正重要的代码。

if_you_can_please_do的博客 82

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IDEA 简介:从零认识 IntelliJ IDEA

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

ztI10的博客 151

IDEA 2026.3正式发布:开始轻量化了

作为一名老程序员,我敢打赌,你肯定经历过这种让人极其抓狂的时刻:下午三点,你正喝着咖啡,突然收到同事发来的一小段 JSON 报错数据,或者你想快速验证一个只有十行的正则表达式。于是,你顺手点开了桌面上那个重达几个 G 的 IntelliJ IDEA。结果呢?它先是转圈,然后弹出一个冷冰冰的“Welcome”欢迎界面,逼着你必须(新建项目)或者Open(打开文件夹),甚至还要让你选一遍 JDK 版本。我就想建一个临时的.txt草稿,或者随便写两行 Python 脚本啊!

weixin_44058951的博客 179

IDEA 的优缺点:一份务实的 IntelliJ IDEA 使用评估

IDEA 的核心价值在于把大量重复、易错的开发动作交给工具完成,用较高的资源与学习成本换取长期的开发效率。它的缺点真实存在,但多数可以通过配置和习惯缓解。是否选择 IDEA,关键不在于它是否“最好”,而在于你的项目规模、团队规范、硬件条件和预算是否与它的能力匹配。

ztI10的博客 248

用Rust重写IntelliJ IDEA:169MB替代2GB,0.9秒打开项目的开源IDE

IntelliJ IDEA虽强大却臃肿,启动慢、占内存。开源项目OpenIDEA用Rust重写,保留熟悉快捷键与工作流,体积仅169MB,0.9秒启动。基于LSP支持60+语言,结合Tauri实现轻量跨平台界面。虽暂不替代IntelliJ的Java深度与插件生态,但为多语言开发者提供高效轻量选择,展现Rust+Web技术构建桌面应用的新范式。

weixin_41007138的博客 196

【git】idea中cherry pick和merge的区别

如果你要把分支 B 的大部分东西都拿过来,或者为了以后合并方便,用。

ooooooooooooooxiaosu的博客 396

解决 IntelliJ IDEA “Accessing invalid virtual file“ 报错

IntelliJ IDEA 多模块项目中出现 InvalidVirtualFileAccessException,源于 VFS 缓存与磁盘状态不一致。常见于外部文件操作、分支切换或构建配置错误后,导致代码提示失效、构建失败等异常。根本原因在于 IDE 的虚拟文件系统异步更新机制。解决路径为:优先执行同步、重载构建模型并清除缓存;无效则检查模块配置一致性,必要时删除 .idea 和 .iml 文件,以构建文件重新导入项目。预防建议:使用 IDE 内置重构、避免网络路径开发、定期更新并配置安全软件白名单。

小李同学的博客 371

在 IntelliJ IDEA 中关闭 DevTools(通常指 Spring Boot DevTools 热部署功能)

在 IntelliJ IDEA 中关闭 DevTools(通常指 Spring Boot DevTools 热部署功能)需要从等多个层面协同操作,才能确保彻底关闭,避免出现“删了依赖但热部署仍在生效”的常见问题。

BillKu的博客 354

Java博客项目实战|工程环境与构建:工程目录、PowerShell命令调用与JDK/IDEA/Maven工作机制

本文围绕Spring Boot单体博客项目,梳理项目文件结构与工程根目录,解析PowerShell命令语法与调用运算符,辨析Java环境概念与多版本共存,区分IDEA运行时与项目SDK,介绍Maven构建及相关配置分工。

Brookty的博客 438

IntelliJ IDEA 下载安装:写 Java 和 Kotlin 主流的开发工具

IntelliJ IDEA 是写 Java 和 Kotlin 最主流的开发工具。代码补全准、跳转快、重构稳,报错能直接给出改法。——个人写 Java 项目、学习、做课程作业,都能用完整的一套。

科小怪的博客 151

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
上一篇: MSBA7017 Financial Engineering
下一篇: CS564: Assignment 5
todcode
博客等级 码龄7年 359粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值