Binary search is an efficient algorithm for finding a key in sorted data. It runs in O(log n) time.
0
votes
0answers
13 views
alphanumerica binary search in node.js
I have some rather large arrays with hash values in them that looks like this: "ZjFhOTZjYzgtMmZhMy00YjdkLThmMDgtNjI4MjYxNTc3MGRlXw==ntyxntmzmzkw"
I've done a binary search, using the node.js ...
5
votes
2answers
58 views
Recursive binary search implementation in Python
I have this (recursive) binary search implementation in Python, and I want you to criticize every aspect of it. It is a naive implementation, (drilling the basics and stuff), but, I want you to ...
0
votes
1answer
38 views
Couting numbers greater than given - using binary search
It's my first exercise involving the well-known binary search. The problem goes as follows: we are given a sequence of n numbers and we have to answer to t questions, each of which is: “How many ...
3
votes
1answer
83 views
Python 2 binary search
I wanted to take a stab at implementing a binary search, and here's what I came up with. Is there anything I could have done better, from a code clarity perspective, or code optimization perspective? ...
-1
votes
1answer
43 views
Finding the minimum from a sorted rotated array with duplicates
Is this an efficient way of finding the minimum using binary search?
...
2
votes
2answers
107 views
Template Binary Search Tree
This is a simple binary search tree implementation written with C++'s templates feature I wrote to learn C++. What improvements would make this cleaner and better as far as C++ practices go, and are ...
2
votes
1answer
77 views
Find the number of quadraples (a,b,c,d) from 4 respective arrays such that a+b+c+d=0
Given four lists of numbers, calculate how many ways there are to
choose one element from each to get a sum of zero.
The input is given on stdin, first ...
-3
votes
3answers
222 views
Binary search algorithm
Would this recursive solution's speed be comparable to a non-recursive solution?
...
2
votes
0answers
364 views
Breadth and Depth First Search in Ruby
I was tasked with building three individual methods; one to create a Binary Search Tree (BST), one to carry out a Breadth First Search (BFS), and one to carry out a Depth First Search (DFS).
Create ...
2
votes
3answers
63 views
Locating a sequence in a sorted array
I read the following question: Searching an element in a sorted array and I thought that I could give it a try in Python.
Given a sorted list of integers and an integer. Return the (index) bounds ...
3
votes
1answer
60 views
Binary and linear search methods for a number-guessing game
This is a code written is Pascal (Delphi). It asks the user to think of a number between min_ and max_ and then guesses the ...
2
votes
1answer
83 views
Binary search function
I have written this function to perform a binary search on an array, given begin/end indices and a value to look for in the supplied array:
...
3
votes
2answers
72 views
Binary search attempt
I've heard about the binary search in an intro class I took a couple months ago, remembered how it worked and read this article, so I attempted to write my first binary search in Python. It works, but ...
1
vote
0answers
59 views
Variations on binary searching an ordered list
In the wikipedia article about the binary search algorithm (https://en.wikipedia.org/wiki/Binary_search_algorithm) a small paragraph in
particular got my attention.
Midpoint and width
A ...
5
votes
1answer
209 views
Find maximum element in bitonic array
An array is bitonic if it is composed of an increasing sequence of integers followed immediately by a decreasing sequence of integers. Write a program that, given a bitonic array of N distinct ...
5
votes
3answers
488 views
Recursive binary search in Python
I have implemented a recursive binary search in Python and tried to implement some verification to my code. Other than that, is there any optimization I am missing?
...
8
votes
3answers
715 views
Computer guesses the user's number
After the feedback for my last script, I realized I should be using functions and trying to adhere to the style guide. I tried to do that here, though still very beginner.
The rounding in Python ...
4
votes
1answer
126 views
Binary search implementation [closed]
Is there a better way to implement a binary search than I am in my code? My function is taking two two lists - first_booth_voters and ...
3
votes
1answer
49 views
Shell binary search with sorted input
I have coded binary search in shell, just for practice.
Input
Input data is already sorted set of numbers streamed to the script. $1 is the sought number.
...
2
votes
1answer
75 views
Efficiency of binary search and improvements
Below you can see my binary search method, and as a relatively new programmer I am looking for any suggestions on how it could be improved.
...
1
vote
2answers
212 views
Sorting an Integer array
The program sorts the array from lowest to highest and outputs the index of the searched value:
...
3
votes
1answer
75 views
Substring searching with Knuth–Morris–Pratt
My program uses the Knuth–Morris–Pratt algorithm to search for a particular substring in a .txt file and then store it in a binary search tree.
Note that ...
4
votes
3answers
212 views
Binary search tree implementation (with Node class)
I have implemented the Binary Search Tree in Java and would love to get reviews. I would like to have some comments on multi thread implantation.
Note: Corrected Code is in the Answers
...
3
votes
2answers
46 views
Binary search feedback and improvements
I implemented the binary search algorithm. Input vector is sorted by < than operator implemented by type T. The less than ...
4
votes
3answers
2k views
Recursive Level Order traversal
I have come up with this code to do level order traversal recursively for a binary search tree.
...
5
votes
4answers
5k views
Simple Binary Search Tree
At the moment I am learning algorithms and here I am trying to implement a simple binary search tree. I would like to know your suggestions on whether I am on the right track or not, and how this can ...
3
votes
2answers
142 views
Epilogue to a binary search to find the range of matching indexes
I am trying to find out the best practice for writing a loop which does one check and at the same time has to increment a value so that the while loop will ...
5
votes
1answer
159 views
Enter values, generate a list, and search
My assignment in school:
Read in names to sort until the user types the “enter” key
After sorting and displaying the array of strings
Do a binary search to find if the string is in the array
If the ...
7
votes
2answers
958 views
Quack - the revolutionary new data structure
I was having a chat with a friend about data structures (as you do), and that, and his love of portmanteaus meant that he came up with a Quack - A queue and a ...
4
votes
0answers
139 views
Persistent segment tree
I'm trying to solve this problem.
Given a sequence \$B=B_0,B_1,\ldots,B_{N−1}\$
for each query \$(P,K)\$, find the minimum \$S\$
s.t. there are at least \$K\$ entries in \$B\$ that satisfies
...
2
votes
1answer
231 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 ...
4
votes
2answers
186 views
Binary search that returns bitwise complement of missing index
While re-writing some old JavaScript code to better handle large arrays, I ended up writing my own binary search method.
I found many examples of binary search methods written in JavaScript, but all ...
4
votes
1answer
216 views
Find string in sorted array with interspersed empty strings
(from McDowell) Given a sorted array of strings which is interspersed with empty strings, find the location of a given string.
eg. "ball" in
...
1
vote
1answer
100 views
Find the peak element using BS
A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.
The array may contain multiple peaks, in that ...
2
votes
0answers
51 views
Basic Binary Tree in Go
As an exercise I have written a basic binary tree implementation in Go.
Tree struct:
...
1
vote
2answers
396 views
Simple peak finder solution - O(log n)
I attempted a solution to a seemingly simple problem:
Peak Finder
Let input be a list. input[i] is a peak if ...
11
votes
3answers
168 views
Karate Chop Kata
I had some time to kill today, and I found the Karate Chop Kata.
Specification:
Write a binary chop method that takes an integer search target and a sorted array of integers. It should ...
1
vote
1answer
476 views
Binary search using recursion, iteration, shifted array
Interview question some engineer, asked me to write binary search in 2 ways,
Also asked me to write binary search on a shifted array (10 20 1 2 3 4).
Wrote that and then asked me to find the offset ...
1
vote
1answer
39 views
insertBST exercise
I'm just learning Haskell on my own, and did an exercise to implement insertBST.
Is this idiomatic Haskell?
...
7
votes
1answer
1k views
Excel VBA binary search class module [closed]
I have a long list of sorted strings in a Workbook, and I have to find a lot of values in it. I was hoping to build a binary search Class Module that will find them for me faster than Excel's built-in ...
2
votes
1answer
89 views
Binary Search in C
The standard C library function bsearch wasn't giving me correct results, apparently. So I decided to implement a binary searching function in place of it. It ...
5
votes
2answers
939 views
Binary Search Tree in Ruby
Binary Search Tree, with preorder traverse. What other methods should I add? How can I improve it?
...
2
votes
0answers
66 views
Mini Binary Tree “library”
This is my first attempt at learning binary trees. I'm looking for general feedback on how it could be made cleaner, more idiomatic, or more efficient.
...
3
votes
2answers
2k views
Read binary file by blocks
I wrote a function that allow me to read a binary file using 3 blocks what ever the length of file.
I've decided to divide the length of my file into 3:
block 1: ______________
block 2: ...
3
votes
0answers
78 views
BST remove implementation
As practise, I implemented a BST and also the remove() method, but I figured I always have to check if the node being deleted is coming from the left child or the ...
4
votes
3answers
6k views
Binary search tree with tree traversal
Although there are several implementations of binary search tree, I have made my own implementation for practice. The following code does the followoing operation
- Create a binary tree
- search ...
6
votes
2answers
219 views
UniqueList Class in VBA
I often find myself abusing dictionary objects just for the exist method like this,
...
1
vote
2answers
274 views
Binary search as a generic algorithm
I am upgrading my C++11 knowledge and repeating some essential algorithm. Here is binary search only in terms of iterators.
...
5
votes
2answers
608 views
Binary search: first/last/random occurrence
I've written some code to "binary search" a list, and return the first occurrence of the target:
...
7
votes
1answer
959 views