Stuck in deletion node in BST when node has both left and right child - binary-search-tree

I'm trying to understand the concept of deletion node in BST when node has both left and right child, but I'm a bit confused, because different books and other sources like web has different definition of this one.
Well, in my case, the Data are:
150, 100, 200, 80, 120, 110, 130, 170, 220
So, the tree is something like this:
150
/ \
100 200
/ \ / \
80 120 170 220
/ \
110 130
Okay. I'm going to delete node 100. I read somewhere that there are two way to do this. Choose either its in-order successor node or its in-order predecessor node. Well, if I choose in-order predecessor, the tree look like this :
150
/ \
80 200
\ / \
120 170 220
/ \
110 130
In this case the postorder traversal is:
110, 130, 120, 80, 170, 220, 200, 150
And its true.
But the second way that there its where I'm stuck is choosing in-order successor, in this case, we have:
150
/ \
110 200
/ \ / \
80 120 170 220
\
130
In this case the postorder traversal is:
80, 130, 120, 110, 170, 220, 200, 150
And its seems to be true, but in the book wrote that its not true. I've google it too much but everywhere write different approach to do this. Maybe all approaches are one, but i did not get it. Someone can explain it in a nutshell ?
I'm not looking for programing code. I'm just want to know what must do exactly?
Any help is appreciated.

Related

how should I rotate this tree to change it into balanced AVL tree?

How could I change this linear tree to balanced tree in single traversal?
1
\
2
\
3
\
4
\
5
\
6
How many rotations should I do to change this into AVL tree?.
Create a new empty AVL tree and insert each of the elements of your tree into this. Follow the example on wikipedia for more information: https://en.wikipedia.org/wiki/AVL_tree?wprov=sfti1
At least 3 rotations are needed.
Because the root has a bad balance 5, rotate the root 2 times.
Go up to the second floor.
4 has a bad balance 2, so rotate it 1 time.

Scan small areas at maximum resolution (up to 6400dpi)

Problem statement: I want to scan an image at maximum scanner resolution (6400 dpi on a Epson V850). This is partly possible from the Epson scanner "professional mode" in the software, provided that the scan area is limited to 21000 x 30000 pixels.
I'm ok with this limitation, I could simply scan small squares of the full area (at max resolution), then "stitch" them together afterwards.
I want to automate this, so I'm attempting to use pyinsane / SANE.
The issue is: the maximum resolution I can set is 1200, as you can see from the properties reported by pyinsane
dps_optical_xres=6400 ([])
dps_optical_yres=6400 ([])
resolution=300 ([50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 525, 550, 575, 600, 625, 650, 675, 700, 725, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1075, 1100, 1125, 1150, 1175, 1200])
xres=300 ([50, 1200, 1])
yres=300 ([50, 1200, 1])
optical_xres=6400 ([])
optical_yres=6400 ([])
So the question is: how do I override this setting so I am able to scan small areas at 6400dpi?
Again, using the EPSON Scan software I can scan at 6400dpi, provided the scanned area is small.
I know the limit exists for memory reasons, but it doesn't feel right that I can't adjust scan area and resolution, just like the Epson software allows to do.
The problems with using the Epson software is A) I can't automate the process, and B) I can't select an arbitrary scan area in terms of top-left to bottom-right coordinates.
I'm surprised how there is no definite answer on this yet. Let's try to have one once and for all, for posterity!
First of all, beware Pyinsane2 is not maintained anymore. Its replacement is Libinsane. (I'm the author of both).
The maximum of 1200dpi comes of the constraint on xres and yres: xres=300 ([50, 1200, 1]) and yres=300 ([50, 1200, 1]) (resolution is just an alias to those 2 options created by Pyinsane2).
Based on what you say, my guess is that you can get this constraint to go to higher values by setting first the scan area to a smaller one (see tl-x, tl-y, br-x, br-y). However after that, I don't think Pyinsane2 will reload the constraint on resolution correctly and so the max will remain 1200dpi (whereas Libinsane should reload it correctly).
By the way, just to be pedantic, if you have options like dps_optical_xres or optical_xres, you are not using Pyinsane2 on top of Sane (Linux), but Pyinsane2 on top of WIA2 (Windows).
For Linux there is ImageScan v3 with command line option.
I didn't try ImageScan v3 but scanimage (sane) on Ubuntu. 3200 ppi worked without problems.

Is the result of a Global MINLP Solver, a global optimum

I used Pyomo and couenne solver that is a global solver for MINLP. But the result is not global optimum!!
Is it possible that the result of a global solver don't be a global optimum?
What is the problem?
The solver log is:
Solver command line: ['C:\\Users\\~\\couenne.exe', 'C:\\Users\\~\\AppData\\Local\\Temp\\tmpv6y0s3cc.pyomo.nl', '-AMPL']
couenne:
ANALYSIS TEST: Problem size before reformulation: 16 variables (6 integer), 37 constraints.
Problem size after reformulation: 54 variables (6 integer), 37 constraints.
*****************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Common Public License (CPL).
For more information visit http://projects.coin-or.org/Ipopt ******************************************************************************
NOTE: You are using Ipopt by default with the MUMPS linear solver.
Other linear solvers might be more efficient (see Ipopt documentation).
Cbc0031I 8 added rows had average density of 2
Cbc0013I At root node, 8 cuts changed objective from -20.3231 to -20.235 in 10 passes
Cbc0014I Cut generator 0 (Couenne convexifier cuts) - 48 row cuts average 2.0 elements, 2 column cuts (10 active)
Cbc0010I After 0 nodes, 0 on tree, 1e+050 best solution, best possible -20.235 (0.16 seconds)
Cbc0004I Integer solution of -10.0826 found after 831 iterations and 63 nodes (0.81 seconds)
Cbc0010I After 100 nodes, 38 on tree, -10.0826 best solution, best possible -15.9137 (0.89 seconds)
Cbc0004I Integer solution of -10.5219 found after 1264 iterations and 114 nodes (0.91 seconds)
Cbc0010I After 200 nodes, 26 on tree, -10.5219 best solution, best possible -11.899 (1.44 seconds)
Cbc0010I After 300 nodes, 29 on tree, -10.5219 best solution, best possible -10.9884 (1.61 seconds)
Cbc0010I After 400 nodes, 13 on tree, -10.5219 best solution, best possible -10.5235 (1.72 seconds)
Cbc0001I Search completed - best objective -10.52192111756512, took 3256 iterations and 479 nodes (1.80 seconds)
Cbc0035I Maximum depth 36, 0 variables fixed on reduced cost
Couenne convexifier cuts was tried 939 times and created 3190 cuts of which 548 were active after adding rounds of cuts
"Finished"

CSound ignores 0dbfs assignment and terminates immediately

I am working through the CSound FLOSS manual and am perplexed by the results I'm getting with one particular example demonstrating the use of RMS in CSound. The example can be found on page 28 in the pdf version, or on this page under the 'RMS Measurement' heading within the html version.
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
;example by Martin Neukom, adapted by Joachim Heintz
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
giSine ftgen 0, 0, 2^10, 10, 1 ;table with a sine wave
instr 1
a3 init 0
kamp linseg 0, 1.5, 0.2, 1.5, 0 ;envelope for initial input
asnd poscil kamp, 440, giSine ;initial input
if p4 == 1 then ;choose between two sines ...
adel1 poscil 0.0523, 0.023, giSine
adel2 poscil 0.073, 0.023, giSine,.5
else ;or a random movement for the delay lines
adel1 randi 0.05, 0.1, 2
adel2 randi 0.08, 0.2, 2
endif
a0 delayr 1 ;delay line of 1 second
a1 deltapi adel1 + 0.1 ;first reading
a2 deltapi adel2 + 0.1 ;second reading
krms rms a3 ;rms measurement
delayw asnd + exp(-krms) * a3 ;feedback depending on rms
a3 reson -(a1+a2), 3000, 7000, 2 ;calculate a3
aout linen a1/3, 1, p3, 1 ;apply fade in and fade out
outs aout, aout
endin
</CsInstruments>
<CsScore>
i 1 0 60 1 ;two sine movements of delay with feedback
i 1 61 . 2 ;two random movements of delay with feedback
</CsScore>
</CsoundSynthesizer>
When I run csound with the file as input using csound ex5.csd the following output follows.
0dBFS level = 32768.0
--Csound version 6.10 (double samples) 2018-01-27
[commit: none]
libsndfile-1.0.28
UnifiedCSD: ex5cp.csd
STARTING FILE
Creating options
Creating orchestra
closing tag
Creating score
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
csound command: Segmentation fault
end of score. overall amps: 0.0
overall samples out of range: 0
0 errors in performance
This all happens immediately, with no sound output to be heard. I am guessing this isn't the intention of the example, and that the 0dBFS level = 32768.0 log message has something to do with the problem. I am asking here because I get the same result even when I copy paste the program from the book, so I am sort of stumped.
Any insight into what's going on here?
Thanks
i don't think it has anything to do with the 0dbfs assignment. you can compare with any other .csd which works for you: you will find it always first in the output console.
i checked the example, and it works for me as expected (csound 6.14 develop).
as you use csound 6.10, my first recommendation is to update your csound. the problem ist that you get a segmentation fault, so no way to know more about the issue without special tools.
by the way, there is a new version of the csound floss manual at https://flossmanual.csound.com/
the examples can now be played directly from the browser (for now, chrome/chromium works best).
hope this helps -
joachim

How does Chi-Square based SPAM detection works in SpamAssassin

I'm trying to understand about Bayes based spam detection, and have difficulty understanding how to code it.
To understand it, I'm reading code of SpamAssassin like below.
http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes/CombineChi.pm?view=markup
But, I could not understand how the chi2q function.
# Chi-squared function (API changed; see comment above)
107 sub chi2q {
108 my ($x2, $halfv) = #_;
109
110 my $m = $x2 / 2.0;
111 my ($sum, $term);
112 $sum = $term = exp(0 - $m);
113
114 # replace 'for my $i (1 .. (($v/2)-1))' idiom, which creates a temp
115 # array, with a plain C-style for loop
116 my $i;
117 for ($i = 1; $i < $halfv; $i++) {
118 $term *= $m / $i;
119 $sum += $term;
120 }
121 return $sum < 1.0 ? $sum : 1.0;
122 }
I tried to google or read book, but cannot find full explanation including from theory to code.
Can you explain why it works?
The Chi Squared test can tell if two sets of numbers are "similar"
The best explaination I could find with googling quickly was here http://formulas.tutorvista.com/math/chi-square-formula.html
This involves finding the difference between an observed value and the expected value. Or the value in a different condition. Then the difference is squared. Squaring it has two effects, the squared numbers become positive and any differences are accentuated.
Then all the numbers found with this difference and squaring operation are added up and this makes a number. The number, together with the "degrees of freedom" in the observations is compared on a table to find the "p value" or probability of the result occurring by chance
It allows a match of similarity on two sets of values, without them being exactly the same
I'm sure you can imagine how useful this sort of comparison can be for detecting spam
Your code sample does not seem to do this, so I can only guess that there are other calculations happening in the rest of the spamassassin code base