Tagged Questions
1
vote
2answers
67 views
Check if a Binary Tree <String> is aBinary Search Tree
i'm understanding the question but wanna make sure if my implementation is correct or not =|
The Q is :
Write a method that accepts as its argument a BinaryTree object and returns true if the ...
1
vote
1answer
52 views
Double linked list with different dependencies
I need to connect different Task with a double linked list and different Dependencies which affect a calculation for which I need the values of both Task:
public class Task {
private ...
0
votes
1answer
43 views
2D Array: Retrieve the “Left” Item
I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board]
One of the things that I want to accomplish is to be able to retrieve ...
6
votes
3answers
349 views
Two Key HashMap
Background
Would like to create a two-key map that is fairly generic. In the existing system, there are a number of ways to name a parameter for a report. Rather than re-writing each report (too much ...
1
vote
2answers
108 views
How can this code become cleaner and less error prone? Especially the binary search part
How could this code become cleaner?
I think that the way I handle the interfaces and binary search could be improved.
I am trying to understand how to structure such a code 9and usage of APIs) in a ...
1
vote
2answers
81 views
Partition a linked list arround an element
This is my code to partition a list into two parts according to a value. I.e. nodes smaller than value x should precede nodes larger than the value x.
It seems correct. Any corner cases I am ...
2
votes
1answer
206 views
Returning Binary Search Tree Nodes in Zig Zag manner
I tried to implement an answer for the algorithm question given below. I implemented two different solutions. I couldn't decide which one is better. ( Maybe none )
Note: Node class and ZigZag ...
0
votes
2answers
80 views
How can I improve the run-time of my Java program?
I have a project for solving Diophantine equations, where a solution exists if
A^5 + B^5 + C^5 + D^5 + E^5 = F^5, where 0 < A <= B <= C <= D <=E <=
F <= N
The program ...
5
votes
2answers
333 views
In Java, how to operate the sublists efficiently?
In my Java program, I need to operate on the sublists a of ArrayList or LinkedList often, like removing a sublist, comparing two sublists.
For ArrayList or LinkedList, I didn't find any good APIs to ...
4
votes
1answer
162 views
Partitioning Array
Problem: Given a randomly ordered array of n-elements, partition the
elements into two subsets such that elements <=x are in one subset and
elements > x are in the other subset.
one way to do this ...
5
votes
1answer
781 views
A trie implementation for left to right wild card search
I was working on a task to implement auto suggest from an array of couple of thousands of strings.
Ofcourse the first and the easiest implementable was to go through each element and do ...
14
votes
4answers
638 views
About coding habits, a small java program as an example,
This is a piece of code to solve a simple problem:)
you can find the statements of this problem with this link
http://acm.bjtu.edu.cn/problem/detail?pid=1547
import java.util.ArrayList;
public ...
1
vote
2answers
6k views
Deleting a node from Binary Search Tree
I have read about it at few places and tried to write my own version, would like to get it reviewed.
class Node {
private int value;
private Node left;
private Node right
// ...
5
votes
2answers
340 views
Find all single elements in an array
I am interested in printing all numbers that do not have a match in an array.
Example: 1,3,4,5,3,4,5,5,6 result 1,5,6
Please review my solution bellow. What would be a much better way for this? Any ...
2
votes
2answers
2k views
Splay tree implementation
I am looking into splay trees and I implemented a version. It seems correct. Could someone please let me know if this indeed correct and how to improve it?
I will just show the insert item and splay. ...
3
votes
1answer
70 views
List creation of BST's nodes
I want to create lists of the nodes of a binary tree at each depth.
So if the depth is X I would have X lists.
Please see my approach. I think it is correct. Am I right to believe it is correct? Any ...
3
votes
3answers
395 views
Possible combinations of bills that sum to the given amount
Question:
You are given an array that represents bills in certain currency
(for example 1, 2, 5, 10) and an amount, for example 17. You should output
the number of possible combinations of ...
2
votes
2answers
3k views
Insert sort on a linked list
I want to do insert sort in a linked list without using dummy nodes.
This is my code. How can this be improved? Any input is appreciated.
public static Node insertSort(Node node){
Node ...
2
votes
2answers
364 views
Please Review my Generic Linked List Implementation in Java
I am looking for feedback on my Doubly Linked List implementation that I have written in Java. I am looking for specific feedback on the efficiency of my code, as well as my usage of generics. I am ...
0
votes
2answers
23k views
Singly linked list Java Implementation [closed]
Here I tried to implement singly Linked list in Java. Here I implemented adding element to the list,removing element from the list etc. Please tell me whether implementation is correct or not? If it's ...
5
votes
3answers
1k views
Check if a binary tree is a subtree of another tree
I am doing a refresher on algorithms.
I tried to solve the problem of determining if you have 2 trees (T1 and T2), one is a subtree of the other.
I came up with the following:
public boolean ...
2
votes
1answer
282 views
Preparing for coding competition, need your feedback
After checking some incoming coding competitions, I feel I may want to develop a little bit more on my coding skills and style using some basic algorithms/data structures.
The following two pieces of ...
3
votes
4answers
2k views
Code Review for Java Implementation of Linked List add(i, x) Method
I'm currently trying to brush up on ADT implementations, specifically an implementation for a Linked List (I'm using Java 5 to do this).
I have two questions:
(1) Is this implementation I've written ...
2
votes
5answers
708 views
Bounded blocking queue
Can someone please review this code for me. I have not implemented all the methods for simplicity.
Original code:
/**
* Implements a blocking bounded queue from a given non-blocking unbounded queue ...