Write the pseudocode of an algorithm that takes in two arbitrary length numbers (provided as strings), and computes the product of these numbers. Use an efficient procedure for multiplication of large numbers of arbitrary length. Analyze the efficiency of your algorithm.
I decided to take the (semi) easy way out and use the Russian Peasant Algorithm. It works like this:
a * b = a/2 * 2b if a is even
a * b = (a-1)/2 * 2b + a if a is odd
My pseudocode is:
rpa(x, y){
if x is 1
return y
if x is even
return rpa(x/2, 2y)
if x is odd
return rpa((x-1)/2, 2y) + y
}
I have 3 questions:
Is this efficient for arbitrary length numbers? I implemented it in C and tried varying length numbers. The run-time in was near-instant in all cases so it's hard to tell empirically...
Can I apply the Master's Theorem to understand the complexity...?
a = # subproblems in recursion = 1 (max 1 recursive call across all states)
n / b = size of each subproblem = n / 1 - b = 1 (problem doesn't change size...?)
f(n^d) = work done outside recursive calls = 1 - d = 0 (the addition when a is odd)
a = 1, b^d = 1, a = b^d - complexity is in n^d*log(n) = log(n)
this makes sense logically since we are halving the problem at each step, right?
What might my professor mean by providing arbitrary length numbers "as strings". Why do that?
Many thanks in advance
I have created a JDialog to be opened when I click on the edit button of my JFrame, it is being opened properly and does'nt have any issue, but when I took this code on the windows ce 5.0 device this dialog is being opened twice. hat is i am clicking only once on the edit button but the dialog is appearing twice, I want there should be only one dialog appear on edit button click.
Hi,
Is there any web service available that returns the information of Time zone based on the location name entered. I am preparing the application where in user will enter the place, based on the place entered, I need the information of the timezone (preferably current time and date) of that particular location.
Kindly help me.
Regards,
Dipal
I'm using v1 of EF(.NET 3.5 SP1). I'm subscribing to the SavingChanges event of the ObjectContext wherein I audit deletes for a particular entity type. I need to get to the foreign keys of the entity being deleted i.e EntityKeys of the related entities (RelatedEnds) but the EntityKeys of the related entities are nulls.
Is there any way to get to the foreign keys of an entity which has been marked for deletion?
Does EF null out the EntityKeys of all RelatedEnds for an entity which has been marked for deletion? If so, is there a way I can get hold of the foreign keys?
I want to use code access security and add code modify group. but I dont see .NET Configuration Tool in the administrator tools.
so where can I find this tool?
Thanks in advance.
I did the following steps to use the CDialog in win 32application;
1.Changed the use of MFC to "use mfc shared DLL".
2.Added a dialog resource and added a class for the dialog.
3.Included the dialog class in my main.
4.Tried to call do modal.
when i try to call do modal...i am getting an debug assertion failed.. can anybody help me out of this?
I am new to C++ programming, but I have experience in Java. I need guidance on how to pass objects to functions in C++.
Do I need to pass pointers, references, or non-pointer and non-reference values? I remember in Java there are no such issues since we pass just the variable that holds reference to the objects.
It would be great if you could also explain where to use each of those options.
I have created a simple win 32 application..in which it has a textbox and a button in a dialog window..first when I created this..it didnt display the dialog window and then what I did is added the code below to handle the close(WM_CLOSE) of the dialog window...but I want to know, how to handle the button click event..
LRESULT WINAPI myProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_CLOSE )
{
PostQuitMessage(0);
}
return 0;
}
to call the above in my main pgm I used
SetWindowLong(hwnd,DWL_DLGPROC, (long)myProc)
Hi all..I have 2 dialog boxes in which I will display 1 dialogbox at a time..If I click NEXT in the first dialog box,I will hide the first dialog box and display the second dialog and vice versa...Now say If I move the dialog box after clicking NEXT in the first dialog..and when I click BACK(in the second dialog) ...it goes back to its previous position(to diaplay the first dialog box)..so I have decided to get the current window's position and update to the other window position so that it doesnt move even If I click next/back..I am not sure how to get the windows position and update to other..please help me if you guys know about this..
I am performing delete records by using jquery ajax in php. I want to refresh that content without the use of location.reload() function. I tried this,
$("#divSettings").html(this);
but, it's not working. What's the correct logic to get updated content in div.
Thanks.
Code:
function deletePoll(postId){
$.ajax({
type: "POST",
url: "../internal_request/ir_display_polls.php",
data: {
postId: postId
},
success: function(result) {
location.reload();
//$("#divSettings").html(this);
}
});
}
I have been trying to find if a file_exist in the directory. If not i want to use a different image. But as i am using the file_exists function it always returns false.
The code i used is
while($r=mysql_fetch_row($res))
{
if(!file_exists('http://localhost/dropbox/lib/admin/'.$r[5]))
{
$file='http://localhost/dropbox/lib/admin/images/noimage.gif';
}
else
$file='http://localhost/dropbox/lib/admin/'.$r[5];}
But the function always return false even if the file exits. I checked that by using
<img src="<?php echo 'http://localhost/dropbox/lib/admin/'.$r[5]; ?>" />
This displayed the image correctly.
Please Someone Help Me
I have heard the Google App Engine[java] do not support JDBC and Hibernate. Is it true?
If yes then how do we access the database in Google App Engine.
Also, is there any [basic] sample application which can help me understand how to perform CRUD operations in GAE.
I want to sort one column fetched from mysql DB, and stored in an array. After fetching I am doing below steps.
1- DB Fetching fields array in row format.
->Field1, Field2, Field3, Field4, Field5
2- From that fields array One columns data [Field3], swapping string keywords.
eg. AB013, DB131, RS001
to->013AB, 131DB, 001RS
Now I want to sort above value in new string format
like-> 001RS, 013AB, 131DB
I am doing an undergrad final project, and need to justify my choice of MySQL for the database element of my project. Truth is, it's the only one I can really use, and hence I went for it.
What other database systems could I have used? Any advantages and disadvantages of these over MySQL?
Hi every one im new to php im working on sphider search feature im not getting how to index pdf using sphider can ayone one pls help me out in this thanks in advance.
Does WPF support multiple binding expressions in one statement?
Something along the lines of the following:
<TextBlock Text="{Binding Path=OrderID} shipped on {Binding Path=OrderDate}"/>
I'm guessing that it does but I think I just don't have the correct syntax.
I was reading the article "50 of the Best Websites Developed Using Ruby on Rails". It seems quite impressive.
But is there any way to find out which framework any specific website uses? Say dzone.com, how could I find out which framework it is using?
How could I find websites made with, for example, the Spring Framework?
I am planning to prepare for CEH certification. I am sure there will be plenty of CEH @ StackOverflow. Please suggest me some freely available / downloadable eBooks.
You can also suggest some good books even if it not free.