# Tagged Questions

Binary search is an efficient algorithm for finding a key in sorted data. It runs in O(log n) time.

69 views

### Making a sorted linked list into a balanced binary search tree

My code works, but I need help on revising it to make it shorter and simple if possible on my main.cpp part ONLY. The other files is to make the program compile and work out if you want to see the ...
76 views

### Calculate the path sum of a binary tree

I want to calculate all sum of all possible paths from root to leaf. Each node has value of an integer number (decimal). In the following example: ...
98 views

### Finding the frequency of an element in a sorted list of integers

Input: Array of sorted integers and an element to check the frequency for Output: Frequency of the element ...
723 views

### Binary search in C#

The challenge requires the program to receive data from the console and use binary search to find if a term is contained in a set of other terms. I've unit-tested the solution below, but according to ...
49 views

### Deletion of a node in a binary search tree

I am looking to see if my implementation of the removal/deletion method in a binary search tree is sufficient, readable, and runs in $O(\log n)$ time. It's been awhile since I've written a data ...
53 views

### Binary search tree class in Java

I am trying to create a binary search tree class in Java and am wondering how I did. I am fairly confident on most of the methods, but fear I may have messed up the delete method. I know I am ...
61 views

### Maximum clique using binary matrix adjacency [closed]

I'm solve the maximum clique problem. I'm using binary matrix adjacency to represent the graph. But when I test using the DIMACS-benchmark, my answer is far more different compared to the answer given....
287 views

### Find median of two sorted arrays

Problem statement There are two sorted arrays nums1 and nums2 of size m and ...
215 views

### Priority Queue (Binary Search Tree) Implementation

I have made a Priority Queue implemented as a Binary Search Tree. I would appreciate comments related to optimization and proper functionality, but any comments/critiques are welcome. PQ.h: ...
38 views

### Binary search tree and breadth first search

I have written code to implement Binary Search and Breadth First Search in JS. Please review my code. I want to ensure Im following the best practices. Node.js ...
88 views

### Minimum element in a sorted rotated array

A sorted array [0,1,2,3,4,5] when rotated n times (3 times in this case) becomes [3,4,5,0,1,2], meaning elements in the front move to the end. The code below finds the minimum element in this array, ...
17 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 ...
68 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 ...
45 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 ...
90 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? ...
52 views

### Finding the minimum from a sorted rotated array with duplicates

Is this an efficient way of finding the minimum using binary search? ...
126 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 ...
81 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 the ...
249 views

### Binary search algorithm

Would this recursive solution's speed be comparable to a non-recursive solution? ...
967 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 ...
64 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 of ...
68 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 ...
91 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: ...
75 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 ...
86 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 ...
299 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 integer ...
919 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? ...
732 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 ...
127 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 ...
52 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. ...
76 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. ...
238 views

### Sorting an Integer array

The program sorts the array from lowest to highest and outputs the index of the searched value: ...
84 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 ...
262 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 ...
48 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 ...
3k views

### Recursive Level Order traversal

I have come up with this code to do level order traversal recursively for a binary search tree. ...
11k 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 ...
159 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 ...
184 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 ...
984 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 stack,...
170 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 ...
279 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 ...
194 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 ...
303 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 ...
104 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 ...
53 views

### Basic Binary Tree in Go

As an exercise I have written a basic binary tree implementation in Go. Tree struct: ...
555 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 ...
174 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 ...