I have two versions of find function, both of which search an integer value in an array and return its position if exists. Function find1() will search up to N elements in worst case on the other hand find2() function will search up to N/2 elements in worst case. Does it mean find2() functions complexity is reduced into O(N/2)?  I assume the array arr contains non-duplicating values.  Function: find1()  int find1(int value){     for (int i = 0; i &lt; N; i++){         if (arr[i] == value){             return i;         }     }     return -1; }   Function: find2()  int find2(int value){     for (int i = 0, j = N - 1; i &lt;= j; i++, j--){         if (arr[i] == value){             return i;         }         if (arr[j] == value){             return j;         }     }     return -1; }
Most people with a degree in CS will certainly know what . It helps us to measure how well an algorithm scales.   But I'm curious, how do you calculate or approximate the complexity of your algorithms?
Setting knots in natural cubic splines in R I have data with many correlated features, and I want to start by reducing the features with a smooth basis function, before running an LDA. I'm trying to use natural cubic splines in the splines package with the ns function.  How do I go about assigning the knots?  Here's the basic R code:  library(splines) lda.pred &lt;- lda(y ~ ns(x, knots=5))   But I have no idea about how to chose the knots in ns. Pass php variables to js without drupal behaviour I stand on the following tricky situation:  I have a node with geofield coordinates attached. I am constructing an array of points. Something like:  Array ( [86] =&gt; Array     (         [0] =&gt; Array             (                 [lat] =&gt; 39.1641410477                 [lon] =&gt; -2.633972168             )          [1] =&gt; Array             (                 [lat] =&gt; 41.0420738489                 [lon] =&gt; -2.633972168             )          [2] =&gt; Array             (                 [lat] =&gt; 41.0420738489                 [lon] =&gt; 1.2524414063             )          [3] =&gt; Array             (                 [lat] =&gt; 39.1641410477                 [lon] =&gt; 1.2524414063             )         [4] =&gt; Array             (                 [lat] =&gt; 39.1641410477                 [lon] =&gt; -2.633972168             )     )  [85] =&gt; Array     (         [0] =&gt; Array             (                 [lat] =&gt; 39.1641410477                 [lon] =&gt; -2.633972168             )          [1] =&gt; Array             (                 [lat] =&gt; 41.0420738489                 [lon] =&gt; -2.633972168             )          [2] =&gt; Array             (                 [lat] =&gt; 41.0420738489                 [lon] =&gt; 1.2524414063             )          [3] =&gt; Array             (                 [lat] =&gt; 39.1641410477                 [lon] =&gt; 1.2524414063             )         [4] =&gt; Array             (                 [lat] =&gt; 39.1641410477                 [lon] =&gt; -2.633972168             )     ) )   I want to pass this to my-googlemaps.js in order to be used by google's init map Google map is defined as:  my-map:   header: true js:   js/my-googlemaps.js: { }   https://maps.googleapis.com/maps/api/js?key=my_key&amp;callback=initMap: {type: external, attributes: {defer: true,async: true}} dependencies:   - core/drupal   - core/drupalSettings  my-googlemaps.js:   console.log(Drupal.settings);   function initMap() {}   This way I get Drupal.settings undefined, which makes sense I guess. On the other hanve if I place initMap into a behavior It can not be seen as a callback as defined in googleapis.com before.  Has anyone stumbled with this before? Any idea how to attack the problem? "I cannot seem to find it" Why don't they use the transporter in the final fight in Star Trek Into Darkness? When Spock was chasing, and beating, Khan over a transport in San Francisco, Uhura orders them beamed both back  to the Enterprise, while Chekov says something like:     Its impossible, they are moving!                                   But in the first movie, it was Chekov that transported back to Kirk and Sulu, avoiding hitting the Vulcan planet when trying to disable the Romulan drilling platform. How can I share a directory with an another user? Gauss's law in a uniform charge distribution extending infinitely in all directions Let us assume the universe filled with positive charge. About a particular point, all the positive charged particles will be symmetrical. Now consider a sphere of radius $r &lt; \infty$ and apply Gauss law. According to Gauss law the electric flux through the sphere will be some finite value as it contains some positive charge. But by symmetry the electric field through the sphere and hence electric flux will be zero. This is a contradiction. Maximum length of a USB Cable? Precedence of user and group owner in file permissions I just ran into something unexpected (for me) regarding file permissions on Linux (Arch Linux). Basically I have:   userX in groupX fileX userX:groupX ---rwx----   What puzzles me: I cannot perform any action (rwx) on fileX. Is this right? Can someone please confirm this is indeed the expected behaviour?  The only actions I can perform are mv and rm because I have write permissions on the parent directory.  The thing is, I always thought these permissions collapse on each other, starting with the most general one (other -> group -> user). In other words, if o=rwx who cares what the persmissions for group and user are? Apparently this is not the case but it doesn't make much sense to me; it seems counterintuitive. The only thing this approach seems to be useful at, is to easily exclude a very specific person / group, which doesn't seem like a smart way to go at it (imho). Besides, the owner (and group?) should be able to chmod anyway right? Any thoughts on this matter? Fantasy series with Celtic overtones, intermittent stone magic, and ongoing slow magic I checked this series out of the library during college, maybe 15 years ago now.    It was based around 'stone magic' – magical stones that granted their bearers enormous power.  Unfortunately, the power of these stones is intermittent, they'll fade out for a long time then fade back in.  The main characters dealt with a 'master' stone of some sort, the first to restore, last to die.  It's also the key to granting other people access to their own powers – I think seals had magic fish they swallowed, which keyed off the master stone, and in the last book I think the character created magic staves for another race. It also had 'slow magic' – longer to set up, less apparently potent than stone magic, but the slow magic, given time to work it, could still be powerful and dramatic.  It just took time and preparation instead of brute force. In one book, the main character faces off against the source (or something like that) of magic, and is about to win when it's discovered she's pregnant.  The source – a dragon? – isn't allowed to harm anyone who doesn't come to it freely, so the main character is forbidden to finish the trial.  In the sequel, her daughter repeats the trial, and becomes immensely powerful by winning, but there was a cost of some sort, something that transformed her A lot of the naming made me think it had a Celtic root. How to clone ArrayList and also clone its contents? How can I clone an ArrayList and also clone its items in Java?  For example I have:  ArrayList&lt;Dog&gt; dogs = getDogs(); ArrayList&lt;Dog&gt; clonedList = ....something to do with dogs....   And I would expect that objects in clonedList are not the same as in dogs list. Add warning when changing display name The policy on changing one's display name :  only one display name change is allowed every 30 days  However, there is no warning whatsoever when actually changing one's display name.  Thus, it came as quite a bit of a shock to me when I found out today that I might be stuck as &quot;Unicorns are Yummy&quot; on Stack Overflow for the next freakin' month. I would like to recommend that a warning be added to the &quot;Edit Profile&quot; page to warn people. Or, at least make the policy concerning display name changes more obvious. Workaround I was able to change my display name back (phew!) by copying my profile from Meta Stack Overflow. I still think a warning should be implemented, though. Script for modifying file content in specified files I tried searching previous questions but none worked, or I couldn't adapt them to my needs.  I want to write a script that asks for:   folder criteria old string new string   And replace every file in the specified folder and subfolders (and force user to type one) with specific criteria (for example, it must be a ".cue" file), and:   If the file is read-only, disable it. Search for specified old string in the file content and replace it with new string , and save changes in same file. If the file was read-only, enable it again.   I have this code so far, but I don't know what to do in the do part:  @echo off   setLocal enableDELAYedexpansion  :START set "var2=" set /P var2="type folder "  if "%var2%"=="" goto ERROR  set /p old="old string ? " set /p new="new string ? " set /p files="what criteria ? " echo modifying files...  for /r "%var2%" %%v in (%%files) do (  ???  ) pause  goto START  :ERROR echo type something!! goto START As teenager Tom Riddle is speaking to Harry Potter in the Chamber of Secrets, both he and Harry are refering to the real Voldemort in the third person. If Tom Riddle had succeeded in sucking all the life energy out of Ginny and had come back alive, wouldn't that have meant there were two Voldemorts in the world? The wraith one which had lived in Quirrell, and the newly constituted one?  This Tom Riddle clearly doesn't have the memories of the wraith version.   As a bonus: If they both existed, would they have competed against each other? Why do I get TypeError: can't multiply sequence by non-int of type 'float'? I am typing to get a sale amount (by input) to be multiplied by a defined sales tax (0.08) and then have it print the total amount (sales tax times sale amount).  I run into this error. Anyone know what could be wrong or have any suggestions?   salesAmount = raw_input (["Insert sale amount here \n"]) ['Insert sale amount here \n']20.99 &gt;&gt;&gt; salesTax = 0.08 &gt;&gt;&gt; totalAmount = salesAmount * salesTax  Traceback (most recent call last):   File "&lt;pyshell#57&gt;", line 1, in &lt;module&gt;     totalAmount = salesAmount * salesTax TypeError: can't multiply sequence by non-int of type 'float' What packages do people load by default in LaTeX? If $$\tan(\frac{\pi}{4}+\frac{\theta}{2})=\tan^3(\frac{\pi}{4}+\frac{\alpha}{2})$$, then prove that $$\sin \theta=\frac{3 \sin \alpha+\sin^3 \alpha}{1+3\sin^2 \alpha}$$  I tried using the fact that  $\frac{\cos A}{1-\sin A}=\tan(\frac{\pi}{4}+\frac{A}{2})$ but now not able to eliminate $\cos \alpha$ and $\cos \theta$. How should I proceed? Set myself as owner of /etc with chown command now getting all kinds of errors Android design convention for saying a user needs to complete an action first? I've read the Android design conventions, but can't see a good solution.  I have a 3 tab mobile application. Tabs 2 and 3 need a selection made on screen 1 before they will work. The user enters at Screen 1, and the tab options are along the top. If they attempt to open screen 2 or 3, I would like to advise them to make a selection first. 'notifications' are the closest answer I can see from the Android design guidelines. Anybody have any other solutions?  Thanks  Andy Multiplication operator has no no eigenvalues Statement: Let $M_x$ denote the multiplicative operator acting on $L^2([0,1], \, dx)$ by $M_x(f) = xf$. Show that $M_x$ has no eigenvalues  Attempt: Let $M_x(f) = xf$ then we should have $M_x(f) = \lambda f$  then we get $M_x(f) = \lambda f \Rightarrow xf = \lambda f \Rightarrow xf-\lambda f \Rightarrow (x-\lambda)f = 0$  Now $f \neq 0$ so that implies that $(x-\lambda) = 0$ but this is achieved when $x = \lambda$, so I don't see how it doesn't have eigenvalue, when we achieve the desired result. How to monitor disk activity? How do I view my Disk Activity on Ubuntu? For example, How can I monitor what is being written and read from disk as well as the percentage of disk usage?  I am looking for an application similar to the Resource Monitor in Windows.