Let $(G,*)$ be a finite semigroup with identity. Prove that $G$ is a group iff $G$ has only one element $a$ such that $a^2=a$.

Let $(G,*)$ be a finite semigroup with identity. Prove that $G$ is a group iff $G$ has only one element $a$ such that $a^2=a$.

For the right direction, since $G$ is a group with identity, then there exists $a=e_G$ i.e. $a^2 = a$. Isn’t it?

For the left direction, what should I do?

java – help me solve it i want to find the occurrence of number in an array and a combination of same element into an arraylist

I am trying to find the combination of same numbers in an array in java e.g i have number in an array e.g numbers{1,2,2,2,1,1,1,2,2,2,1,1,2,2,2,1,1,1,2,2,1} .So i want the program to check all combinations of number that occurred in a sequence of order only like 1, or 2,2,2 or 1,1,1 or 2,2,2 then it will check how many times did 2 or 1 occur so the occurred number will be stored in an arraylist. In that case first 1 occurred 1 time then 2 occured 3 times then 1 occurred 3 times then 2 occurred 3 times and so on it will show how elements are arranged in an array .i have wrote a code but it is not working in java as i want it to

public class Main {

private static ArrayListPlistItem=new ArrayList();

private static ArrayListNlistItem=new ArrayList();

private static ArrayListPwillhappen=new ArrayList();

private static ArrayListNNhappen=new ArrayList();

private static ArrayList LhappenList=new ArrayList();

private static ArrayList NhappenList=new ArrayList();

private static ArrayList LhappenListTotal=new ArrayList();

private static ArrayList NhappenListTotal=new ArrayList();

private static int Lhappen=0;
private static int Lhappen2=0;

private static int Nhappen=0;
private static int Nhappen2=0;
private static int () items ={1,2,2,2,1,1,1,2,2,2,1,1,2,2,2,1,1,1,2,2,1};
private static int () Nhappenitems =new int(1);
private static int () Lhappenitems =new int(1);

public static void main(String ()args){

PlistItem.add(1);
NlistItem.add(2);

//comparing elements from an array which with an arraylist number
for(int y=0; y<items.length; y++){

if(PlistItem.get(0)==items(y)){
//counter to count how many times 1 occurred
Lhappen++;
//counter to count how many times 1 occurred
Lhappen2++;
//adding the counter in arraylist
Pwillhappen.add(0, Lhappen);

//adding the numbers how many times it occured in arraylist
Lhappenitems(0)=Lhappen2;

//adding in total number it occur in an arraylist
LhappenListTotal.add(0,Pwillhappen.get(0));
//setting the counter into 0
Nhappen=0;

}else if(NlistItem.get(0)==items(y)){
//counter to count how many times 2 occurred
Nhappen++;
//counter to count how many times 2 occurred
Nhappen2++;
//adding the counter in arraylist
NNhappen.add(0,Nhappen);
//adding the numbers how it many times it occurred in arraylist
Nhappenitems(0)=Nhappen2;

//adding in total number it occur in an arraylist
NhappenListTotal.add(0, NNhappen.get(0));
//setting the counter into 0
Lhappen=0;

}

}

System.out.println(” RESULTS ” );
System.out.println(“——————————————————————————–“);
System.out.println(“1 occurrence total “+ Nhappenitems(0) +” times”);
System.out.println(“2 occurence total “+ Lhappenitems(0) +” times”);
System.out.println(“——————————————————————————–“);
for(int i=0; i<LhappenListTotal.size(); i++){
System.out.println(” combination of 1’s occurred “+ LhappenListTotal.get(i) +” times”);

}

System.out.println(“——————————————————————————–“);
for(int i=0; i<NhappenListTotal.size(); i++){

System.out.println(“combination of 2’s occurred “+ NhappenListTotal.get(i)+” times”);
}

}
}

RESULTS

1 occurrence total 11 times

2 occurence total 10 times

combination of 1’s occurred 1 times

combination of 1’s occurred 3 times

combination of 1’s occurred 2 times

combination of 1’s occurred 1 times

combination of 1’s occurred 2 times

combination of 1’s occurred 1 times

combination of 1’s occurred 3 times

combination of 1’s occurred 2 times

combination of 1’s occurred 1 times

combination of 1’s occurred 1 times

combination of 2’s occurred 2 times

combination of 2’s occurred 1 times

combination of 2’s occurred 3 times

combination of 2’s occurred 2 times

combination of 2’s occurred 1 times

combination of 2’s occurred 3 times

combination of 2’s occurred 2 times

combination of 2’s occurred 1 times

combination of 2’s occurred 3 times

combination of 2’s occurred 2 times

combination of 2’s occurred 1 times

my code when i run it is showIng as above results instead i want my results to be as below so help me to solve the code to produce the results as below it show produce the result same as the elements how they are arranged in an array.. items ={1,2,2,2,1,1,1,2,2,2,1,1,2,2,2,1,1,1,2,2,1};

RESULT

combination of 1’s occurred 1 times

combination of 1’s occurred 3 times

combination of 1’s occurred 2 times

combination of 1’s occurred 3 times

combination of 1’s occurred 1 times

combination of 2’s occurred 3 times

combination of 2’s occurred 3 times

combination of 2’s occurred 3 times

combination of 2’s occurred 2 times

javascript – Is possible set state from parent and set state from children at same element?

I have a component and I need to update the value from parent (ok), but if the user change the value of the input (children / functional component), I need set this value without pass to parent to re-render children.

See this example:
https://codesandbox.io/s/boring-thunder-qvibf?file=/src/App.js

Follow this steps:

  1. Set some value on input and see console log
  2. Click on button, the input receive new value
  3. Change value on input again
  4. Click on button, why doesn’t work again and set value to input?

I need independent children (functional component or class component), and sometimes I need use parent to set children value, but also keeping the children to change his own state, this is possible?

solution verification – Proof of greatest element of a non-empty set

I am working from Elliott Mendelson’s “Number Systems and the Foundations of Analysis,” which I am thoroughly enjoying thus far.

The proof I am struggling with comes at the end of a section on order relations in the chapter on natural numbers:

By a greatest element of a set $B subseteq P$ we mean an object $z$ such that $zin B$ and $(forall u)(uin B) implies u leq z)$.

If $emptyset neq A subseteq P$ and $A$ is bounded above (that is, $(exists w)(forall u)(u in A implies u leq w)$), then $A$ has a greatest element. (Hint: Let $B = {w: (forall u)(uin A implies u leq w)}$. By hypothesis, $B neq emptyset$. Apply the least number principle.)

The hint basically prescribes how to satisfy the requirement of a greatest element possessing the property that there exists some $z$ such that $(forall u)(uin B) implies u leq z)$. In particular, define $B$ as given in the hint; since $A$ is bounded above, $B$ is non-empty. Since $B$ is, in turn, non-empty, it possesses a least element by the least number principle. This least element of $B$ is clearly the “$z$” referred to above, i.e., the greatest element of $A$. I have been struggling for quite a while with demonstrating that this “$z$” is indeed contained in $A$. I have attempted the method of proof by contradiction considering the alternative case that $z notin A$, but can’t seem to figure a means to arrive at a contradiction. I’ve also considered induction proofs as a means of reaching a contradiction, but likewise can’t reach any contradictions. Can anyone provide an extra tip or approach to explore, please?

Why is the Kth Largest Element solution using a MinHeap O(N lgK) in complexity?

This is a rather well known solution to the $k$-th order statistic problem which requires us to find the $k$-th largest number in an unsorted array with $n$ elements where $1 leq k leq n$:

public int findKthLargest(int() nums, int k) {
        PriorityQueue<Integer> heap = new PriorityQueue<Integer>();
        
        for (int num: nums) {
            heap.add(num);
            
            if (heap.size() > k) {
                heap.remove();
            }
        }
        
        return heap.remove();
    }

A brief summary of this approach is that we maintain a min heap and keep polling from this heap each time its size exceeds $k$. This way, our final heap will contain $k$ elements, and these $k$ elements are guaranteed to be last $k$ elements in the sorted array (since we have been polling minimums). Within these last $k$ elements, the minimum element is guaranteed to be the $k$-th largest so we extract the min and return that as a result.

What I don’t particularly understand is why this problem is $mathcal{O}(n lg{(k)})$. For instance, after $mathcal{O}(n)$ creation of the heap, we do an extraction of the minimum $n – k $ times, which would require sifting up in the heap $n – k$ times and hence, shouldn’t this solution be $mathcal{O}(n lg{(n – k)})$?

Thanks!

replacement – Repeated ReplacePart On Each Element of a Square Matrix for Eigenvalue Difference

I have a large $ntimes n$ square matrix, whose elements are all either 0 or 1. I want to see by how much the single largest eigenvalue of the matrix (which Mathematica gives as the first element in the list from Eigenvalues) changes when I change each element of the matrix individually, so that I can produce a list of this eigenvalue difference for each element. A $10times 10$ matrix would thus give a list of 100 eigenvalue differences. By “changing each element”, I mean switching the element to 1 if it’s a 0 or to 0 if it’s a 1 in the original.

For instance, if the matrix is {{0, 1, 0}, {1, 0, 1}, {1, 0, 0}}, finding the largest eigenvalue of {{1, 1, 0}, {1, 0, 1}, {1, 0, 0}}, then that of {{0, 0, 0}, {1, 0, 1}, {1, 0, 0}}, then that of {{0, 1, 1}, {1, 0, 1}, {1, 0, 0}} etc…

I experimented with Loops but since $i$ and $j$ need to increase independently I couldn’t resolve that issue. I also thought of combining ReplacePart and If but can’t find a neat way of doing this for very large matrices.