All Questions
54 questions
2
votes
1
answer
76
views
A search function that searches for a contact inside a vector [closed]
I have this function to search for a specific contact inside a contact management program. I want to know the following:
Is returning the contact object as a pointer(...
2
votes
1
answer
84
views
Speed up searching for the lowest element that is not in the array
I try to solve this question: B. Informatics in MAC at Codeforces
To solve it, I think I need to calculate the prefix and suffix array of MEX. I made observation that making only 1 subsegment will ...
3
votes
1
answer
99
views
Fast search for the longest repeating substrings in large text (Rev.4)
This is the forth iteration of the Fast search for the longest repeating substrings in large text (Rev.3) code review. Special thanks goes to G. Sliepen who conducted all the reviews.
Functional ...
3
votes
1
answer
136
views
Incremental upper bound in sorted range
Since initial question Increasing binary search for mismatch in sorted range contained defects in code and can confuse the readers, here is the updated version of the question.
Is the code below ...
2
votes
1
answer
136
views
Fast search for the longest repeating substrings in large text (Rev.3)
This is the third iteration of the Fast search for the longest repeating substrings in large text (Rev.2) code review. Special thanks goes to G. Sliepen who conducted the first two reviews.
Functional ...
2
votes
1
answer
108
views
Fast search for the longest repeating substrings in large text (Rev.2)
This is the second iteration of the Fast search for the longest repeating substrings in large text code review. Special thanks goes to G. Sliepen who conducted the first review.
Functional ...
3
votes
1
answer
196
views
Fast search for the longest repeating substrings in large text
Is there a chance to implement the code below better with the features of recent C++ versions?
Functional specification
Having a large text and already built prefix array find the longest substrings (...
4
votes
2
answers
488
views
Spatial radius search in Boid simulation
I am working on a Boid simulation with 10,000 boids. I've successfully utilized geometry shaders and an array<GLfloat[3], MAX_BOIDS> for vertices to enhance ...
7
votes
2
answers
496
views
Copy file with text replacement
I am currently learning C++. I coded a tiny program for school and I wonder if there could be issues (like bugs or security issues) with it.
Any ways to make it have weird behaviours would be very ...
6
votes
4
answers
952
views
Counting the number of patterns that exist in a particular string
I am solving this problem where the function returns the number of times a pattern is found in a said string word. It could be easily solved via ...
1
vote
1
answer
642
views
Sort and search vectors by different criteria
Class
class Player {
std::string name;
int score;
int id;
};
I thought about how to write a code to sort and search vector ...
7
votes
6
answers
4k
views
C++ implementation of depth-first search
I got the C++ implementation of depth-first search (DFS) from here and made slight modifications to it. The modified code is as follows:
...
1
vote
1
answer
105
views
Check if is it possible to get to a point that is presented by a number [closed]
Problem description from an Iranian online course, translated with the help of Google Translate:
Tired of coding, Mehdi has gone on to his childhood games. But because he doesn't know who to play ...
1
vote
1
answer
155
views
Inventory system codebase
I'm here looking for a review over my current code-base.
Please:
Ignore using namespace std; this is for educational purposes mostly so the usage of using namespace std; does not matter for this ...
8
votes
3
answers
2k
views
Java TreeMap.floorKey() equivalent for std::map
I wanted something equivalent to this Java program:
...
4
votes
1
answer
492
views
Filter for CANbus frames
The actual data types here are probably not relevant to post an answer. I use Qt types here, but the question should apply for other structured types as well.
I ...
4
votes
1
answer
627
views
Knuth-Morris-Pratt algorithm in C++
First of all, I know there is huge amount of information about KMP on the internet but many examples are just the code without any explanation. So I've decided to implement it on my own.
Secondly, I ...
4
votes
0
answers
70
views
Array Search Algorithm
Recently, I've been experimenting with an array searching algorithm that I'm not sure I've seen anywhere (minor references here).
I'm still not fully-learned on how to state the efficiency of what I'...
3
votes
1
answer
407
views
Search for rows in a 2D array that contain a given sequence
I have a 2d array of m * n dimension (m and n can vary from 1 to 100000). The following snippet of code checks if the sequence exists in the row and stores the index if it exists. The time taken by ...
3
votes
3
answers
3k
views
Insertion of a node in M-way search tree
I am currently studying data structures and i am looking to see if my implementation of the insertion method in an M-way search tree is good and i am looking forward to improving my coding approach.
...
2
votes
0
answers
2k
views
C++ implementation of Monte Carlo Tree Search with Python wrapper
Important
Prebuilt Python Extensions built for Python 3.6
Includes Python f-strings (3.6+)
Complementary GitHub link
https://github.com/thejhonnyguy/CPyMCTS
Notable: Previous attempt with stock ...
4
votes
1
answer
188
views
Filling a string at minimal cost
I'm solving the following problem. Here is the problem statement:
You are given a string with wildcards, e.g. X***Y*Z. Your goal is to print an input string ...
3
votes
2
answers
250
views
Variadic function to find the first matching (string) argument in a larger array
Playing around with parsing a data buffer I wrote a small search function to find the first complete match out of a set of (string) arguments.
The (simplified) buffer class with the find function:
<...
3
votes
1
answer
113
views
Slow execution time of search algorithm
I have solved a problem of a game named 'Set'.
The full problem is detailed on it's website: https://www.urionlinejudge.com.br/judge/en/problems/view/1090
However my code for the search algorithm is ...
-2
votes
1
answer
106
views
Search function for a trie tree
I have made a search function that seems to work for passing the tester. I am just unsure if it will always be without errors. Can someone tell me if they see any flaws in the logic, and if so, where ...
2
votes
1
answer
81
views
Finding a path across a grid after randomly filling some proportion of it
Essentially, we must be able to get from one side of the grid to the opposite side of the grid. My code tests for up to down and left to right.
However, this is painfully slow and I'm wondering if ...
1
vote
1
answer
3k
views
Search function for books
I was making a library program for trying to practice C++. I wanted to use a vector to store all the books, the books being a struct to hold the general things the books would have.
...
0
votes
1
answer
95
views
Sentinel based find with conditional fallback to std::find
I've got bored, so I decided to write a code using ancient knowledge of sentinels.
Sentinel based find
Basically what we do is put value that is needed to find at the end, and then write an endless ...
3
votes
1
answer
2k
views
Detect if string contains more than 1 period
This function returns true if the string contains zero or one periods, and returns false if the string contains more than one ...
9
votes
2
answers
1k
views
Exponential search
I recently discovered the exponential search algorithm which can be used to find whether a value exists in an ordered range. An exponential search checks whether a value is smaller than the \$2^n\$th ...
-3
votes
1
answer
3k
views
Mapping phone numbers to names [closed]
Problem description:
You are given a phone book that consists of your friend's names and
their phone number. After that you will be given your friend's name
as query. For each query, print the ...
5
votes
1
answer
862
views
Search file for keyword program
Just looking for some advice and I know using std namespace is bad but I didnt have the time to do all the using stuff. I want help on what here is good and what is bad practice :).
...
3
votes
1
answer
351
views
Finding nearest float values corresponding to a data point (of three variables) in a table with multiple columns using C++
I have a data file which contains floating point data arranged in 4 columns. Each row represent a specific data point. The first column(X) is made up of 100 different values but the values are ...
6
votes
1
answer
126
views
Bash command helper in C++
I'm writing a program to help with remembering complex bash commands. On invoking the program, it asks for a description of the desired operation, e.g., "increase volume" or "find orphaned packages", ...
1
vote
1
answer
178
views
Array search algorithms: performance comparison
I'm making a program that compares multi-key sequential search and Interpolation search in a sorted array by the number of array accesses for my assignment.
...
9
votes
1
answer
433
views
Trinary Search Tree
I'm probably not the first to think this up, but here we go. An trinary search tree is a generalization of a binary search tree in the sense that instead of a comparison function returning true or ...
2
votes
2
answers
2k
views
Breadth-First Search heuristics to find solution to Water Jug Challenge
I started learning AI recently. In AI, searches should be avoided and everything in AI is a search problem.
One of the easiest problem where we could use general AI search techniques is the water jug ...
6
votes
2
answers
1k
views
Contact search application
Create a C++ program which will act like contact search app in mobile.
For example, if the following contacts are saved in contact list:
Massi
Pradip
Prasad
Praveed
Raju
...
2
votes
3
answers
611
views
Searching a string of consecutive characters in a binary bar code
I am writing a program that will take a binary bar code and convert it to a zip-code. I need to validate the bar code. A valid binary bar code contains no more and no less than two 1s in any position ...
4
votes
2
answers
102
views
Search key in a rotated sorted array without repetition of elements
Is there any improvement possible in this implementation?
...
4
votes
1
answer
527
views
Optimizing variadic template pack subsequence matching algorithm
I'm building a small MPL module in one of my utility libraries for fun and learning experience.
One of the problems I'm trying to solve is getting a list of all indices where a sequence of types ...
4
votes
1
answer
557
views
Test if two nodes in a binary search tree are cousins
Cousins are nodes at the same level of the tree, with different parents.
They don't have to share the same grandparent.
My solution depends on having a binary search tree with unique elements.
This ...
12
votes
4
answers
8k
views
strstr() implementation
In this strstr implementation, I am basically skipping the already matched and checked characters with an if else condition. Is ...
3
votes
2
answers
7k
views
How to search for a word in a sorted text file efficiently?
I want to write my own program to search for a word in a sorted text file. In the text file each word is in one line. I want to write this myself because I did not find any simple program (without ...
3
votes
2
answers
4k
views
Searching and comparing a record
I am still a beginner in C++ and I am always curious about good/best coding methods.
Let's say I have a program which allows a users to edit the salary of a employee.
The system will prompt the user ...
6
votes
3
answers
176
views
6
votes
3
answers
2k
views
Improving speed of word search algorithm
I've been working on this word search algorithm and had some issues about its speed. It kinda looks like it takes a little too much time.
If anyone could offer suggestions on making this better and ...
6
votes
1
answer
658
views
Is this implementation of binary search correct?
Is this implementation of binary search correct? Any special or edge cases that I missed out? Maybe it should be optimized for elements that are less than the first element of the array or greater ...
6
votes
1
answer
208
views
Randomizing and mutating algo class - functionality
See Randomizing and mutating algo class - style
I'm looking for a review of the functionality of this code, answers to the above question which also describes the code use focus on style instead.
...
5
votes
2
answers
319
views
Randomizing and mutating algo class - style
I've updated this question to be about code style only, as all of it's answered focused on this aspect. For the codes function, see Randomizing and mutating algo class - functionality
...