Posts by Sérgio Mucciaccia • 2,745 points
47 posts
-
1
votes2
answers1498
viewsQ: How to delete all untracked files at once in git?
Whirling git status in a briefcase: On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: b.txt Changes not staged for commit: (use "git add…
gitasked Sérgio Mucciaccia 2,745 -
1
votes1
answer99
viewsA: Distinc Criteria Hibernate java
I’m not sure I understand your question. I got that: SELECT distinct * FROM entidade2 e2 WHERE e2.id not in ( SELECT e1.commentId FROM entidade1 e1 WHERE e1.userId = 1 ); Using HQL would look:…
-
1
votes2
answers1031
viewsA: Divide vector according to delimiters and copy content to other strings in C
One possibility would be: #include<stdio.h> #include<string.h> int main(){ int tam = 256; char vetor[tam]; char segundo[tam]; char terceiro[tam]; int i = 0; int j = 0; fgets(vetor, tam,…
-
2
votes1
answer1778
viewsA: Object persisting problem with @Manytoone - JPA/Hibernate
In JPA there is the concept of relationship owner (Relationship Owner). In your case it is the entity Item that holds a foreign key to the entity Declarationtax, therefore it is the entity Item that…
-
1
votes1
answer164
viewsA: Manytomany mapping. Bean problem
Within your term object you have a list of attorneys right? To save a deadline along with references to your attorneys just take these attorneys from the database with find() and add them to the…
-
6
votes1
answer641
viewsA: How does the Conditional Random Fields algorithm work?
Let’s assume you like to keep track of your favorite company’s daily stock price. One day you notice a strange relationship: on days when it rains, the stock price is more likely to rise. Intrigued,…
-
19
votes4
answers8677
viewsA: What’s the difference between data and information?
Datum I believe that the concept of data has a relatively precise definition, being used with the same interpretation in several areas. In computing there are for example the terms data structure,…
terminologyanswered Sérgio Mucciaccia 2,745 -
1
votes1
answer339
viewsA: Why is the complexity cost of a BFS O(n+m)?
That depends... If you are using a list of adjacencies to represent the graph, the search algorithm in width (BFS) will have complexity O(V+A) being V the number of vertices and A the number of…
c++answered Sérgio Mucciaccia 2,745 -
9
votes1
answer2359
viewsA: Difference in the application of Dijkstra and Prim algorithms
The original algorithm proposed by Dijkstra serves to find the shortest path from an initial node to a final node. But the most widely used Dijkstra algorithm is a variant that finds the shortest…
graphanswered Sérgio Mucciaccia 2,745 -
2
votes1
answer1905
viewsA: Set the shortest path in graphs
Finding the shortest path in a graph is a little more complex than this. In your case where all edges have the same weight it is possible to use a search in width. The following code is an example…
-
20
votes1
answer25509
viewsQ: What exactly does git checkout branch -- . do?
I would like to understand this command in an easier way, I did some tests but I’m not quite sure of the conclusion. I have two branches, the master branch and the new branch, and I did the test…
gitasked Sérgio Mucciaccia 2,745 -
2
votes2
answers116
viewsA: Word problem with same letters
Hello! I made a reasonably efficient solution, it’s very easy to understand: import java.util.*; public class App { public static void main(String[] args) { String a[] =…
-
1
votes1
answer392
viewsA: JPA/Hibernate Entity with Collection for itself
This happens because the JOIN of JPA was made to imitate the JOIN of SQL and this behavior observed is exactly the JOIN behavior of SQL! A JOIN between two JPA menus would be equivalent to the query…
-
4
votes1
answer438
viewsQ: What is the Java Constant pool?
I am reading the Java Virtual Machine Specification to go a little deeper and I didn’t fully understand what the Constant pool table is. For example, when speaking da run-time Constant pool…
-
1
votes1
answer564
viewsA: Autowired spring boot in Jframe
Spring will not manage instances created with new! Spring itself must create the class instance for the injections to work. The right one would be to inject the itemFrame object by Spring as well,…
-
1
votes1
answer500
viewsA: Calculated Field JPA Spring Boot
The default value of a Double variable in Java is null, so when you declare a variable without initializing it its initial value will be null. Initialize the total variable with zero value first as…
-
1
votes1
answer561
viewsA: Persist associative table in manyTomany
Suppose you have a person with id 1L and a Time with id 2L in the database and want to add a relation between the two as a row in the Personal Time table. The code would look like this:…
-
1
votes1
answer542
viewsA: No bean corresponds to CDI injection point
To be used with CDI your class needs to have a constructor without parameters or your constructor with parameters should be annotated with @Inject (but ai ensure that the parameters will be injected…
-
1
votes1
answer1605
viewsA: Removing items from a Onetomany relation by default
The child is an entity of its own and can exist even without a parent. So removing the relationship does not mean removing the child. To no longer appear in the database the child must be removed…
-
1
votes1
answer86
viewsA: Entitylisteners @Transactional Demoiselle - Id null
According to the JSR 338 specification (Java Persistence API, Version 2.1) on page 101: It is implementation-dependent as to whether callback methods are Invoked before or after the Cascading of the…
-
1
votes1
answer152
viewsA: Hibernate shows ddl but does not create tables in the database
Note that in your file persistence.xml has the line: <property name="hibernate.hbm2ddl.auto" value="create-drop" /> Worth create-drop Hibernate will delete all tables, create new tables and at…
-
1
votes1
answer504
viewsA: Mysql select Random with priorities
I think the easiest thing in this case would be to use a Procedure and make a loop drawing each line with the conditions. But I was able to think of a way to make the appointments without it. Mysql…
-
1
votes1
answer108
viewsA: Are the keys in a knot of a B-Tree in non-decreasing or ascending order?
B-Tree is a kind of generalization of the binary tree, where the nodes are grouped into pages and each of them can point to several others. Its properties make it ideal to work with disks, as it…
treeanswered Sérgio Mucciaccia 2,745 -
1
votes1
answer265
viewsQ: Due to NAT, is the IP access count imperfect?
I found it difficult to find content on the internet about this. I would like to know in general what is NAT (Network Address Translation), how it maps private Ips on a public IP and mainly where…
-
5
votes4
answers2247
viewsA: What is the iterative (non-recursive) version of the LCA (Lower Common Ancestor) algorithm
Very good answer utluiz! But if I may, in my opinion an algorithm is characterized by its efficiency, memory consumption and accuracy for each case of the problem being solved. Since your algorithm…
algorithmanswered Sérgio Mucciaccia 2,745 -
3
votes2
answers1449
viewsA: Putting and comparing dominoes in order in C, using list or not ( if you can without)
Luiz Viera’s excellent answer! Just out of curiosity and to complement, this dominoes problem is a classic problem in graph theory! It is isomorphic to the problem of bridges from generalized…
-
23
votes1
answer14650
viewsA: What are the differences between utf8 and utf8mb4?
In the past, programming languages only supported ASCII encoding that defines 128 symbols. This encoding is excellent for English, producing very compact texts where each letter spends only one…
-
6
votes1
answer755
viewsQ: How to make an interface in C++?
Java, C# and other languages have the concept of interface, which is very useful in some circumstances. How to interface or get closer to it in C++?
-
1
votes3
answers3385
viewsA: 2 COUNT within a SELECT with LEFT JOIN
The COUNT aggregation function counts the number of rows in the table, so COUNT(id_receive) or COUNT(id_send), will make no difference in this case, as the table has the same number of rows in both…
-
2
votes2
answers361
viewsA: Count friends in common using LEFT JOIN
By the question I understood that you want all friends in common between two users. SELECT u.usuario, u.pnome, u.snome, u.foto, COUNT(c.id) as comum FROM amizades a INNER JOIN usuarios u ON…
-
9
votes1
answer325
viewsQ: In C++ where are the functions of the objects in memory?
In C++ when an object is declared, class variables are stored in the stack or in the heap depending on how the object was created. With the operator sizeof() it is possible to test and realize that…
-
2
votes1
answer12084
viewsA: Random letters: How to generate with Rand and how to compare them in C
Your code is working perfectly, just missing add 'a' in each vector char. And your Bubble Sort is ordering in ascending order and not decreasing. To change this just change the > to < no if.…
-
2
votes2
answers809
viewsA: What will the new logic of quantum computer programming look like?
The logic of a quantum computer is completely different! First, every function used in a quantum computer must be reversible, i.e., with the output it must be possible to generate the input again.…
-
2
votes3
answers3650
viewsA: Scanf function with variable amount of parameters, how to implement?
Good if you want to read until the end of the file do so: #include<stdio.h> int main(){ int a[30], n = 0; while(scanf("%d", &a[n++]) != EOF && n < 30) printf("a[%d] = %d, ",…
-
8
votes2
answers1931
viewsA: Meta Keywords is still needed?
Google does not use the Keywords meta tag to process the ranking of the sites that will be displayed in a search. In the link below you can check which meta tags the google robot uses to index the…
meta-tagsanswered Sérgio Mucciaccia 2,745 -
9
votes1
answer574
viewsQ: What is Explicit in C++?
I came across the term explicit being used in a C code++. What is the use of this keyword?
-
7
votes1
answer1284
viewsQ: Cin vs scanf, which is faster?
In competitive programming it is common for several programmers to use scanf() and printf() in C++ code instead of using cin and cout. And I’ve even seen problems that result in a Time Limit…
-
12
votes4
answers1048
viewsA: Should every algorithm be finite?
The best consideration to make is that your example is a computational method, but not an algorithm. I will argue why this statement follows. Like: Almost all major articles that contributed to the…
-
8
votes2
answers2560
viewsA: Fork in Windows
One of the biggest difficulties in porting Unix programs to Windows is precisely the process model of the two operating systems. Windows does not have the Fork call. Depending on how Fork is used in…
-
2
votes1
answer364
viewsQ: How to know if three points are clockwise or not in C/C++?
Given three points P1, P2 and P3, what is the best way to know whether this order is clockwise, counterclockwise, or neither (the three are collinear)? For example, in the image below the dots are…
-
4
votes1
answer1023
viewsQ: Why is the size of a struct not the sum of the sizes of its variables?
For example, the following code: #include <stdio.h> struct exemplo{ char letra; int numero; float flutuante; }; int main() { printf("Tamanho do char: %u\n", sizeof(char)); printf("Tamanho do…
-
1
votes2
answers1768
viewsA: Algorithm in C - Primes
Well there goes an example of solution to your problem. It is based on generating a vector containing 1 for the numbers that are primes and 0 for the numbers that are not, it is the famous…
-
1
votes4
answers9378
viewsA: Algorithm Factorization in C
Usually when we talk about factoring a number what we want are the prime factors and their multiplicity. Here’s a factorization algorithm I made based on the Eratosthenes sieve. #include…
-
2
votes1
answer2118
viewsA: While Loop in Assembly MIPS
Assuming i = $s1 total = $s2 n = $s3 The code would look like this: .text add $s1 , zero , zero add $s2 , zero , zero Loop: slt $t0, $s1, $s3 beq $t0, $zero, Exit la $t1, endereco_de_X # Pegar o…
-
2
votes1
answer1369
viewsA: Insertion Sort in double-linked circular list
Well, you made a mess with pointers and the algorithm, I modified your code and it’s working normally here. Your if(n) should be a while, since the Insertion Sort performs several exchanges for each…
canswered Sérgio Mucciaccia 2,745 -
1
votes1
answer854
viewsQ: What is the use of the extern keyword in c?
I saw on the site with link below that in ANSI C pattern there is the extern keyword, but never seen being used in practice. What exactly does it? http://tigcc.ticalc.org/doc/keywords.html…
casked Sérgio Mucciaccia 2,745 -
2
votes1
answer265
viewsA: How to solve the recurrence function T(n)=2T (n 1/2) + logn ? Cormen Book Exercise cap 4
Whereas log(n) is at base 2, the solution of the recurrence function is thus: T(n) = 2*T( sqrt(n) ) + log(n) Substituindo n = 2^m T(2^m) = 2*T( sqrt(2^m) ) + log(2^m) T(2^m) = 2*T( 2^(m/2) ) + m…
canswered Sérgio Mucciaccia 2,745