Tagged Questions
4
votes
2answers
78 views
Implement queue using linkedlist
Implement queue using linkedlist. Looking for code review, optimizations and best practices.
...
2
votes
1answer
35 views
Detect a complete binary tree
Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices.
...
4
votes
1answer
32 views
Implement stack using a linked list
I am trying to implement Stack using a linked list. Looking for code-review, best practices and optimizations.
...
4
votes
1answer
37 views
Counting inversions
Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion ...
3
votes
2answers
130 views
How is my Java code for stack implementation?
The following example shows how to implement stack by creating user defined push() method for entering elements and pop() method ...
4
votes
1answer
313 views
Queued Employees
The following example shows how to implement a queue in an employee structure. I am looking for a review of the implementation:
...
5
votes
2answers
523 views
Comparing list elements in an effective way
I have a list of opened nodes, with each step about 3000 nodes are opened and I want to put to the opened list only those nodes that are not already there. For now I'm just comparing each new one to ...
2
votes
1answer
47 views
M coloring problem
Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with same color. Here coloring of a ...
9
votes
3answers
170 views
Calculating infix expression with no parenthesis
This is my Java implementation (\$O(n)\$) about how to calculate infix expression with no parenthesis.
For example, when we input "3 + 4 * 4 / 8", we will get a double type answer is 5.0. Here to ...
0
votes
2answers
86 views
Stack implementation using a queue
I've implemented a stack using a queue.
Time complexity:
\$O(n)\$ - push(), where n is the number of elements in the queue
\$O(1)\$ - ...
4
votes
2answers
346 views
Implement data structure overflow queue
Implement data structure overflow queue. Overflow queue is a normal queue with one extra property. It never throw Stack overflow exception. So whenever queue becomes full, it replaces the oldest ...
3
votes
0answers
43 views
Morris inorder traversal
Morris Inorder traversal - an algorithm for in-order traversal, of a tree, without recursion of extra memory. Looking for code review, optimizations and best practices.
...
7
votes
2answers
115 views
Java implementation of spell-checking algorithm
This little program was written for an assignment in a data structures and algorithms class. This is my first post here, and I understand that I shouldn't post the entire assignment, so in lieu of ...
3
votes
2answers
131 views
BinarySearch Tree implementation & traversals
I am practicing various tree algorithms and that require code review for it's efficiency, clarity and also if it can be made better etc.
Is there a better way to call ...
2
votes
4answers
845 views
Depth First Search & Breadth First Search implementation
I've implemented DFS and BFS implementations. I want to check if the code is readable, contains any issues, and can be improved.
GraphImplementation
...
1
vote
1answer
55 views
Appropriate insertion sorting algorithm
I am learning data structures, and have written an algorithm for insertion sort after learning from some sources. But I am confused which implementation is more correct or appropriate.
Code #1 This ...
6
votes
2answers
541 views
Count frequency of words in a given file
Write a function that takes two parameters:
a String representing a text document
an integer providing the number of items to return
Implement ...
4
votes
1answer
1k views
Partitioning array elements into two subsets
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.
...
5
votes
2answers
2k views
Implementation of Dijkstra's algorithm
Please pick my code apart and give me some feedback on how I could make it better or more simple.
...
2
votes
2answers
7k 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.
...
9
votes
3answers
696 views
Checking brackets nesting in a string
I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the ...
10
votes
1answer
101 views
Binary Tree/ Amorphous Binary Tree Creator
I suppose this is a two-part question. The first part is just a simple implementation of a Binary Tree (BTree), with pre-order, post-order, and in-order searches ...
18
votes
5answers
1k views
6
votes
3answers
129 views
How to extract elements from multiple sorted list efficiently?
Problem Statement:-
I was ask this interview question recently.. I was able to come up with the below code only which runs in O(k log n)-
Given k <= n sorted arrays each of size n, there exists ...
6
votes
1answer
412 views
10
votes
2answers
153 views
Thread-safe prime number source
I am working on some multi-threaded code that requires a prime-number source.
The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
2
votes
1answer
266 views
Printing the values on each level of a Binary Tree
The below code is for printing level-by-level in a binary tree:
...
5
votes
1answer
105 views
Duplicate detection and reporting in a BST
For the purpose of this problem, the BST is defined to allow duplicates, and the duplicate values will always follow to the right-side of the parent nodes with the same value. For example, with the ...
3
votes
2answers
172 views
Least common ancestor in binary tree
This code finds a common ancestor. If one of the input does not exist in the tree then throws an exception. This does not use extra storage. It does not even traverse more than what it should be. It ...
4
votes
1answer
5k views
Create a tree from a list of nodes with parent pointers only
I want you to pick my code apart and give me some feedback on how I could make it better or more simple.
...
-1
votes
1answer
227 views
Join levels of binary tree
Please ignore feedback to include generics and function renaming while giving me feedback. Names of functions have been deliberately kept the way they are for time-being. Also please let me know if ...
2
votes
2answers
289 views
2
votes
1answer
493 views
Least common ancestor for binary search tree
I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code finds a common ancestor for binary search tree. This code accounts duplicates as ...
0
votes
1answer
130 views
Find the mean of the medians of two equal sized sorted arrays [closed]
A corrected solution is found here
Looking for code review, clever optimizations, adherence to best practices. etc.
As an example:
a1[1, 3, 5, 7]
a2[2, 4, 6, 8]
The median for each array is the ...
3
votes
1answer
123 views
Inorder traversal of a tree without recursion or stack
Please review the code for code cleanup, smart optimizations and best practices. Also verify my complexity: O(n2), where n is the number of nodes
...
2
votes
2answers
556 views
Creating an Array of Linked Lists from a BST
Question
Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists)
Here is my ...
2
votes
1answer
225 views
How can this code, especially the binary search, become cleaner and less error-prone?
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 (and usage of APIs) in a ...
3
votes
2answers
123 views
Constructing a binary tree in java
I am constructing a binary tree. Let me know if this is a right way to do it. If not please tell me how to?? I could not find a proper link where constructing a general binary tree has been coded. ...
2
votes
1answer
49 views
Join of two databases
This is the most basic code to join two tables in a database. For tables it uses a simple list. Solved this using brute force, sorting and using hashtable.
...
2
votes
2answers
3k 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 ...
1
vote
1answer
124 views
Given preorder array construct a BST
Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. Also its really hard to make this code work if ...
2
votes
1answer
2k views
Design LRU cache interview questions
Code reviewers, I request you review the code and suggest all tips for improvement.
...
3
votes
1answer
987 views
Print path(leaf to root) with max sum in a binary tree - code review request
Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple.
...
3
votes
2answers
750 views
Creating a binary search tree
I want you to pick my code apart and give me some feedback on how I could make it better or simpler. Although, agree that generics should be used, instead of integers, let's punt on generics as a ...
1
vote
1answer
46 views
FixedSizePriorityQueue - Review Request
I implemented the FixedSizePriorityQueue class. The intended purpose is that, you can add as many elements as you want, but it will store only the greatest ...
4
votes
4answers
1k views
Check if a Binary Tree <String> is aBinary Search Tree
I'm understanding the question, but I want to know whether or not my implementation is correct.
The question is:
Write a method that accepts as its argument a BinaryTree object and
returns true ...
2
votes
1answer
647 views
Finding inorder successor
I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code finds inorder successor in a binary tree.
...
4
votes
3answers
1k views
Flatten iterator for nested list
Given a list which can can contain elements as well as lists, write an iterator to flatten a nested list. Please make this code better and suggest any improvements.
...
1
vote
1answer
279 views
2
votes
1answer
128 views