Is it possible to keep weights of left and right subtree at each node of BST that has duplicate values?


Is it possible to keep weights of left and right subtree at each node of BST that has duplicate values?

I must be able to delete a node completely(irrespective of how many times it is present)

Currently, in my code, I am keeping count variable in each node that records the number of times it is present in tree.

During insertion, I can increase the size of left and right subtree weight at each node according to if my value is less or more. but how do I adjust the weights when I delete a node(because I may delete a node with count >1)

Values of k that make this true, $\log^k n \in \Omega(\sqrt n)$

I have seen some algorithms with complexities like $ \log^3 n$ and $ \sqrt n$ . In view of getting a better idea on how to compare these I wanted to know for which values of $ k$ does $ \log^k n \in \Omega(\sqrt n)$ hold true?

I suspect $ k$ would need to be a function of $ n$ . Because if it were a constant $ C_1$ , we could always find a larger constant $ C_2$ that makes the previous statement false.

This is what I have tried.

$ \log^k n \in \Omega(\sqrt n)$

$ \log^{2k} n \in \Omega(n)$

$ \log(\log^{2k}n) \in \Omega(\log n)$

$ 2k \log\log n \in \Omega(\log n)$

From here, I can see that if $ k$ is $ \log n$ , then $ 2\log n \log\log n \in \Omega(\log n)$ is true.

However, I doubt this is a tight bound.

MATLAB: Write a function A = mymatrix(X, m, n) which creates an m-by-n matrix A, for arbitrary values of m and n and any length of vector X [closed]

X is a vector i already have… its recommended to use length, mod, reshape, repmat this is what ive got but cant come up with anything further:

function A = myMatrix(myvec, m n)

if length(myvec)< m*n

A=reshape([length(myvec)~mod(m*n)  

i know what im trying to do in the last line but not sure how to type it

thanks

Assigning Monk Attribute Values

If the way we roll characters means that we can roll the six numbers and assign them to whatever attribute we want then there is usually a preferred attribute for the highest value:

  • a Magic User would usually put the highest value in Intelligence
  • a Cleric would usually put the highest value in Wisdom
  • A Fighter would put usually the highest value in Strength

But what about the monk?

A monk needs 15 is each of Strength, Dexterity and Wisdom. There is no AC bonus for dexterity and no to-hit/damage bonus for strength. It reads as if you do still get the reaction bonus for dexterity and the saving throw bonus for wisdom and the weight bonus for strength so there is some value in having a value higher than 15 in those attributes but it isn’t clear to me if there would be a clearly superior order for assigning the three highest values rolled.

Is there a clearly superior order for assigning those highest three values when playing a monk?

Algorithm to delete BST nodes with duplicated values

For BSTs we have:

  1. Greater values go to the right
  2. Smaller or EQUAL values go to the left

All the algorithms I found to delete a node say to find the smallest node in the right subtree of the node we want to delete, successor, (or the greatest node in the left subtree, predecessor), and replace the deleted node for the successor.

But what happens when we have BST nodes with the same value?

     4    /   \   2     5 <-- Delete 5  / \   / \ 1  3  5   7          / \        [7]  9 <-- 7 will take 5's place 

Now we end up with:

     4    /   \   2     7   / \   / \ 1  3  5  [7]  <-- This 7 should be in the left subtree            \             9 

The BST will still work (or not?), but the definition of BST won’t fit this resultant tree anymore.

Is there another algorithm that takes this into account or is this result expected and generally accepted?

Arrays sums for 3 distinct values

My problem is that we have an array of N integers (N <=5000) on the interval [-10^6,10^6]. We also have Q queries (Q <= 10^5) giving us some range in the array.

For each query, we want to find the number of triplets of indices in the range such that the sum of those array values equal to zero. More formally we want to find the number of ways we can choose unordered distinct triples i j and k(within the given query range) such that a[i]+a[j]+a[k] = 0.

I’m thinking of doing an N^2 precomputation + logN time for each query but I am unable to come up with a concrete working idea. Any help would be appreciated.

Edit: queries can be processed offline, as the array does not need to be updated.

Why HOG angular bins have values between 0 and 180 degrees?

I have learned that HOG angular bins have values from 0 to 180 since the algorithm uses unsigned gradients. I am failing to understand why.

As far as I know gradient orientation is calculated as

angle = atan(S_y / S_x) 

where S_x and S_y are image gradients in x and y directions respectively.

Provided that S_y and S_x are non-negative, the ratio will also never be negative. Hence, the angle should be in range from 0 to 90 degrees (see atan graph below). What am I missing?

enter image description here

How can I change field values of posts before displaying

I have wordpress project with woocommerce. What I’m trying to achieve is to change values before displaying them on the view page.

For example depending on session/cookie I want to change the language of post title and content

Using the hooks the_title, the_content I was able to achieve it. The problem is when I try to do the same for the_excerpt hook, it’s just never called.

Relevant code from functions.php :

add_filter('the_title', 'custom_lang_title');  function custom_lang_title($  title){     if($  otherlang){         return get_field('lang_title');     }else{         return $  title;     } }  add_filter('the_content', 'custom_lang_desc');  function custom_lang_desc($  content){     if($  otherlang){         return get_field('lang_content');     }else{         return $  content;     } }   //The code below does not work  add_filter('the_excerpt', 'custom_lang_excerpt');  function custom_lang_excerpt($  desc){     if($  otherlang){         return get_field('lang_excerpt');     }else{         return $  desc;     } } 

I’m completely new to wordpress, so if don’t really know what other info can be helpful. I can provide more info on request.