2022 Developer Survey is open! Take survey.

Questions tagged [java]

Programming questions are off-topic here. Do not ask questions about how to write code in Java. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

Filter by
Sorted by
Tagged with
0 votes
0 answers
5 views

How to create database query to calculate automated commision for each associate?

The following queries required: 1] Provide the commission tabulations due each month to associates 2] Along with the commissions for each associate provide the actual number of active memberships that ...
user avatar
0 votes
1 answer
41 views

Solve modified knapsack problem using dynamic programming

I'm trying to solve following modified knapsack problem using dynamic programming. What we know: Total number of items Item weight, value and type Knapsack capacity Aims Find Maximum weight of ...
user avatar
  • 1
0 votes
0 answers
29 views

What is the time complexity of this Java program?

Below is the code. ...
user avatar
0 votes
0 answers
22 views

Find the value using call by reference and call by value

Given the following code: ...
user avatar
  • 13
0 votes
1 answer
13 views

Find the output value using call by value and call by reference

Given the following code: int p = 5 , q=2; int f( int b, int c){ b = 2 * c; c = 3 + p; return b + c ;} print f(p,q); print p; print q; I have found that the output values using call by value are: f(p,...
user avatar
  • 13
11 votes
2 answers
2k views

Why is the Java HashMap load factor 0.75?

I can't understand why the Java HashMap load factor is 0.75. If I understand well, the formula for the load factor is n/m, where n is the number of key and m is the number of position in the hash ...
user avatar
  • 315
0 votes
0 answers
86 views

How to incorporate Duplicate Letter Handling for Wordle?

I am trying to reverse engineer the following image. So far, the way I would take into account of duplicate letter handling is the following . I am unsure how I could code this such that the ...
user avatar
0 votes
0 answers
16 views

Count all independent sets and cliques of an undirected graph

I need to write a Java program that tells if a graph is a (k, l)-graph or not, that is, if we can partition its set of vertices into k independent sets and l cliques. Then I would need to build a ...
user avatar
0 votes
1 answer
38 views

Which type can cause problems with encapsulation in Java?

Out of the following, which type can cause problems with encapsulation? A. Int B. Int[] C. String D. non of the above I chose D and was incorrect. I am kind of confused what this questions is asking ...
user avatar
0 votes
3 answers
76 views

How to make a Huffman tree

I'm trying to make a huffman tree based off of some words. I have the frequencies of each character stored using a hashtable, but i need to then make a minheap structure in order to then be able to ...
user avatar
  • 1
-1 votes
2 answers
37 views

why Loop-Programm always terminates

well-known that a loop-programm in Theoretical computer science always terminates, but why do that java example not? for( ; ; ){ }
user avatar
1 vote
1 answer
67 views

virtual machine based programming languages vs low level

I took programming lecture it was about C/java and how to build compilers, so I wanted to know. As far I see, languages like Java/C# are developing their virtual machine CLR/JVM with good base and are ...
user avatar
  • 199
-1 votes
1 answer
88 views

UCS and Dijkstra's algorithm do both of them give the minimal cost between two vertices?

i tried both algorithm to find the shortest path with minimal cost between two vertices,but most of the time Dijkstra gives a different path and the cost is smaller than the cost for the path UCS ...
user avatar
0 votes
1 answer
28 views

Why is this control flow graph correct?

Given the following method written in Java: ...
user avatar
  • 183
0 votes
0 answers
36 views

Reordering similar elements together within an array

I have a requirement where I need to group similar elements together within an original list. For example: I/P array: ...
user avatar
-1 votes
1 answer
34 views

help understanding the recurrence relation of an algorithm

I have the following code which I have to figure out the recurrence relation, but I am having a bit of a trouble understanding what the algorithm does exactly. ...
user avatar
1 vote
1 answer
44 views

Indentations in If-Else?

I am a beginner at Java and this code example came up in class: ...
user avatar
0 votes
2 answers
144 views

What are the differences between the set of Real Numbers and the Java datatype float?

Besides the fact that the real numbers ℝ go on forever whereas the floats only go up to a certain point (Float.MAX_VALUE) in Java, what else could I compare between these two sets of numbers?
user avatar
  • 1
0 votes
0 answers
20 views

What is the currently know fastest algorithms to convert each individual Java primitive and Number types to a Char Array/String

What is the currently know fastest algorithms to convert each individual Java primitive and Number types to a Char Array/String number representation while ...
user avatar
-1 votes
1 answer
134 views

Blueprint for class and objects in Java

Good morning everybody. I would like to know if there is a blueprint I could refer to when creating classes and objects in Java? For instance, I was told for classes. You start VARIABLES DECLARATIONS ...
user avatar
  • 1
-1 votes
1 answer
36 views

Java programming object terminology

Say there is a class called Person. Then in the following expression : Person human = new Person() Which is the "reference&...
user avatar
  • 1
1 vote
1 answer
105 views

What is loop invariant for this loop?

As far as i understand all loops have a loop invariants. My understanding is that loop invariant is an argument that is true at the beginning of the loop block as well as at the end of the loop. For ...
user avatar
0 votes
0 answers
13 views

How to remove filaments from a planar graph?

I have a planar graph and I'm trying to implement this algorithm (https://geometrictools.com/Documentation/MinimalCycleBasis.pdf Chapter 4, page 3). For the filament F0(V4, V3, V2), that has one ...
user avatar
  • 1
0 votes
1 answer
197 views

How to draw the heap for an array in Java?

I have an assignment to draw the heap after an ArrayList and a LinkedList is created. ...
user avatar
  • 1
0 votes
1 answer
131 views

How to calculate the runtime of a following code?

Could someone explain how to calculate the Big O notation for a runtime of a snippet of a code? ...
user avatar
  • 1
0 votes
2 answers
801 views

Intelligent use of XOR operator to find missing number

I've come across the following problem on leetcode & tried to solve it with the following code however there seems to be an even better solution that takes advantage of XOR. Leetcode has a ...
user avatar
0 votes
1 answer
163 views

Elements of Programming Interviews - 16.4 Generate Power Set - solution 1 time complexity question

hope you all are doing well. I have a question about the time complexity of solution 1 for question 16.4 - Generate Power Set from the book Elements of Programming Interviews by Adnan and Tsung-Hsien....
user avatar
1 vote
2 answers
72 views

Can Yacc be used to generate three address code for Java 1?

I have read that yacc generates bottom up parser for LALR(1) grammars. I have a grammar for Java 1 that can be used for generating three address code and is strictly LALR(1), but the translation ...
user avatar
0 votes
0 answers
22 views

How to get synonyms from definitions using Bayes algorithm

I work on a project: an online dictionary where the user can find definitions of a word he's looking for. My supervisor asked us to add synonyms using machine learning. He recommend us to use Bayes ...
user avatar
0 votes
0 answers
37 views

Please explain the algorithm for finding bridges in graph?

let, low[] and disc[] be two 1D arrays disc[i] stores the discovery time of node[I] low[i] stores the lowest value between disc[i] and discovery time of children of node[i] I'm curious that what is ...
user avatar
0 votes
2 answers
117 views

Numerical Approximation in Java

I am trying to solve an equation which I believe cannot be done analytically, but can use a numerical approximation to get a result. The equation is: $$\frac{2*\sqrt{\pi}*h*s*e^{m^{2}/(2*s^2)}}{\sqrt{...
user avatar
1 vote
1 answer
70 views

Difficulty in understanding this summations to analyze time complexity

I wanna know if what this link https://stackabuse.com/shell-sort-in-java/'s calculation of the complexity of shell sort is true. Here's the shell sort algorithm: ...
user avatar
1 vote
0 answers
995 views

Time Complexity of Subset Problem

The Subset Exercise taken from LeetCode: ...
user avatar
  • 123
2 votes
0 answers
1k views

How to visualize complex algorithm, like Split Array Largest Sum

I am trying to do the leetcode question I got the answer and trying to understand a systematical way to come up with the answer using the DP bottom-up approach, and I am having a hard time to ...
user avatar
  • 121
2 votes
2 answers
77 views

Minimum words in a string given a dictionary

The question is: Given a dictionary consisting of a set of words and a string: find the minimum number of words the string can be split into. If the string can not be decomposed into a list of words ...
user avatar
  • 201
0 votes
1 answer
72 views

Creating sum of all numbers within a sequence [duplicate]

Write an algorithm that, given sequence seq of n numbers where 3 <= n <= 1000 and each number k in seq 1 <= k <= 200, finds maximum sum by repeatedly removing one number from seq, except ...
user avatar
  • 31
0 votes
2 answers
74 views

Why does a RNN network output different based on the training sequence

I've set up an RNN LSTM network in Java using DL4J as the library. I currently have 500 examples of positive text, and 500 examples of negative text. When I fitness the training data by first ...
user avatar
0 votes
0 answers
198 views

Converting Turing machine into the source code in industrial programming language?

Are there methods how to convert Turing machine (e.g. neural Turing machine or other rigorous Turing machine) into the source code/program that is written in some industrial programming language like ...
user avatar
  • 1,351
2 votes
1 answer
66 views

In what sense if any does java have multiple dispatch?

I'm trying to get my head around the difference between message passing (with which we are all familiar as by far the most common form of object orientation today) vs generic functions as implemented ...
user avatar
  • 121
3 votes
1 answer
187 views

Sum of unique integers to cnf constraint

As a study project I try to solve the kakuro puzzle problem using SAT SOLVER. I can't really find an efficient way to convert the sum of k unique integers (1...9) to a CNF constraint. What I had in ...
user avatar
  • 209
0 votes
1 answer
70 views

What is a constructor in java? [closed]

I have checked many websites but did not get the right answer. what is the meaning of constructor in java?
user avatar
4 votes
1 answer
240 views

Linked list: advantages of preventing movement of nodes and invalidating iterators on add/remove

C++ and Java include native classes for linked lists, C++ std::list and Java LinkedList For C++ std::list, nodes can be "moved" within a list, or from list to list (if the lists are compatible), via ...
user avatar
  • 324
1 vote
0 answers
80 views

What is the difference between self-rewriting program and program-with-updates-and-restart

I am reading about Goedel machine http://people.idsia.ch/~juergen/goedelmachine.html and especially the article about possible implementation (in the Scheme language) of this machine http://people....
user avatar
  • 1,351
0 votes
0 answers
129 views

Given n strings, how to output their order after k phases of the radix sort (huge constraints)?

Disclaimer This is not from an ongoing contest, this is from my course of ITMO on edx.org, which is a paid code so I cannot give you a direct link to the course. Problem You are given $\...
user avatar
-1 votes
2 answers
1k views

Is there any way to find the nodes in the each subtree of each node having distance equal to height of the subtree?

We are given a tree of N nodes from 1 to N where node 1 is the root of the tree. For each node i from 1 to N, you have to find the numbers of nodes which are in the subtree of i and are at distance ...
user avatar
  • 1
0 votes
1 answer
151 views

Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2

Given (n) , what is the Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2. Is there any way I can re-write this code just without using nested loop? ...
user avatar
1 vote
0 answers
34 views

Java configuration for int-amqp [closed]

I am trying to convert a XML based configuration to JAVA based configuration. Can someone please let me know the java annotation based configuration for the following ...
user avatar
2 votes
1 answer
162 views

Find path from node

I have a question where I need to find a path from node 1 to node N in an undirected graph given weights in O(A Log^2 A). The total cost of each path must not ...
user avatar
-1 votes
1 answer
75 views

How does the instanceof operator work in the context of downcasting in java? [closed]

I am trying to understand the purpose of using the instanceof operator as a way to properly downcast an object in java. I really hope someone can help. Below is more code: ...
user avatar
1 vote
0 answers
50 views

Prove that a recursive program satisfies a logic predicate with implication and quantifiers by induction [closed]

i have this program to prove: ...
user avatar
  • 11