If you 'select' the O(n) entry, it shows the actual formula used to plot the curve
77.171939*n + -2095873.106014
In other words, if the system was actually linear, each element you add to the array would cost an additional 77 nanoseconds.... and the cost starts at -2 miliseconds.
I visualize the complexity as being the a combination of components.
for example, a merge-sort.......
has some basic overhead that needs to happen regardless of the size of the data.
that is the O(1) component.
then it has some work that it has that is proportional to the size of the data.... which is the O(n) component (like scan the data from beginning to end).
then there's also a log component, because it divides the data in a binary way.... and merges pre-sorted binary components...
So, the overall time for the run will be some O(1) time, plus a O(n) time, and then for each N there's a log-n time as well.
I would expect a curve that for any scale (x axis value) is the sum of the overhead, the linear component (the time reqired for each component), and then the search time (the log n time).
a curve like:
A * n * log (B *n) + C
where C is the overhead....
and B is the time in the log function, which happens log-n times.
and the A is the time needed for each n in the data.
Add them together, you get the time required for scale N
The complexity is n-log-n, but the performance can be improved by reducing any of the A,B, or C coefficients too.
reduce the time it takes to process each n, and you win.
reduce the constant-time C component, and you win.
This can be very useful in the decision making process, I hope, because you can possibly identify where your scalability is failing to grow in a friendly way.
Or, you can use it to do 'black-box' testing of third-party code.
Error 2 The item "Grammar\VBABaseListener.cs" was specified more than once in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter. Rubberduck.Parsing
I'm relatively new to Java and decided to make a Memory Match game. Below is the code:
Here's Card.java:
import javax.swing.JButton;
@SuppressWarnings("serial")
public class Card extends JButton{
private int id;
private boolean matched = false;
public void setId(int id){
...
In reference to codechef's counting non decreasing sequences , problem ,
I came up with the following solution,
from itertools import combinations_with_replacement
t = int(raw_input())
for x in range(t):
n,l,r = map(int, raw_input().split())
lst = []
for x in range(1,n+1):
...
I'm trying to develop a program that stores currency values. In my particular application I only care about two decimal of precision (cents) but have read it's a good idea (for accuracy when dealing with interest rates) to store 4 digits.
I didn't notice a "currency" class in either boost or c++...
I wrote the following solution to the coin partition problem. I use Euler's recurrence relation for the partition of n and that modular addition is associative; (a + b) % n = (a % n) + (b % n) % n.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// generalized pentagon...
I am trying to multithread a for loop, and this works so far. How can it be improved? Have i done anything inccorrectly?
The work is broken up into blocks and the block variable is the amount of objects to process per thread.
TEST CLASS
public class TaskTest extends MultiThreaded {
public...
I am currently completing a Ray Wenderlich iOS tutorial over #Augmented Reality , and as I came to this problem concerning the setLocationManger not being found in the MainViewController interface. Which I don't understand because I thought this was included in the class of CoreLocation/Corelocat...
I am designing a datamodel for a new project.
One of the requirements specifies that some objects can point either a person or a company.
What is the smartest way to achieve that?
I have thought about a table link "actor" like this (drawn with the excellent yUML.me BTW) :
In the actor table...
I'm trying to learn to program on my own with the help of books and the Internet and thought I'd start a project (a sub-project for a project).
I want to build a dictionary that allows multiple keys for one value:
d = mkdict()
d['what', 'ever'] = 'testing'
d['what'] is d['ever'] #Â True
I thou...
Disclaimer: It's literally the second time I write in Haskell.
The purpose of this module is to provide some basic operations with IP addresses (and networks).
At the moment I only implemented the successor operation, that returns a next address in the range if it exists.
Eg: for 192.168.1.1 i...
@rolfl many people seem to have problems knowing what the complexity of their code is. I figured that by providing a void doSomethingToFindComplexity(int n) method, and in that method create an input and sort it using some algorithm or whatever, it would be possible to estimate the actual complexity of the code.
I am trying to make a text to speech program, using festival. When running it in command line
sudo festival (SayText "Hello")
In python :
import subprocess
subprocess.call(["festival"]) subprocess.call(["(SayText\"hello\")"])
It raises an error, I put the back slashes in python so that it wi...
New to this site!
Im attempting to upload some form data to a PHP database I have made on my server.
The information I manually added via PHPMyadmin shows up but the form submitted data is not being added to the database.
I am checking the information on a separate website that connects to the...
Multi-threaded concepts are complicated at times. If you really want to learn multi-threading, it is important to get it right. Some things can be extremely difficult to get right. I can highly recommend reading Java Concurrency in Practice.
Overall
It is not that often I see "multi-threaded co...
You will probably also find the question interesting. And the code nasty.
I'm a complete newbie to Elixir, but I managed to bang together this working example of Ascii85 for a project I'm working on in my spare time.
I find some awkward repetition in here which I have tried to replace with iteration but it just made the code harder to read. There is also some lop-side...
This PHP User System was built with MySQLi and I also used Composer. I'm planning to improve this, and add more stuff and release it as a sort of a module for Composer. Here is my source code:
User.php (Controller File in the src/Controller) folder.
<?php
namespace Application\Controllers;
use...
This PHP User System was built with MySQLi and I also used Composer. I'm planning to improve this, and add more stuff and release it as a sort of a module for Composer. Here is my source code:
User.php (Controller File in the src/Controller) folder.
<?php
namespace Application\Controllers;
use...
Sure. Welcome to Python and also to SO. Please give a brief skim to the FAQ and browse some other few beginner Python questions to see good tips on how to ask your question here to get the best response. Also you might like CodeReview for general code-reviews as opposed to specific questions with well-defined objective answers. — smci57 secs ago
Spec-
In the game the children sit in a circle and one person outside the ring (the leader) sings a song with a fixed number of words. Moving clockwise around the circle, the leader points to a new child in the ring for each word in the song. The child being pointed to on the last word of th...
I have write this code to get in descending order, input is taken from file. i want output as case#1:something here case#2: somethig here and so on. case1 contains first line and case2 contains line 2 of file, but i cant get it my code is
public static void main(String[] args) throws NumberForma...
in the past two days I have created a mobile-first web app with sessions using the new JWT standard that stores tokens in redis (for revocation) and user information in mongoose
Card class
Your id does not change after being set once. This makes it perfect for being set inside a constructor. This will also allow you to make it private final int id; . It is a good practice to use final fields whenever possible.
Instead of:
Card c = new Card();
c.setId(val);
Do:
Card...
The source of the problem is here.
Given an array of integer elements, return the maximum difference of any pair of
numbers such that the larger number of the pair occurs at a higher index
than the smaller.
Here is my implementation in Java.
package algo.mindiff;
public class Main {
...
I started with this really jumbled initialize method:
class MyPhaser
attr_accessor :event_uuid,
:organization,
:location,
:map_id,
:phase_name,
:phase_timestamp,
:phase_ui_config_json,
:phase_ui_config_json_v2
def initialize(args = {})
if args[:source_ui_conf...
Please review this solution for matching parens for correctness and nesting.
def matchParens(pstring):
plist = [l for l in pstring]
newlist = []
if plist[0] == ')' or plist.count('(') != plist.count(')') or plist[-1::] == '(':
return False
while len(plist) > 0:
he...
I think my Table class may be doing too much. I feel as though I should perhaps create a separate Input class that deals with editing the table's rows.
My main problem is knowing when to create a new class. Is it true that the table is doing too much? Which things should be made into other class...
@laggingreflex This code seems to have been shortened down and stripped of context, it would likely be considered "example code" on Code Review and therefore closed as off-topic. — Simon André Forsberg35 secs ago
@SimonAndréForsberg: but I never said Code Review was for "Why doesn't this code work?" questions. I said it was for code reviews. And I directed them to the FAQs. — smci33 secs ago
@smci Simon was simply pointing out that this question is very much so a "Why doesn't this code work?" question, so it's probably not the best question to be pointing a new user toward Code Review for. — nhgrif11 secs ago
There's one advertisement that frequently appears in the right margin of Stack Overflow pages, that I find annoying and distracting. Does anyone else feel the same way?
The advertisement in question is for a Microsoft Developer Camp. It has a man with his arms folded. To the left of the man...
@ChristopherW This question isn't asking for a Code Review, and wouldn't be appropriate for Code Review. That may be one aspect of this question, but the user is asking for help writing additional things that aren't already implement (try/catch, checking for installed applications, Windows version check, calculate virtual memory, etc.) This question is probably "Too Broad" for Stack Overflow, but it's definitely off-topic for Code Review. — nhgrif1 min ago
And I never referred this question to Code Review. I told them to read the FAQ, and also that Code Review is a separate site for a different purpose. This question had already been answered here, so there was very little chance they would both misunderstand and go repost it there, of all places. I will take care not to give any impression to the contrary, ok? — smci29 secs ago
If a triplet of segments A, B and C are triangle triplets if and only
if
- A + B > C
- A + C > B
- B + C > A
Is there a better implementation for this problem?
#include<vector>
#include<iostream>
void findTriangleTriplets( std::vector<int>& vec_input, std::vector<std::vector<int
If a triplet of segments A, B and C are triangle triplets if and only
if
- A + B > C
- A + C > B
- B + C > A
Is there a better implementation for this problem?
#include<vector>
#include<iostream>
void findTriangleTriplets( std::vector<int>& vec_input, std::vector<std::vector<int
My C++ isn't the greatest. Are you passing in a vector by value, and a vector by reference and returning void, and the one passed by reference is filled?
Why don't you just pass in one by value and return a vector instead of returning void?
Also, which version of C++ did you use? Is it necessary to tag with both c++11 and c++14? Does just c++ cover it?
Please let me know if there is a shorter way...
static bool isSortedArray(int[] ar, int length)
{
if (length == 0)
return true;
bool temp = isSortedArray(ar, length - 1);
if (temp && ar[length - 1] < ar[length])
return t...
I'm learning Rust now and created a program to solve the task General Fizzbuzz on Rosetta Code.
For example, given:
20
3 Fizz
5 Buzz
7 Baxx
where the first line indicates the upper bound and every line after that indicates the divisor and the corresponding word, the program should return:
1
...
As a variant on the fizzbuzz concept, and as an exercise for learning JavaScript, HTML5, and CSS (I know none of them very well).
The regular fizzbuzz is somewhat tired, but having a web-based, visualizable output seems to be useful, and being able to adjust the inputs at will, allows you to see...
In keeping with using FizzBuzz as an introduction to a language, I present FizzBuzz with a Fortran95 twist:
For multiples of 3, print Fort, and for 5's multiples print Ran. For multiples of both, print FortRan.
Looking especially for style and common practice criticisms. A hint on how to left-j...
you might remember PyDOS from my other post. I have now updated it and its better than ever! Post any ideas below that could make it better.
Source Code:
import time
import os
import sys
import random
def splash():
print ()
print ("PyDOS")
print ()
print ("Version 1.9.8")
print ...
First thing to comment on after copying and pasting into my IDE, the following line gives a warning:
int size = vec_input.size();
Implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'int'
Apparently, the size() method of Vector returns an unsigned long, and w...
you might remember PyDOS from my other post. I have now updated it and its better than ever! Post any ideas below that could make it better.
Source Code:
import time
import os
import sys
import random
def splash():
print ()
print ("PyDOS")
print ()
print ("Version 1.9.8")
print ...
This is a follow up question to PyDOS shell simulaton
you might remember PyDOS from my other post. I have now updated it and its better than ever! Post any ideas below that could make it better.
Source Code:
import time
import os
import sys
import random
def splash():
print ()
print ("P...
@JS1 I am working on it. Here we have 3 nested loops. If I implement multiple 2 nested loops its Big O notation will change. I am not sure will it be effective in performance !!!
I wrote a small script to get the probability of a given text to be spam. I downloaded some ham (good content) and spam (bad content) text from the internet. The spam corpus is a 1.8 MB txt file, the ham corpus a 3.6 MB txt file.
My method is pretty naive: I count how many times each word appear...
The short answer is yes. But assuming this code works correctly, it's kind of off-topic here. I believe that codereview.stackexchange.com would be more suitable. — David Wallace1 min ago
Ok guys, some things have been updated and fixed, almost all sleeps have been removed and some ideas have been implemented. Overall, the code should look better and ideas are still accepted.
(Updated) Source code:
import time
import os
import sys
import random
def splash():
print ()
p...
Hi I have created a school management system but unable to run it as I get the following errors:
8 duplicate symbols for architecture x86_64
Error 127 occurred while running autoreconf
make: ***[libproject2] Error1
make: *** No rule to make target 'all'.
The following is my code:
main.cpp:
#i...
@royvano If that's what you call correctly formatted, then I recommend you start putting some working code examples (not this one... this one doesn't work as intended) to Code Review... because that was far from well formatted... — nhgrif1 min ago
I'm writing an animal shelter program, which keeps a database of different classes of animals (dog, cat, monkey). Functions that create the form and add the animals are very similar (difference is two questions and the rest is the same). Is it possible to divide this functions into parts so that ...
I wrote a script with utilities for calculating the entropy of iterables and included a Tk GUI that shows a quick overview over a text's properties in real-time. (on GitHub)
I tried to follow PEP 8 as good as possible, but I'm not sure about other things, specificially:
I think my docstrings a...