I have a problem to implement a recursive version of an algorithm that I made, I get different values. Here is the code so Iterative (OK) and Recursive code form that is not OK.
The data sets do not give equal:
The algorithm is given two source and target positions on a board, find the number of paths between them...
Input Example: 5 2 3 4 4
Output Example: 5
Iterative Algorithm ( OK )
Code: #include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <string.h> #include <vector> #include <queue> using namespace std; int n , dp [1000][1000], x, y, xx, yy;
I have an school assignment that asks me to measure the most famous sorting algorithms for performance in terms of number of steps and CPU running time. ( Here I'm testing for running time)
I decided to test for bubble sort first:
#include <iostream> #include <ctime> using namespace std; void bubbleSort(int ar[], int size) { int temp;
[Code] ....
So basically what I want to know is:
1. Is this clock function giving the correct CPU running time?
2. Is there any way to write code that would measure the number of steps for each algorithm?
3.I need to test it for number of integers=100 then 200, then 300... Well you get my point, and I don't want to have to actually input 200 numbers with my keyboard. Is there any way to generate as many entries as I want?
I have to develop minimalistic implementation of RSA algorithm in C for an embedded device.
I'm doing that for two days but I have run into a problem. The N modulus is the limitation for the maximum message value to be encrypted with RSA.
For example theoretically RSA-1024 can encrypt/decrypt messages 1024 bits long but I still cannot understand how to choose p and q values to produce N == pow(2, 1024).
Is it possible to encrypt/decrypt 1024 bits long messages in practice if the N < pow(2, 1024)?
I was trying to implement Big Integer Implementation. I wanted to start with the basic operation of addition. I am having some problems with operator overloading part
I was looking at this tutorial: [URL] ..... And I was wondering if implementing it in MVC would be pretty much the same way? How would I display feed items in the views page using?
I tried something like:
ReaderModel Reader = new ReaderModel(); Collection<Rss.Item> List; List = Reader.GetFeed(); ViewData["RssItems"] = List;
// then in index.cshtml @foreach(Collection<Rss.Item> items in ViewData["RssItems"]) { <h3>items.Title</h3> ... }
I don't think this is right as I'm getting those red error lines...
I've been working on creating a simulator to crash two galaxies together as part of a project to stress test a CUDA super computer. I've got a long way to go and am currently just working on correctly simulating n-body gravity functions. First I will use this to simulate the cores of the galaxies (the black holes) and eventually the stars.
So long story short I'm working on the beginnings of a gravity simulator. At this point I found some basic code that works well but doesn't quite give the effect I'm looking for.
The code below only pulls each object towards each other like a spring faster and faster until they shoot off into infinity. I try to give one of my bodies an initial velocity to get it to orbit another, but it always just shoots straight at the other body. I'm thinking I need to factor in inertia so that the initial velocity doesn't just get calculated away really fast by the other calculations.
I'm really looking for a bit of direction to get a real gravity simulator with orbits and such working right so eventually I can scale it up to a galaxy, throw in 100B stars and let the CUDA run for a month..
As you can see, I'm calculating all the bodies in a vector called "galaxies" with each other, and doing a basic gravity calculation to it. The update_position function simply takes the calculated acceleration and uses it to calculate the velocity and position based on the "elapsedTime".
I think I need to use the Varlet or Runge-Kutta integration methods, after doing a bit more research.
Output to terminal: 0 2 3 1 4 5 but it should be: 0 2 4 5 3 1
Here's my code:
#include<stdio.h> #include<assert.h> /* maxVertices represents maximum number of vertices that can be present in the graph. */ #define maxVertices 100 void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)
I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,
bash-3.2$ g++ stack_str_arr.cpp stack_str_arr.cpp: In member function ‘void stack::push(int)’: stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope stack_str_arr.cpp: At global scope: stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’
Code:
#include<iostream> using namespace std; #define MAX 5 class stack { public : stack();
I'm implementing a 4x4 matrix class and all is going well until the inverse function turned up. I'm trying to implement the inverse function, but I can't seem to get my head around it.
I've tried the internet, but found nothing useful. Also, I've looked into source code of other programs/libraries that implement a matrix class, but the code is unreadable.
How I can implement this damn 4x4 inverse function? I know the process of inversion, but putting that process into code is proving quite a challenge.
In addition, I do have some code, but it's unmanageable and inefficient at the moment. If you want to see it, just ask.
Additional question(s): What applications does the inverse matrix have in 3-D?
I'd like te have a heap which contains any item inserted by me. However, when I insert the values, if I delete the min value of this coded heap twice, I get the min value uncorrect.I could not find where the mistake is.
Code:
void BinaryHeap::percolateDown(int hole) { int child = hole*2; while (child < size) {
I was trying to implement a hash function in c++. This is just for learning purposes and not for a class project or assignment question. I had some questions before I started programming it:
1) Is it meaningful to have a hash function which maps string to string, string to int, int to int, float to int? 2) Can we have a template implementation which does element to element hashing?
I looked at several sources for a clear understanding of concepts and implementation technique but could not find a good source for reading about hashing.
I created a structure Vector and implement some functions to make the new defined type (vector) dynamically allocated and resized (inspired from the C++ implementation of the dynamic arrays : vector). I need to assign a structure to every vector element but I am not sure that I am doing it right:
here is the structure that I've defined:
typedef struct { void** mem; // to make this parametrizable I want the void* to point to a Structure (referenced with * a pointer) unsigned long elems; unsigned long elemsize; //element size
[Code] ....
I believe I have serious problems with pointers, values and dereferencing a pointer.
So I'm going through and trying to do a recursive implementation of a Heap. I keep getting access violations for some reason on my sifts (_siftUp) - even though I'm trying to insert into sub[0] (currSize = 0 in the constructor). I don't think either of my sifts are implemented correctly, are they?
What is the benefit on separating the abstraction and implementation.
The below code
Code: class FileProcessor { public: virtual void processFile(); }; class DocProcessor : public FileProcessor
[Code] ....
Till now it is fine. suppose DocProcessor and ExcelProcessor uses two big algorithm to process these file types then I still can have subclasses like :
class Algorithm1 : public DocProcessor { public: void algorithm(); //which will be called as per the algorithm class instantiated for to process };
[Code] ....
same for ExcelProcessor class
Here everything looks fine to me. [ I have not used the bridge pattern to separate the abstraction and implementation]. The only thing i can achieve using bridge is that the number of classes will be reduced if new class like jpgProcessor is introduced or new algorithim is introduced.
Then why it is recommended that always separate the abstraction and implementation...
I have a COM exe which runs fine on all machines that I have used except one. On a particular machine, the COM exe does not start even after trying to execute it manually (do a double click on the file from explorer).
There are no error messages as well. what could be happening ?
I'm trying some codes about string arrays and taking array length. But i have some problems. I can't get length of string and can't send to a function.
------------------------ #include<iostream> #include<cstring> #include<string> using namespace std; void GetLength(string); std::string Words[]={"table","gun","programming"}; int main() {std::string InputWord;
binary [] is the char array and count is... you know how many times the for loop will turn. So my question is, how do i know the length of the number ? Any function that shows the integer length ? because its impossible to know what count is equal to. like 100 is 3.