A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.
2
votes
1answer
65 views
Binary Search Tree in C
I have implemented a BST from scratch. My aim is to draft better code and understand some pitfalls which I may have overlooked.
It includes the following functionalities:
Insert a new item.
Find ...
-2
votes
0answers
12 views
How to yearly upgrade students in new grades/classes in school management system [on hold]
I'm sorry if this question is inappropriate. if it doesn't fit here kindly give me specific link where i can get a solution or please answer here!
I've been through many solutions on this site but i'm ...
8
votes
1answer
80 views
Java Trie structure
I recently have been working on a Trie in Java. I have looked at the related posts here on Code Review to try and enhance my code, but I do have some methods and constraints not present on other ...
2
votes
1answer
83 views
Constructing and maintaining a complete binary tree
Problem statement:
Create and maintain a Complete Binary Tree in C. Include the following
operations.
Insert a given key and perform inorder
Replace ALL occurrences of the given key ...
17
votes
2answers
572 views
Designing another Coffee Machine Application
After reading Designing a coffee machine yesterday, I decided I could also give the same problem a try.
I have used the following problem statement (copied from the given question):
Design a ...
3
votes
1answer
69 views
3-stack implementation with a single array
I'm teaching myself data structures and would really appreciate some feedback on my stack implementation.
A couple of things I'm not sure if I should be doing:
creation of the array and pointer ...
27
votes
5answers
3k views
Designing a coffee machine
I was recently rejected from what looked like a really promising string of interviews. I did very well in a questionnaire style review, and then they handed me this assignment (more or less):
...
1
vote
0answers
15 views
Entering base characters one-by-one for a List [closed]
This function should prompt the user to enter bases characters (a, g, c and t) one-by-one and then insert them in the List.
...
6
votes
2answers
374 views
C++ Linked List Implementation
I'm learning C++ and also about data structures, so I am trying to implement some. This is my linked list. I've included two different ways of getting the length of the list, with a ...
11
votes
5answers
707 views
Singly Linked List in Java
I created my own implementation of a Singly Linked List. Is there anything I can improve on, in terms of effciency. Also, what other methods would you recommend for me to try and implement. My goal is ...
0
votes
0answers
31 views
Extract and rename specific columns of a CSV data file
I have a CSV data file with 3,896 columns (variables), and I am attempting to extract a particular subset of columns for use in a data analysis project. To avoid the burden of having to constantly ...
6
votes
1answer
48 views
Prefix trees for auto suggest
I wrote a quick prefix tree implementation. I know it may be far from perfect, but I need to make sure that I got the basics right.
My main concerns are:
Have I settled for the correct data ...
3
votes
1answer
80 views
Depth First Search and Breadth First Search in C++
I am trying to learn DFS and BFS. However, I just want to make sure that I am not doing anything wrong. Would you please determine if the BFS and DFS functions are correct?
...
7
votes
3answers
168 views
Return list of common email ids from a list of lists
Input: ArrayList of ArrayLists with email ids.
Output: Return ArrayList of email ids which appears in each inner ArrayList.
Ex: Input: [[[email protected], ...
0
votes
3answers
81 views
Finding all integers in an array with odd occurrence
I am doing an interview exercise problem from here.
The problem is to find "all numbers that occurred an odd-number of times in an array".
Here is my high level psuedo code thinking:
Construct a ...
1
vote
1answer
49 views
Data structure for inserting and replacing data in list
I have a list of key value pairs, that is used as an intermediate store for building URL parameters or JSON data. Currently this is done with a linked list:
...
3
votes
1answer
42 views
Perceptron algorithm
This is the Perceptron algorithm, I wrote this implementation with my friend. It gets the job done, but it's quite dirty, perhaps one of you stylish hackers might help me beautify this beast.
This ...
14
votes
4answers
1k views
Smart as a bag of rocks
For my second project in CS2, I was given the following assignment:
Implement a new ADT called a bag with receipts.
The specification for the class of bag with receipts differs from a
...
3
votes
1answer
65 views
Trie Implementation in Java
I am trying to implement a Trie class in Java which just supports insertion and searching operation up until now. I think it works perfectly on the several examples ...
6
votes
0answers
52 views
Memory Segmentation Simulation
I recently have been working on a project to simulate segmentation in memory. I wanted to create everything from scratch; not use pre-built data structures.
I create a memory object that allows for ...
2
votes
0answers
55 views
Linked list order reverse program efficiency
Here is my function which convert linked list in the following order:
Example:
Inputs: 1->2->3->4->5->6->7->8->NULL and k = 3
Output: 3->2->1->6->5->4->8->7->NULL.
Code:
...
5
votes
3answers
92 views
Check if a binary tree is balanced
Looking for code-review, optimizations and best practices. This question is attributed to geeksforgeeks.
NOTE: Please help me verify space complexity, as I am creating ...
2
votes
1answer
45 views
Improving time complexity of cheapest travel route algorithm
Below is the code to find the cheapest route for a passenger. stationsUnexplored is a Queue to which stations are added and ...
5
votes
0answers
49 views
BiDirectional Dictionary (and its Mutable friend can come too)
I've attempted to implement a 1-to-1 dictionary in Objective-C. I'm probably missing some convenient methods that one might commonly want to use.
These are both declared in the same ...
2
votes
2answers
154 views
Is there some way of taking advantage of code reuse in this example?
I am implementing a set, using an array as the backend.
Here is how I declared it (and some method implementations):
...
3
votes
1answer
46 views
Disjoint-set data structure in Python 3
Inspired by this question, I decided to implement a Disjoint-set data structure in Python 3. I mainly followed this description for understanding the algorithm (but did not do the optimizations for ...
2
votes
2answers
112 views
Bag data structure (a set that can store multiple copies of items)
I am trying to make my class a bit cleaner, especially some of its methods like Count, __add__, ...
2
votes
4answers
78 views
Coupon collector
This is a coupon collector code to analyze the running time. I need some suggestions on improving the running times of this code. I have used the data structure dictionary, but is there any other data ...
4
votes
2answers
100 views
Inefficient hash map operation provokes OutOfMemory: Java heap space error
I know I can increase the size of the heap but that seems like a poor solution.
This program runs correctly on small files but when run on large data sets it crashes with the OutOfMemory: Java heap ...
2
votes
3answers
428 views
Finding duplicates in two sorted arrays
This is an interview question from here. Specifically, the second asked for a function that took in two sorted arrays of integers with no duplicate values within a single array and which returned an ...
5
votes
2answers
141 views
Data structure to count occurrences of entries
I would love to hear any thoughtful suggestions on how to improve my programming style in order to be more understandable.
Listed below is a sample of my code which I wrote in Eclipse:
...
4
votes
1answer
63 views
Design/reiterate or code reuse for linked list
This is what my class hierarchy looks like. I have an abstract superclass, AbstractLinkedMyList, that contains common operations for both sorted and unsorted linked ...
15
votes
1answer
264 views
Order a delicious pie here
For a quick summary: I've created this internal web application, and I've hit a point where I can really see the mess I've made. I need some help separating the logic, the view, and the data.
More ...
2
votes
1answer
63 views
Rewriting linked list function without a NULL variable
This is how my LinkedList class looks like in PHP. I am trying to figure out if I can rewrite my reverse_list_recursively() ...
3
votes
3answers
110 views
Implementing a singly LinkedList and IList interface
I have implemented a LinkedList in C#. What would you change/make better? What naming conventions are misused? What would you add? Some of my ideas are to make it ...
3
votes
1answer
67 views
Least common ancestor (LCA) in a binary tree
Find the LCA in binary tree, where a node is also its own ancestor.
This question is attributed to GeeksForGeeks. I'm looking for code review, optimizations and best practices.
...
3
votes
1answer
100 views
Finding the shortest substring containing keywords
Problem: Write a function that takes a String document and a String[] keywords and returns the smallest substring of ...
7
votes
4answers
494 views
Recursive binary search tree - follow-up
This is a follow-up to
Recursive binary search tree
changes:
Used raw pointers rather than std::unique_ptr
const correctness
Made variable names more beautiful
implemented at()
How can I improve ...
4
votes
3answers
507 views
Preorder, inorder, postorder for tree in C++11
Please review my code for preorder, inorder and postorder of a tree. I am using C++11 (or wanted to use), so let me know if anything is deviating from the C++11 standard.
...
1
vote
0answers
67 views
Hash Table Implemented by Javascript
I recently tried to implement a simple hash table using Javascript. Could anyone help me review my implementation?
...
2
votes
2answers
117 views
Counting a cycle
An interview question I got -
Each element of an int array points to the another element,
eventually creating a cycle. Starting at ...
4
votes
1answer
87 views
Circular linked list in C
Let me know if it seems right to you and if anything can be optimized. My concern is that I'm unsure if circular linked lists are supposed to have a tail. I've implemented it just using a head. Is ...
2
votes
2answers
84 views
Doubly linked list code in C
Let me know if it seems right to you and if anything can be optimized.
...
3
votes
1answer
97 views
Circular queue implementation using two regions
Inspired by the "bip buffer", I coded a fixed-size circular queue that uses two regions (two pairs of begin/end pointers) to account for the wrap-around.
The main goal of this design was to simplify ...
3
votes
0answers
75 views
Binary heap with O(1) lookup and O(log n) change key
I needed a priority queue that allowed efficient searching and changing of keys. I tried std::priority_queue, but the interface was extremely limiting. Not being ...
5
votes
2answers
144 views
Find if a word with wildcard exists in dictionary [closed]
This is a question from a phone interview I had.
The question was in 2 parts:
a. find("cat") -> T/F suggest a data structure to find is if a word
exists in a large dictionary, how will one node ...
8
votes
1answer
144 views
Networking in iOS Swift
This piece of code is working - It gives me a lot of JSON back, which I have yet to parse, but I'd like to show my code here first to get tips on how to improve what I already have:
...
2
votes
1answer
166 views
Graph implementation adjacency list 1.0
Please note the following:
All edges are directed
Removal of edges/nodges is not implemented yet
A user of the class Graph can never (hopefully) access a ...
5
votes
1answer
135 views
Find all the paths of tree that add to a input value
This code is attributed to Stack Overflow itself here. The path which adds to the sum, which need not be starting from the root, not be ending at the leaf, i.e. a path can be between root and a leaf.
...
6
votes
3answers
115 views
Removing duplicates without using a temporary buffer
This question is from Cracking the Coding Interview and in this question they have asked to solve without using temporary buffer.
I have used Iterator interface. Can I use it or need to re-implement ...