Hi, below is my code for binary search algorithm. My question is, what if I enter more than 1 same numbers in the array? How should i modify my code to print out all the locations where that same number is found? For example, if I entered the number 2 at three different locations, let's say, array[3], array[6] and array[17], how should I ask my compiler to return all the three locations instead of one? P.S. the below code returns only 1 position even if the number is entered multiple times. Thanks in Advance :) // Binary Search Algorithm ... … |
+0 forum
4 | ||

How to calculate time complexity of any algorithm or program .... need help on this.. |
+2 forum
114 | ||

If I have the following code, let's say the Parent class has the complexity of O(n^2) according to methods included in the Parent. So if I want to calculate the complexity of inherited class (Child class), does it take the Parent class complexity and its own complexity? something like that complexity of child class = O(O(Parent)+O(Child)) ? public class Parent { private int number; // more stuff } public class Child extends Parent { public void setNumber(int newNum){ this.number = newNum; } } |
+0 forum
2 | ||

Reusable Code Snippet
Farmer crossing river with wolf, duck, bag of corn This snippets contains a python program to find a shortest solution to the problem of the farmer who whishes to cross a river. The boat can only contain two things, including the rower. The farmer comes with a wolf, a duck and a bag of corn, and he can't leave the duck alone with one of the other items because the wolf would eat the duck, or the duck would eat the corn. The program shows how to use a `collections.OrderedDict` to implement a stack without repetitions. This is used to traverse a tree of states. These states, encoded as … |
+0 forum
5 | ||

Hello. I want to submit a code stuff with an explanation. It is not a valid code. Someone can help me to find error? <code> ** ** I'm trying to build a program that change numbers writen in decimal notation. If we consider each ranges of numbers: unities, 10-es, 100-es and etc, the pattern is the same. If we take an array of characters ["a", "b", "c"], we have: 1 --> 'a', 2 --> 'aa', 3- --> 'aaa' 4 --> 'ab', 5 --> 'b', 6 --> 'ba', 7 --> 'baa', 8--> 'baaa', 9-->'ac'. 0 -->'' Now we have as representations … |
+0 forum
16 | ||

Implement the following class.the class has two instance variables num for the fraction numerator and den for the fraction denominator. public class Fraction implements Comparable<Fraction> public Fraction(int num, int den) // initialize instance variables public int den() // returns the denominator public int num() // returns the numerator public Fraction mediant(Fraction that, int n) // returns the medianfraction of this and that fraction public boolean equals(Object that) // overrides the equals method public String toString() // returns the fraction as a string “num/den” The mediant of two fractions a/b and c/d , given an integer n is the fraction(a+c)/(b+d)only if … |
+0 forum
6 | ||

Hi im trying to learn software engineering at home but m confused about two things should i learn coding 1st or learn algorithms 1st i already started learning coding but some people said that i should learn algorithms 1st then i started looking for algorithms courses online but most of them require knowledge in programming to understand so what should i do !! |
+0 forum
11 | ||

Dear all, I need the code for counting sort algorithm but I try this code but is not working #include <iostream> #include <conio.h> #include <time.h> #include <stdlib.h> //srand and rand functions using namespace std; void add_random_numbers(long arr[], long b); void countingSort( long left, long right, long vector[], int k, long length); long const MADH_MAX_VEKTORIT = 110000; int main() { long random_vector[MADH_MAX_VEKTORIT]; long vector[] = { 1000, 10000, 15000, 25000, 30000, 45000, 50000, 60000, 75000, 90000, 100000 }; long num_elem; clock_t tn, tp; srand(time(NULL)); cout << "AlgorithmttNumbers_of_emelmentstttTime(s)n"; cout << "--------tt-------------------tt-------n"; for (long i = 0; i < 11; i++) { num_elem … |
+0 forum
1 | ||

Hi! I want to know how artificial intelligence system(s) work(s)? I want to know whether artificial intelligence depends upon software i.e special type of software having special algorithms or it depends upon special type of hardware having characteristics like human brain cortex and neuron system or both of them(software and hardware) working in harmony. I know the real world present artificial intelligence system examples like the **Google Search Engine**, **Siri**, etc. All of them are, according to my knowledge, totally software based. So, I want to know which thing(software or hardware) mostly affects the **AI** System or both are required. … |
-1 forum
13 | ||

I am trying to develop the genetic algorithm to solve Traveling Saleman problem and part of my challenge is to generate random tours long enough and write a fitness function to evaluate the cost incurred for each of the random tour. I have attempted to write the following. My objective is to generate random tours from the city to city distance matrix without any repetitions in the tour. The random function should return a tour without any cities repeating twice. Please can any one help me with the logic for this problem: class ran { public static void ranper(int n, … |
+0 forum
6 | ||

**hello peeps and geeks, i am missing the MinSpanningTree function here.. any help please? need to fill up the function to get a) Minimum spanning tree cost for the graph b)Spanning tree path for the graph. E.g in matrix or adjancency list. ** #include <iostream> #include <ctime> // For time() #include <cstdlib> // For srand() and rand() #define N 6 #define infinity 9999999 using namespace std; void MinSpanningTree(int AdjMat[N][N]) { cout<<" The minimal Spanning Tree cost is "; cout<<"The minimal Spanning path is "; // A B C D } int main () { int AdjMat[N][N] = { 0, 1, … |
+0 forum
2 | ||

I would like to propose a link thread for posting listings of sites on CS topics not tied to a specific language. Two that come to mind as being relevant to some of the more common questions would be the [OS Dev Wiki](http://www.osdev.org), and the similarly themed but less established [Compiler Dev Wiki](http://www.compilerdev.com/). [Rosetta Code](http://rosettacode.org/wiki/Rosetta_Code) would also be relevant, for comparisons between languages and paradigms. A few others to start with might be: * [The Dictionary of Algorithms and Data Structures](http://xlinux.nist.gov/dads/) * The [Portland Pattern Repository](http://c2.com/ppr/), home of the original WikiWikiWeb as well |
+1 forum
2 | ||

Hello, I've got a question about a project in my operating systems class. The task was to create a program that lets the user choose a variety of cpu scheduling algorithms and simulates them with random data or data from a file. I've already done it for first come first serve, shortest job first, and priority. I've got the round robin code to work I think I just have no idea how to calculate the average wait time (AWT) or average turn around time(ATT). Here is my code for FCFS algorithm: void FCFS(job jobList[iterationsToRunTest][numJobs], results &output) { queue <job> q; … |
+0 forum
0 | ||

At the moment I am trying to decide which book to buy, there are many that I think would be very interesting, but some are most likely beyond me. The books in my list, along with my thoughts on them are: Concrete Mathematics (I believe this is probably too advanced for me at the moment, however I am revising mathematics and will want to pick this up in a few months) The art of computer programming volumes 1-4 (I have read many times that one should be familiar with the concepts in Concrete Mathematics before attempting to consume this book, … |
+0 forum
13 | ||

alright guys so am havign trouble finding a way to search for seats that are toghether, my pgram consists of a theater with 20 x 10 seats, i have created a seatSelection class and the theater file which has the main. Ok so heres a sample output of how it should look like Premium(1) or Regular (2): 1 # of tickets: 5 Your seats are: 1A 1B 1C 1D 1E Premium(1) or Regular (2): 2 # of tickets: 4 Your seats are: 6A 6B 6C 6D it groups the people toghter, what i did was set up a 2d array … |
+0 forum
3 | ||

Hello, What is the best way to check my code? I have written a program that counts the swaps required to sort an integer array using the Bubble, Selection, Insertion and Quick sort methods. How can I be absolutely certain that my swap counts are correct? Will someone take a look at my code and make a suggestion? Is there code on the web that will confirm my results? Thanks, Jim |
+0 forum
4 | ||

Hey guys, I'm trying to understand how radix sort works in C++ : I've looked over the C++ implementation from wikipedia: void radixsort(int *a, int n) { int i, b[MAX], m = a[0], exp = 1; for (i = 0; i < n; i++) { if (a[i] > m) m = a[i]; } while (m / exp > 0) { int bucket[10] = { 0 }; for (i = 0; i < n; i++) bucket[a[i] / exp % 10]++; //accumulate for (i = 1; i < 10; i++) bucket[i] += bucket[i - 1]; //transfer for (i = n - 1; … |
+0 forum
1 | ||

Hi everyone, I'm learning C# at the moment and really enjoying it. I'm wondering though how I can develop my own algorithms. do I need to read on data structures and algorithms? Is there a book for all programming languages so you can apply the knowledge to basically any programming language you use (E.g Java, C#, PHP, JavaScript, Python..etc)? Links will help also. thanks, |
+0 forum
7 | ||

Hi I have a CS class assinment that invloves solving a word search puzzle with a brute force string matching algorithm. I have made a lot of head way in getting the four search methods to work, however when I search for words that end along the edges of the puzzle they are never found. Some help getting this part done would be nice, thanks!' #include<iostream> #include<cstdlib> #include<string> #include<iomanip> #include<fstream> #include<cctype> #define SIZE 12 //Global variable to hold the size of 2D array. using namespace std; //****************************************************************************** //structure defintion struct arrayData { string qury; //Variable to hold the term being … |
+0 forum
6 | ||

What is the running time for the following recursive function: pubic static int Sum(int [] a, int start, int end) { if ((end – start) = =0) return a[end]; else { int mid = (end + start) / 2; return (Sum(a, start,mid) + Sum(a,mid+1,end)); } } Can someone please explain step by step on how I would figure this out. My attempt is that I only care about the if statement and int mid here (i think). "If" would be a simple n and would "int mid" be log_2n giving a running time of nlog_2n? |
+0 forum
3 | ||

Hello all, I'm having trouble getting google to give me anything useful because I don't know the name of the algorithm I'm looking for. ![line_types](/attachments/large/1/line_types.png "line_types") This image shows different ways of connecting two points together, A is just plain lines, C is bezier curves but what is the algorithm that is usually used for B? the double 90 degree bent line, I've googled various different phrases with no luck, most give me smooth curves like C. any information onf the name of the algorithm usually used for B would be helpful, or links would be good too. NOTE: D … |
+0 forum
1 | ||

I am currently working on kind of multi-graph structure. The thing is that two graphs are needed for my application which span the same vertices but with two distinct set of edges (i.e., a multi-graph). The first graph is a binary search tree, while the second graph must be general (directed / undirected, or bidirectional, possibly with cycles, etc.). The B-tree is used for fast queries of nearest nodes, while the second graph is needed for path-planning (e.g., in the style of shortest-path algorithms). Both graphs have to be completely mutable (reconnections, moving nodes around, adding/removing nodes and edges to … |
+0 forum
12 | ||

i am looking for information source on an algorithm for parametric surfaces design in 3d. i just need advice on how to go about it. the language used for the algorithm is not a matter but rather the idea on how the algorithm is to be is of paramount importance. below i have shown what i want to achieve. |
+0 forum
1 | ||

Hello! I just want to ask you guys if anyone can help me reedit my program from BFS to DFS. I know how BFS works but i can't figure it out how to write the sintax. So i would please ask you guys if you could help me out. Heres code of my last program: #include <iostream> #include <queue> using namespace std; const int bela = 0; const int siva = 1; const int crna = 2; const int nil = -1; const int inf = 2147483647; char menu() { cout << "Iskanje z razvijanjem v sirino - izbira:"; cout … |
+0 forum
1 | ||

[ATTACH=right]16169[/ATTACH]Today on [URL="http://news.google.com"]Google News' Top Stories front page[/URL] you could find plenty of coverage of the ruling allowing the [URL="http://www.daniweb.com/news/story299633.html"]"jailbreaking" of iPhones[/URL] as well as some discussion of the soon to be released update of the Android operating system and continued skepticism about Microsoft's upcoming Phone 7. Just above most of these headlines was a link to Google News' Mobile Technology "section," a new feature and a slight alteration to the way Google News' algorithms organize its thousands of headline links into something useful. Clicking over to the front of the [URL="http://news.google.com/news/section?pz=1&cf=all&ned=us&hl=en&q=Mobile+Technology"]Mobile Technology section[/URL], however, brought to light the shortcomings … |
+0 forum
4 | ||

I see that there are many questions here regarding complexity analysis, specifically regarding the Big-O notation of algorithms. I will attempt to shed some light on the subject. I will start with an introduction, after which I will go over some common complexities and last we will solve a few simple examples for practice. [U][B]1. Introduction[/B][/U] When looking at the Algorithm, we want to know its order of growth regarding the input size given to it. Consider two simple algorithms that sort an array of [TEX]n[/TEX] cells. The first algorithm is doing [TEX]n[/TEX] operations in order to complete the sort, … |
+13 forum
11 | ||

Every day on his way home, little Billy passes by his great aunt Clara Mitchum's house. Generally he stops in for a chat with his aunt and sometimes he asks for some lollies. When he does, she generally gives him some, but then adds now don't be asking for any more for another N days where N is some positive integer. If N = 1 that means he can ask for some on the next day, but for example if it is April 6 and N = 4 then he must wait until April 10 or later before asking for … |
+0 forum
1 | ||

Let me first describe my situation. I have a list of Hex values, which are called BaseID. They are chosen [B]such that logical OR between any number of them will give you a unique ID[/B] which is called FinalID. That is, my BaseID values are as follows. BaseID = { 0x01, 0x02, 0x04, 0x08, 0x10, ... } The critical point is that I don't know how many BaseIDs that I will have [B]before I run the program[/B] (I do get a list of BaseIDs once I run the program as it is read from a file), or [B]how many out … |
+0 forum
9 | ||

Hello. I have tried numerous string permutation methods, and they work, but not for what I need. I need to permute a string such that I don't get any reversals: abcd abdc acbd acdb adbc adcb * bacd badc bcad bcda * see how these are reversals of each other? this is the first few lines of output when I try to permute "abcd". Unfortunately I can't think of an algorithm to skip over any reversals. Thanks |
+0 forum
3 | ||

I am looking for computer algorithm that not in my directory codewordblog.blogspot.com. please inform me your suggestions........ |
-1 forum
4 |

The End.