Well, I thought it would be different since you go through each element of the collection twice. But I must admit, even though I now understand that the complexity stays O(n) even if you loop multiple times, I have a hard time understanding why
@TopinFrassi The same amount of computer power is needed if you loop once but do two things in the loop, or if you loop twice and do one thing in each loop. You're still doing the same amount of things
Thanks! So, when we talk about O(n^2), I thought it meant "Each time you go through an element of the collection, you go through all the collection again" or something like that, which seems to make sense. I fail to understand how is this different from going through the list twice or something like that. Why does O(n^2) affect scaling and not O(2n) (which is invalid, from what I now understand)
Well you can also answer whenever you have time, I don't have a gun against my head asking me to explain Big-O notation :P
This is my second Custom Control I have made, a dice. The code below has worked 100% in all my tests, program contains 1 dice control and seven buttons, 6 for setting a number directly, and one for randomizing it. Feedback and improvement suggestions are greatly appreciated.
using System;
using ...
@TopinFrassi Let's say that you have a nested for loop. A for-loop inside a for-loop. And you're looping through the same list in both loops. Let's say that the list is 10 items, how is performance affected if you make the items to 20 instead?
@TopinFrassi Hint: Let's say that inside the inner for-loop you're printing "Hello World" to System.out, how many times will it be printed if the list is 10 items, and how many times will it print if the list is 20 items?
If the item has 10 elements it'll be printed 100 times, and 20 : 400. But what I don't understand is, if I have two loops that aren't nested, I would print Hello World 20 times with 10 elements, not 10..
So, "O(2n)". (I'm not trying to prove a point or anything, just trying to understand!)
@TopinFrassi Exactly. Now imagine if it would take one second to print something to System.out. If you have O(n^2) complexity, it would take 400 seconds instead of 100 seconds. If you have what we can call O(2n) complexity, it would take 40 seconds instead of 20 seconds.
So you see, if you increase the size of the list for O(n^2), the performance is affected much more than if you have O(2n)
@TopinFrassi O(n) would be 20 seconds instead of 10 seconds. Which indicates a doubling. O(2n) is 40 seconds instead of 20 seconds, which is also a doubling. So technically, they have the same scaling.
Double the size, double the time required.
vs. O(n^2), where you double the size and get a quadratic increase in time required
Saying that going through the array twice (O(2n)) is exactly the same as saying "If I go through the array one, the complexity is O(n) since they scale at the same rythm. O(n^2) is important because the time required is exponential comparing to the number of elements
Oops I realise I'm not clear. I mean, if I go through the array twice the performance will double, so the scaling of the algorithm stays O(n) since the performance scales the same way the data does. Where as O(n^2), the performance doesn't scale with the data, which is why it is specified O(n^2). Did I understand?
A logarithmic scale is a nonlinear scale used when there is a large range of quantities. Common uses include the richter scale for earthquakes, acoustics, optics and chemistry.
It is based on orders of magnitude, rather than a standard linear scale.
== Common usages ==
The following are examples of commonly used logarithmic scales, where a larger quantity results in a higher value:
Richter magnitude scale and moment magnitude scale (MMS) for strength of earthquakes and movement in the earth.
ban and deciban, for information or weight of evidence;
bel and decibel and neper for acoustic pow...
whic inclues this graph:
In the top left graph, the blue line.
that's the log scale.
the blue line becomes flatter, and flatter, and flatter.
as you go beyond the right margin, you find the log scale is, for practical computational purposes, flat
Isn't there some... "perfect" implementation examples. I mean, the binary search algorithm is quite clear in how it works, why is there multiple implementations of it?
"The version of binary search that I wrote for the JDK contained the same bug. It was reported to Sun recently when it broke someone's program, after lying in wait for nine years or so."
I believe it wouldn't be much faster? But I understand the point. And @mjolka, I understand that the algorithms are theoricaly awesome, but the implementations are yet to be better (I'd need to get on English SE to see if that is a correct sentence..)
It is a heavy investment in infrastructure, but, now, to add another million subscribers, all they need to do is add a server rack here or there, and not even worry about their central bandwidth.
Lack of voting has already been identified as an issue that prevents the site from graduating. I'm shamelessly stealing this post from Meta Biblical Hermeneutics, hoping it will inspire all of us to be a bit more active with our votes. Enjoy! And vote!
I cannot state this strongly enough. Voti...
@Mat'sMug I think that's where you're thinking is getting twisted. DetailsPresenter shouldn't be an IPresenter, it should be a PresenterBase, which has an implemented Dispose method. All of Presenter's properties would be little more than wrappers around 'BasePresenter' with their additional logic.
And specifically, user cimmanon posted the following suggestion:
CREATE TABLE PersonRole(
-- look, no serial
PersonRoleName TEXT PRIMARY KEY
);
INSERT INTO PersonRole
(PersonRoleName)
VALUES
('Staff'),
('Partner'),
('Customer'),
('Vendor'),
('Session musician')
;
And I'm basically perplexed as to whether an int PK (as in my original version) is indeed a bad idea, for such a small table
On the upside, this would make it where fewer joins would be needed for the data to make sense, which I feel is good. On the downside, each of those words stored being larger in size due to being text/varchar would make each record bigger
I know you're not asking me @Phrancis, but I feel like it's a judgement call. On such a small table, performance and storage size won't be an issue, so the artificial key might be overkill.
So, if you have 1,000,000 people and 3 roles, then go for the int key. 4 bytes will win out.
@nhgrif's logic follows mine.
There are some caveats now though.
For example, I know with IBM's new DB2 BLU column store technology, I would recommend the alternate system, and have a text-based role
The column store uses an encoding scheme that would essentially store the data in almost no space.... like, often just a few bytes for a few hundred values.
But, by default, and to avoid user surprise, I would suggest an int-based primary key, and suffer the addtional lookup.
In almost all applications I have seen the join to the lookup is fast, or non-existent (because the lookups are resolved in the client-side of the query).
Is storing array values inside of a closure considered bad practice. I having been trying to decide if i should just use standard object with key value pair. This is NOT the method I am using to populate arrays, but this does show how i create function to store values.
also...is this technical...
I'm currently writing a scraper to extract recipes from Wikipedia. I've come to the point where I've realized that I'm going to need a complex regular expression to remove all of the unwanted text and I personally think that's going to be expensive in the long run. Below in the code section, I've...
@rolfl There is also smallint which stores 65k values in 2 bytes, and tinyint which stores 256 values in 1 byte, of course depending on your actual DB.
Store anything as a partial byte won't speed up comparison, but could save on size (but probably not a useful optimization). Processors compare bytes at a time--not individual bits.
It's not even that comparing strings is slower than comparing ints--it's the fact that strings require more bytes to represent for each character that you add. If you only count the set of upper and lower case letters, that accounts for just 52 possible values--yet each character is going to take at least a byte. And a byte can hold 256 possible values.
So unless you're going to use punctuation, numbers, symbols, and whitespace characters, you will definitely be wasting bytes when using strings.
I'm guessing converting a column to a bigger int as needed is a pretty trivial thing as well right? (wouldn't be surprised if it did automagically say when you insert value # 257 into a tinyint)
I'm writing a hook for cordova that prints out the projects name in the console. Nothing special, but it's a part of a bigger project. Currently I have this
#!/usr/bin/env node
var _NMR = '../../node_modules/'; // update this to your node_modules/ where cordova locates
var cordova_util = requi...
Nitpicking
Aliases/notation
Single-letter alias names are not very helpful. Aliases should at least give Mr. Maintainer a clue what it stands for. What if you had a table called family along with friends... would you call it F2?
FROM friends F
LEFT JOIN message_share S ON S.ouid_fk <> F.friend...
This is not the most important aspect of your script, but I wanted to answer about...
SQL formatting
I recommend using line breaks and indentation to make your query easier to read, as inline SQL can be difficult to read, doubly so when using column aliases. Also, optionally, meaningful table a...
My goal was to create a tiny DOM builder library that made creating element trees less gross.
This is the syntax I decided on:
var foo = Builder.create('div', function(){
//set attributes
this.id = "foo-div";
this.title = "Foo Div";
//append a child node
this.create('button...
Use a CTE to keep it simple:
-- 1. Artical(ID,Description,PubDate)
-- 2. ArticalMedia(ID,ArticalID,MediaURL)
with Top5Artical as (
select top (5) Artical.ID as ArticleID
from Artical
order by Artical.PubDate desc
),
select Top5.ArticalID,
Art.Description,
Art.PubDate
ArtMedia.ID,
...
The Wolfram Language is what we all know as Mathematica, but rebranded to help wider adoption to people, particularly for people who don't self-identify as "math" people. As a Mathematica programmer, emphasis on the "programmer", I see this as a good thing.
If both tags exist, then they should be synonyms. Which one should be the master, I'm not sure.
If you disagree, please post your rebuttal as an answer on the cited question. =)
I need a class to read and store directory structure. This is my first step in Objective C so I ask to you to say what you think.
Header file:
#import <Foundation/Foundation.h>
@interface FileStructureRepresentation : NSObject
- (id)initWithPath:(NSString *)path;
-(NSMutableDictionary*) parse...
Good point, and yes. It's a case of the OP looks like had a crappy question, commented on all the answers saying that's not what they needed, then went and edited their question with the solution... wtf.
Hi I bumped into http://coolcarousels.frebsite.nl/c/2/, the full width carousel with half visible side slides.
I used that on the project that I am currently working on which is
http://1ne-studio.com/test/
id: total
pass: totalc
and carousel is working but when I start resizing my browser,
half...
We seem to be having difficulty understanding what you want. However, SO discourages inclusion of working code in questions. Why not post a complete working version of your procedure on Code Review instead? Then your intentions would be unambiguous. Also include any relevant background information, ask an open-ended question about your dislike of the temp tables, and maybe even include your application-layer code (C# or whatever). — 200_success55 secs ago
FYI - The last of the swag backlog we've been hammering at goes out today, so if you're owed something, it's out of the warehouse this week. Apologies, technical difficulties and such, I think we've got it back to normal.
I implemented Anisotropic Diffusion for 2d image in C language in order to develop Brain Surface Extractor. My code is having some flaw which I am not able to find.Its taking a pgm image as input and not producing the expected output which is the "Edge highlighted image".
Please help me in this....
@200_success I think the benefit of the tag wolfram-mathematica is that it covers both if someone starts to type "wolfram" and also if they type "mathematica"
override def get(key: String): Option[Any] = {
val timer = couchbaseMetricsTimer.time()
try { // Any way (is it more elegant?) to avoid the try/catch/finally?
Option(couchBaseClient.get(key))
} catch {
case e: Exception => couchbaseFailureMetricCounter.inc(); throw e
...
I am sorry, but what makes your answer any different from the question now?? You're going on a completely unproductive and unhelpful rant here. The point of meta is, that anyone can express their opinions as long as they do it in a serious and constructive manner. Op was seeking input and you are not giving any here. Your own answer suffers of being "slanted towards the [answerers] opionion of". You are not answering the question, but try to attack OP. -1 — Vogel6128 secs ago
Watson gives to Sherlock an array: A1,A2,⋯,AN. He also gives to Sherlock two other arrays: B1,B2,⋯,BM and C1,C2,⋯,CM. Then Watson asks Sherlock to perform the following program:
for i = 1 to M do
for j = 1 to N do
if j % B[i] == 0 then
A[j] = A[j] * C[i]
endif
end do
end ...
I'm coding a networking software, which has lots of functions (modules) which can be run in parallel. They share some resouces, like libnet_contexts of every type, pcap_handles, device info (may not change). Now the sructure is (pseudocode):
class Tools
{
Libnet link;
Libnet raw4;
Li...
First and foremost, I think the return type really should be an NSDictionary rather than a mutable one... but that aside, there are bigger issues:
-(NSMutableDictionary *) parseDirectory:(NSString *)path {
// stuff
NSError *error = nil;
NSArray *listOfFiles = [fileManager contentsOfD...
I've written a custom PHP session class for handling sessions across the web app. Please review the code and point out mistakes and suggest better handling techniques.
require_once('config.php');
class Sessions {
protected $sessionID;
public function __construct(){
if( !isset($_SESSION) )...
Is this an argument for using var more often or disagreement that this question was asked on meta? I don't understand what you're trying to say. Please clarify. — RubberDuck26 secs ago
I have a method that is getting called when someone zooms camera on map (google map).
I recalculate the positions of markers of map and the code is clunky and not effective. I iterate over arrays three times per method call and that is really slow. When I have 600 markers the performance is reall...
@alan2here I fail to see the point you're trying to make.. If you have critique concerning an answer, you should comment on the answer, and not post an answer about another answer (even though meta is different). Especially "unhelpful, counterproductive assumptions" is not clear enough to me. Care to join me in Code Review Chat so we can sort this one out better? — Vogel6126 secs ago
This is a rather conceptual question but I was hoping I could get some good advice on this. A lot of the programming I do is with (numpy) arrays; I often have to match items in two or more arrays that are of different sizes and the first thing I go to is a for-loop or even worse, a nested for-loo...
Welcome to Code Review! We review code here, and don't provide general advice like this. Your question might be a better fit for Programmers Stack Exchange, but even there I think they would prefer to see an example or two. — Gareth Rees1 min ago
I forgot how many awesome reviewers there are that don't chat here.
This is my way of talking I use these words bro, brother and dude , to be polite when talking. If you don't like such words then I'm sorry. — OMI15 mins ago
a well meant "suggestion": don't use "bro", "brother", "dude" and the like if you intend to be polite. Usually it's fine to just drop the salutations, but if you really want to be polite, then "Sir", "Mr." and the like are the words of choice. Anyways, thanks for clarifying ;) — Vogel61255 secs ago
In some cultures and (religious) communities, “brother” is actually a honorific. However, it's better to assume a more generic western cultural reference frame in the internet. I think it's also weird when someone calls me “Sir” on Stack Exchange, as that tends to imply a hierarchy that doesn't exist in my perception.
Brother is an honorific @amon, but one that is earned. At least in my culture... And yeah, I get weirded out every time the bag boy at the store calls me sir.
_GN_If CheckProjectReadOnlyStatus() = "-1" Then
_PS_ Redraw off
_GN_ ' When a read-only planogram is open along with a read-write planogram, Redraw Off throws an error.
_GN_ ' I have no idea why this code fixes it. It should read "If CheckProjectReadOnlyStatus() = False [0] Then"
_GN_End If