algorithms – Dynamic Predecessor Search

We have a universe $U = {0,1, …,u-1}$ and a set $S subseteq U$ of size
$n$. We will create a hash table containing all the elements of $S .$ Additionally, the hash table will contain every $prefix$ of the binary representation of every element in the set. We will create a doubly linked list of all the elements of S which are arranged in increased order of their values. Finally, with each $prefix$ $p$ in the hash table, store a minimum and a maximum: Among all the elements of $S$ which have $p$ as a $prefix$, minimum (resp., maximum) of $p$ will be the element with the minimum (resp., maximum) value.

  1. What is the space occupied by this data structure?
  2. How to perform insertion of a new element in $O(log u)$ time?
  3. Given a query $x in U$, the longest common prefix (lcp) operation will report that prefix in the
    hash table which has the longest common prefix with $x$. How do you perform this operation by querying the hash table only $O(log log u)$ times?
  4. Assume that the lcp operation can be performed in $O(log log u)$ time. Using the lcp operation,
    how to perform predecessor search operation in $O(log log u)$ time?

My Take on the Problem:

For example, consider $u = 16.$ Then representing each integer in the universe will require four bits. If, say, $14$ is in $S$, then its binary representation is $1110$, and hence, all its prefixes $1, 11, 111, 1110$ will be stored in the hash table.

For the number $3$, an example, if $x = 110111$, and
hash table has two strings $y = 110100$ and $z = 111100$, then $y$ has a common prefix of length
four with $x$, while $z$ has a common prefix of length only two with $x$. Every element in
$U$ in binary representation requires $O(log u)$ bits. I have come up to this point.

Please provide a short description or pseudo code for number $2$ and $3$ and a solution for $4$ .

Thanks in advance!

How to search for a specific link in SharePoint Online

I’m trying to find out what would be the easiest way to search for a specific link in a site collection. It isn’t a SharePoint link but a link to an external site. I tried to configure a custom search page but it doesn’t seem to pick up navigation links.

I want to be able to find everything that contains that URL – whether it’s a document, a navigation link, a link s list or a link existing as a text on a page or in a content editor. Is this possible out of the box?

Any help would be appreciated.

facebook – How to automatically search my entire site for any content embedded using oEmbed?

How can I carry out an automatic search of all pages/posts on my site for any content embedded using oEmbed (preferably Facebook/Instagram content)?

The reason I ask is because this WPBeginner post says that on October 24th, all Facebook or Instagram content embedded on a site using oEmbed will be deprecated, and such content will be (slightly) broken. I’d like to first determine how much oEmbed content I have on my site. My site is has a relatively large amount of pages/posts (content added by others), so manually searching each will be a bit tedious.

Would I perhaps need to carry out a database search? Or a text search through all the files?

FYI my site uses Classic Editor throughought–not Gutenberg.

Thanks.

8 – Search API XSS issue

Using the search API documentation, built a form in the header that passes the search text to the search page.

https://www.drupal.org/docs/8/modules/search-api/getting-started/common-pitfalls

When doing a simple search with this text

<script>alert('Test');</script>

shows a popup test on the page. Any suggestions on how to fix it?

python – Approximation search implementation

I’ve ported a C++ approximation search algorithm to Python. Unfortunately, my Python is a bit rusty, so this could probably use some (read: a lot) of cleaning up. Additionally, I remember a better way of working with instance variables than using self repeatedly, which I find a bit cumbersome. I can’t quite recall what, however.

For a far more detailed explanation of approximation search that I could hope to give, please see: https://stackoverflow.com/questions/36163846/how-approximation-search-works/36163847#36163847

Here’s my code:

class Approximate:

    done = False
    stop = False

    def __init__(self, _xi, _xf, _dx, _n):

        self.xi = _xi;      self.xf = _xf;
        self.dx = _dx;      self.n  = _n;

        self.ei = -1.0

        self.x = 0.0

        self.xs = _xi

        self.i = 0

    def step(self):

        if(self.stop):
            self.i += 1

            if(self.i >= self.n):
                self.done = True
                self.x = self.xs
                return

            self.xi = self.xs - self.dx
            self.xf = self.xs + self.dx

            self.x = self.xi
            self.dx *= 0.1

            self.xi += self.dx
            self.xf -= self.dx

            self.stop = False

        else:

            self.x += self.dx

            if(self.x > self.xf):
                self.x = self.xf
                self.stop = True

Tear it apart! I’m aware it’s probably bad. The more criticism the better.

Woocommerce error on admin ajax search product: Unknown column ” in ‘where clause’

When I want to add products to a manual order in Woocommerce, the product search returns “no matches found”. I looked at the logs and I found this error seems to be culprit. I searched the error but every case I found, the unknown column name is defined in the log. Here it’s blank: Unknown column '' How can I investigate what’s causing it? I’m trying with TwentyTwenty and only WC activated…

Full error:
(proxy_fcgi:error) (pid 3178592) (client *:60140) AH01071: Got error 'PHP message: WordPress database error Unknown column '' in 'where clause' for query SELECT DISTINCT posts.ID as product_id, posts.post_parent as parent_id FROM wp_posts postsnttt LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON posts.ID = wc_product_meta_lookup.product_idnttt LEFT JOIN wp_wc_product_meta_lookup parent_wc_product_meta_lookupnttt ON posts.post_type = 'product_variation' AND parent_wc_product_meta_lookup.product_id = posts.post_parent ntttWHERE posts.post_type IN ('product','product_variation')nttt AND ( ( ( posts.post_title LIKE '%chorizo%') OR ( posts.post_excerpt LIKE '%chorizo%') OR ( posts.post_content LIKE '%chorizo%' ) OR ( wc_product_meta_lookup.sku LIKE '%chorizo%' ) OR ( wc_product_meta_lookup.sku = "" AND parent_wc_product_meta_lookup.sku LIKE '%chorizo%' ) )) nttt AND posts.post_status IN ('private','publish') ntttntttORDER BY posts.post_parent ASC, posts.post_title ASCnttt LIMIT 30 nttt made by do_action('wp_ajax_woocommerce_json_search_products_and_varia...',

Search Result displays Item_default as display template for my custom result type

My Search Results displays Item_default as display template for my custom result type . I have my display template major version published and have mapped in Search Result Types. My search result type is also under site collection. In content search web part I have set result type to decide option.

I don’t know where else to look to debug the issue. Any pointers ?

8 – How to display default drupal search block in twig template

In twig_tweak module before version 2 (for Drupal 8) I could place the following code in my page twig template and it would work:

{{ drupal_block('exposedformsearch_contentpage_1') }}

This would display put the default site search box.

After upgrading to version 2, this doesn’t work anymore and see the following message on the page:

This block is broken or missing. You may be missing content or you might need to enable the original module. 

I tried using the command:

{{ drupal_block('search_form_block') }}

That displays the same error message.

Does anyone know what the the correct call is? I can’t seem to find any documentation anywhere as to what the replacement call should be.

Thanks.

SharePoint search API not bringing results from Subsites

I am trying to use Search Api in SharePoint online to search against a RefinableString that is mapped to to a column

https://tenant.sharepoint.com/sites/SiteName/_api/search/query?querytext='RefinableString00:SomeQueryText'&rowlimit=500&selectproperties='Title,RefinableString00'

When I query this, it brings the documents from the root site collection only. When I include the path:"http://pathToSubsite" in querytext, it brings the document from that subsite only. So if want to bring results from all the subsites, do I need to include all of them in the path?

Not sure what I am missing in the query. Also I noticed that it the result is containing only one result even when we have more than 1 matching results in the site.

Complexity in time and memory for graph search algorithm

I am working on an assignment where I have to write an algorithm to detect all vertices that lie in a cycle in a graph and then calculate its complexity. I have come up with an algorithm in pseudocode. My approach is to ‘delete’ all vertices that have only one connecting edge until no vertexes are left that have only one connecting edge. The remaining vertices, if any, are part of a cycle.

The graph is undirected.

/*
// vertices is an array containing every vertex
// e.g. vertices = (0,1,2,3,...)
*/
vertices()

/*
// edges is a two dimensional array defining each edge
// by the two vertices it connects
// e.g. edges = ((0,1),(2,3),(4,1),...)
*/
edges()

verticesInCycle = cycleDetection(vertices, edges, vertices)

verticesNotInCycle = vertices

foreach (verticesInCycle as vertexIC) {
    if (verticesNotInCycle.contains(vertexIC)) {
        verticesNotInCycle.remove(vertexIC);
    }
}


/*
// vertices() = vertices to test
// edges() = edges to test them against
// verticesLeft() = all untested vertices that are left
*/
function cycleDetection(vertices(), edges()), verticesLeft()) {
    recur = false
    nextVertices()

    foreach (vertices as vertex) {
        count = 0
        connectingEdge = null

        foreach (edges as edge) {
            if (vertex == edge(0) || vertex == edge(1)) {
                count++

                if (count > 1) {
                    break
                } else {
                    connectingEdge = edge
                }
            }
        }

        if (count == 1) {
            edges.remove(connectingEdge)
            verticesLeft.remove(vertex)

            if (connectingEdge(0) == vertex) {
                nextVertices.add(connectingEdge(1))
            } else {
                nextVertices.add(connectingEdge(0))
            }

            recur = true
        }
    }

    if (recur) {
        cycleDetection(nextVertices, edges, verticesLeft)
    } else {
        return verticesLeft
    }
}

Example Run

Example graph

10  6
  / 
  1   5
  |   |
  2   4-7
  | /
  8 3
   
    9

Initial call of cycleDetection

x   o
  / 
  o   o
  |   |
  o   o-x
  | /
  o o
   
    x

First recursive call

    o
   / 
  o   o
  |   |
  o   o
  | /
  x o


Second recursive call

    o
   / 
  o   o
  |   |
  o   o
    /
    o


Done!

Now I am calculating the complexity (time and memory)

I calculated that the complexity is approximately O(1.4(V*E)), where N is the number of vertices and E the number of edges.

This is based on the time (or iterations) because the maximum number of iterations (vertices and edges to check) is approximately 1.4(n*e), where n is the number of vertices and e the number of edges.

The worst case, which requires the most iterations, is a line of connected vertices with a cycle at one end.

o
|
| o-o-o-o-o-o-o-o-o-o
|/
o

In this case the complexity is the number of vertices n times the number of edges e multiplied by approximately 1.4. Initially all edges need to be iterated for every vertex but subsequently only the remaining edges need to be iterated for one vertex at a time. In the end about a fourth of n*e needs to be iterated through after the initial iteration of all edges for every vertex.

Memory usage

Memory usage is directly dependant on the amount of recursive calls, with the first call needing the most memory. Every call of cycleDetection uses v + e + vL memory, v + e + vL being the size of the three arrays passed as parameters.

The worst case for memory usage is a line of connected vertices with a cycle at one end (as above). In this case the amount of recursive calls required is v - 2, where v is the number of vertices given that v > 2. So memory complexity is approximately O(3) work memory.

A. I am unsure if my time complexity is formulated right? It doesn’t need to be spot on but I also saw that you can leave out the multiplier and write something like O(VxE**2).

B. I am pretty sure my memory complexity is wrong? I have read this and formulated my complexity accordingly based on the fact that I have three variables that I am passing to my function with every recursive call.