Giter Club home page Giter Club logo

Comments (10)

Abner3 avatar Abner3 commented on May 28, 2024 2

Hello, I also had a question about the output in the console and asked during office hours.

Assuming you didn't modify testRuntime() in TernaryHeapQuizTest:
If you look at the line that starts with 1000 the 47 is how long it takes to add using a binary heap and the 62 is how long it takes to add using a ternary heap. The 94 is how long binary heap took to remove and 126 is how long ternary heap took to remove. All time units are in milliseconds.

from dsa-java.

Kaseyc27 avatar Kaseyc27 commented on May 28, 2024

Hello TFloyd. What really helped me was running the test in two different runs. Like in separate lines. If you read the documentation. I believe the first line is the time for add and the second line is the time for remove. If ran by itself. I am not sure if binary heap or trenary heap is either/or. In this case, the chart created is comparing the add methods of both binary/trenary heap, then the remove methods of binary/trenary heap.

from dsa-java.

marvinquiet avatar marvinquiet commented on May 28, 2024

Thanks for your guys' reponses.

Below is the code what Abner3 tries to refer to:

    @SafeVarargs
    final void testRuntime(AbstractPriorityQueue<Integer>... queues) {
        final int begin_size = 1000;
        final int end_size = 10000;
        final int inc = 1000;
        final Random rand = new Random();

        for (int size = begin_size; size <= end_size; size += inc) {
            // JVM warm-up
            benchmark(queues, size, 10, rand::nextInt);
            // benchmark all priority queues with the same keys
            Time[] times = benchmark(queues, size, 1000, rand::nextInt);

            StringJoiner joiner = new StringJoiner("\t");
            joiner.add(Integer.toString(size));  // size of heap
            joiner.add(Arrays.stream(times).map(t -> Long.toString(t.add)).collect(Collectors.joining("\t"))); // "add" of the input heaps
            joiner.add(Arrays.stream(times).map(t -> Long.toString(t.remove)).collect(Collectors.joining("\t"))); // "remove" of the input heaps
            System.out.println(joiner.toString());
        }
    }

I added some comments in the above code around the joiner.add and hope it helps.

So in the end, if you are comparing 2 heaps, it will become:
size, heap1 add, heap2 add, heap1 remove, heap2 remove

from dsa-java.

TFloyd1989 avatar TFloyd1989 commented on May 28, 2024

Oh okay thank you all. Should the binary heap add and remove be faster than the ternary heap add and remove?

from dsa-java.

marvinquiet avatar marvinquiet commented on May 28, 2024

As for plotting, you can do it either way by using an Excel or some online graph tools where you can input your data.

from dsa-java.

marvinquiet avatar marvinquiet commented on May 28, 2024

As for which is faster, please refer to the course notebook to find the answer and I believe you can find it out!

from dsa-java.

TFloyd1989 avatar TFloyd1989 commented on May 28, 2024

According to the notebook log base 3(1000) for ternary > log 10(1000) binary. This is correct?

from dsa-java.

lujiaying avatar lujiaying commented on May 28, 2024

@TFloyd1989 Sorry, we can not answer the question that is directly related to quiz questions

from dsa-java.

lujiaying avatar lujiaying commented on May 28, 2024

According to the notebook log base 3(1000) for ternary > log 10(1000) binary. This is correct?

However, for binary it should be log base 2(n)

This is depicted in the textbook

A binary heap is a PQ that takes O(logn) for both add() and remove()

And in computer science, if the base of log is ignored, it typically means log base 2.

from dsa-java.

jdchoi77 avatar jdchoi77 commented on May 28, 2024

Hello, I also had a question about the output in the console and asked during office hours.

Assuming you didn't modify testRuntime() in TernaryHeapQuizTest:
If you look at the line that starts with 1000 the 47 is how long it takes to add using a binary heap and the 62 is how long it takes to add using a ternary heap. The 94 is how long binary heap took to remove and 126 is how long ternary heap took to remove. All time units are in milliseconds.

@Abner3 thanks for answering this but figuring out the output format of this method is a part of assignment so I'm closing this issue.

from dsa-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.