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
1 vote
1 answer
550 views

Big-O time complexity for this code snippet

...
Angel's user avatar
  • 11
-1 votes
1 answer
146 views

"Cannot return a value from a method with void result type" but it's not void?

In Java, I'm getting the error for all my return statements that I can't return a value with a void result type, but I don't declare the return type as void anywhere, and I'm really not sure what the ...
eap's user avatar
  • 1
0 votes
1 answer
76 views

3sat to clique reduction program

I am searching for a program to convert 3sat to clique problem. I tried following links https://www.geeksforgeeks.org/maximal-clique-problem-recursive-solution/ https://www.geeksforgeeks.org/find-all-...
user's user avatar
  • 1
0 votes
0 answers
14 views

Can (intrinsic) locks act in different ways in addition to mutexes?

I'm reading Java Concurrency in Practice, and I came across the following sentence (section 2.3.1 Intrinsic locks, pg. 25): Every Java object can implicitly act as a lock for purposes of ...
uzluisf's user avatar
  • 101
0 votes
0 answers
32 views

Java: Non-static Communication. Ex: Type1 X; Type2 Y; X$\leftrightarrow$Y

I have two JFrame windows equipped with various components including JButtons and I want the actionPerformed methods for the buttons to send data between the two windows so that one can update the ...
KevinS's user avatar
  • 101
0 votes
1 answer
81 views

Why does Java's HashSet have an underlying HashMap, not the other way around?

Why does Java's HashSet have an underlying HashMap, not the other way around? HashMap could ...
Sergey's user avatar
  • 101
-1 votes
1 answer
44 views

How to find if a string in a list is an extension of another string with wild card *

Problem: Given a list of wild card strings(wild card is a * which is always at the end of a string), determine if the list has strings that are extension of another wild card string in the list. ...
sreethi's user avatar
0 votes
0 answers
14 views

Finding a ArrayList Connection (representing Subway Lines) with Recursion

I have this ArrayList (called linArray) (and this only) that contains Subway exchange stations (first the station name and then the lines you can exchange to at that station): ...
BlueInundation's user avatar
0 votes
1 answer
34 views

Threads and its priority in Java

I was experimenting with the concept of threading in java, we have a method setPriority, using which we can set thread priority. In official documentation it is given as below, But while seeing in ...
Niraj Jain's user avatar
2 votes
1 answer
66 views

Java optimization and minimization

I'm new to optimization and I have a little problem that I want to resolve with my job. Here we go! I need a certain number of drivers per day and each driver has 2 consecutive days off during the ...
Maxime's user avatar
  • 23
0 votes
1 answer
5k views

Update a property of all objects in a List/Collection/Array when at least one object satisfies a criteria using a single loop

Here is the puzzle I was asked in an interview There's a List of Employee objects. Update all the objects in the list to be eligibleForHike if at least one employee exists whose salary is less than x; ...
JavaHopper's user avatar
-2 votes
1 answer
62 views

What does this condition in the for loop mean?

I found a solution of exercise C-8.28 from Data Structures and Algorithms in Java (6th Edition), but I'm having trouble understanding how the for loop condition works here. ...
Tita's user avatar
  • 225
-2 votes
2 answers
63 views

Java | If a=250, b=3, c=(a + b/2)/b * b, Why doesn't c equal 251 but rather 249?

If int a = 250; int b = 3; int c = (a + b/2)/b * b; Why doesn't c equal 251, but rather 249? How is it that ...
Coo's user avatar
  • 109
0 votes
1 answer
927 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 ...
MMMORG's user avatar
  • 1
0 votes
1 answer
108 views

What is the time complexity of this Java program?

Below is the code. ...
Enterbot's user avatar
0 votes
1 answer
24 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,...
yaman's 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 ...
Bender's user avatar
  • 367
1 vote
1 answer
693 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 ...
Ali Reza Ghasemi's user avatar
0 votes
1 answer
66 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 ...
SixTwelfthsPi's user avatar
0 votes
4 answers
257 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 ...
Papu's user avatar
  • 3
-1 votes
2 answers
50 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( ; ; ){ }
dev-sn-27's user avatar
1 vote
1 answer
107 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 ...
MR.-c's user avatar
  • 197
-1 votes
1 answer
151 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 ...
pinky_dinky_doo400's user avatar
0 votes
1 answer
36 views

Why is this control flow graph correct?

Given the following method written in Java: ...
Monika's user avatar
  • 183
0 votes
0 answers
59 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: ...
Rishav Jayswal's user avatar
-1 votes
1 answer
42 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. ...
functionEqualsM's user avatar
1 vote
1 answer
69 views

Indentations in If-Else?

I am a beginner at Java and this code example came up in class: ...
Nathan King's user avatar
0 votes
2 answers
182 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?
Greg's user avatar
  • 1
0 votes
0 answers
43 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 ...
Suminda Sirinath S. Dharmasena's user avatar
-1 votes
1 answer
251 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 ...
user127836's user avatar
-1 votes
1 answer
37 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&...
zach's user avatar
  • 11
1 vote
1 answer
157 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 ...
Oleksandr Papchenko's user avatar
0 votes
0 answers
18 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 ...
void's user avatar
  • 11
0 votes
1 answer
302 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. ...
riley's user avatar
  • 1
0 votes
1 answer
250 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? ...
Sarah's user avatar
  • 1
0 votes
2 answers
2k 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 ...
Umer Farooq's user avatar
0 votes
1 answer
229 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....
dallasarch's user avatar
1 vote
2 answers
125 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 ...
Shashank Kumar's user avatar
0 votes
0 answers
23 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 ...
littleX's user avatar
0 votes
0 answers
47 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 ...
vivek gupta's user avatar
0 votes
3 answers
199 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{...
JJJJJJJJJJJJJJJJ's user avatar
1 vote
1 answer
101 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: ...
queenjekyll's user avatar
1 vote
0 answers
1k views

Time Complexity of Subset Problem

The Subset Exercise taken from LeetCode: ...
Giacomo's user avatar
  • 143
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 ...
Jaxox's user avatar
  • 121
2 votes
2 answers
142 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 ...
Sid's user avatar
  • 211
0 votes
1 answer
198 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 ...
Shyver's user avatar
  • 31
0 votes
2 answers
87 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 ...
Jakeinzah's user avatar
0 votes
0 answers
265 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 ...
TomR's user avatar
  • 1,381
2 votes
1 answer
115 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 ...
mwal's user avatar
  • 121
3 votes
1 answer
324 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 ...
misha312's user avatar
  • 209