running-time

Time complexity of Sieve of Eratosthenes algorithm

From Wikipedia: The complexity of the algorithm is O(n(logn)(loglogn)) bit operations. How do you arrive at that? That the complexity includes the loglogn term tells me that there is a sqrt(n) somewhere. Suppose I am running the sieve on the first 100 numbers (n = 100), assuming that marking the numbers as c...

c++ thread running time

I want to know whether I can calculate the running time for each thread. I implement a multithread program in C++ using pthread. As we know, each thread will compete the CPU. Can I use clock() function to calculate the actual number of CPU clocks each thread consumes? my program looks like: Class Thread () { Start(); Run(); Computing(...

c++ quick sort running time

I have a question about quick sort algorithm. I implement quick sort algorithm and play it. The elements in initial unsorted array are random numbers chosen from certain range. I find the range of random number effects the running time. For example, the running time for 1, 000, 000 random number chosen from the range (1 - 2000) takes 4...

delete all from table

what's faster? DELETE * FROM table_name; or DELETE * FROM table_name where 1=1; why? does truncate table work in access? ...

Find if there is an element repeating itself n/k times

You have an array size n and a constant k (whatever) You can assume the the array is of int type (although it could be of any type) Describe an algorithm that finds if there is an element(s) that repeats itself at least n/k times... if there is return one. Do so in linear time (O(n)) The catch: do this algorithm (or even pseudo-code) ...

How to prove worst-case number of inversions in a heap is Ω(nlogn)?

I am busy preparing for exams, just doing some old exam papers. The question below is the only one I can't seem to do (I don't really know where to start). Any help would be appreciated greatly. Use the Ω(nlogn) comparison sort bound, the theta(n) bound for bottom-up heap construction, and the order complexity of insertion sort to show ...

How to add events to Controls created at runtime in Excel with VBA

I would like to add a Control and an associated event at runtime in Excel using VBA but I don't know how to add the events. I tried the code below and the Button is correctly created in my userform but the associated click event that should display the hello message is not working. Any advice/correction would be welcome. Dim Butn...

error in running a simple swing program

i just started learning swings. And thought of trying out a simple program, but i can't run it. import java.awt.*; import javax.swing.*; class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.orange); g.fillRect(20,50,100,100); } } I am getting the following error: E...

Help me understand how the conflict between immutability and running time is handled in Clojure.

Hello, Clojure truly piqued my interest, and I started going through a tutorial on it: http://java.ociweb.com/mark/clojure/article.html Consider these two lines mentioned under "Set": (def stooges (hash-set "Moe" "Larry" "Curly")) ; not sorted (def more-stooges (conj stooges "Shemp")) ; -> #{"Moe" "Larry" "Curly" "Shemp"} My first th...

Python garbage collection can be that slow?

Hi, I have a problem with my python application, and I think it's related to the python garbage collection, even if I'm not sure... The problem is that my application takes a lot of time to exit and to switch to one function to the next one. In my application I handle very large dictionaries, containing thousands of large objects whic...

accurate running time of each line and total running time

Show the accurate running time of each line and total running time for the following function: int f1(int n, int A[ ], int B[ ]) { if ( (n>=5) || (n<0) ) return 0; for (int i=0; i<=n; ++i) { A[I] = 0; for (int j=0; j<i; ++j) ...

PHP running time in Apache

I want to run a PHP file/function that will not stop until it finishes it work. Is there any option for that? (It will not print any information to the browser, it will make calculations and it will store them on a database. Note: The Apache server is in my PC. ...

Read Macros from External File quickly

Here is my code, For Each pj In wdApp.Application.VBE.VBProjects x = pj.FileName y = pj.Protection If x <> "" Then If y <> "1" Then For Each vbcomp In pj.VBComponents For i = 1 To vbcomp.CodeModule.CountOfLines newMacro = vbcomp.CodeModule.ProcOfLine(Lin...

BigO bound on some pseudocode

AllDistinct(a1 , . . . , an ) if (n = 1) return True for i := n down to 2 begin if (LinearSearch(a1 , . . . , ai−1 ; ai ) != 0) return False end return True Give a big-O bound on the running time of AllDistinct. For full credit, you must show work or briefly explain your answer. So the actual answer for this according to ...