Questions tagged [bisection]

Anything related to a class of algorithms where the result is found by searching either the upper or the lower half of a sorted set of items and repeating this procedure recursively. Commonly used to refer to the bisection method (to find a root of an equation) or to the bisection search algorithm (to search a sorted list for a matching element).

Anything related to a class of algorithms where the result is found by searching either the upper or the lower half of a sorted set of items and repeating this procedure recursively, narrowing the search at each step.

Two common examples of bisection algorithms are:

233 questions
188
votes
21 answers

Binary search (bisection) in Python

Is there a library function that performs binary search on a list/tuple and return the position of the item if found and 'False' (-1, None, etc.) if not? I found the functions bisect_left/right in the bisect module, but they still return a position…
rslite
  • 73,388
  • 4
  • 40
  • 45
30
votes
3 answers

In Python, how do you find the index of the first value greater than a threshold in a sorted list?

In Python, how do you find the index of the first value greater than a threshold in a sorted list? I can think of several ways of doing this (linear search, hand-written dichotomy,..), but I'm looking for a clean an reasonably efficient way of doing…
static_rtti
  • 46,349
  • 44
  • 123
  • 180
11
votes
1 answer

Bisect a Python List and finding the Index

When I use the bisect_left() function, why do I not get the index of the element, but instead index + 1? import bisect t3 = ['carver', 'carvers', 'carves', 'carving', 'carvings'] print bisect.bisect(t3, 'carves') # 3 print bisect.bisect(t3,…
Nyxynyx
  • 52,075
  • 130
  • 401
  • 707
10
votes
2 answers

Solving equation using bisection method

Is there a bisection method I can find online, specifically for python? For example, given these equations how can I solve them using the bisection method? x^3 = 9 3 * x^3 + x^2 = x + 5 cos^2x + 6 = x
bbnn
  • 3,114
  • 8
  • 46
  • 64
10
votes
3 answers

Fast block placement algorithm, advice needed?

I need to emulate the window placement strategy of the Fluxbox window manager. As a rough guide, visualize randomly sized windows filling up the screen one at a time, where the rough size of each results in an average of 80 windows on screen without…
James Morris
  • 4,651
  • 3
  • 27
  • 49
9
votes
7 answers

How to do the Bisection method in Python

I want to make a Python program that will run a bisection method to determine the root of: f(x) = -26 + 85x - 91x2 +44x3 -8x4 + x5 The Bisection method is a numerical method for estimating the roots of a polynomial f(x). Are there any available…
Scrubatpython
  • 103
  • 2
  • 2
  • 6
8
votes
2 answers

Multi-threaded bisection search

Suppose that I have some computable predicate, P, that maps integers to bools. I know that P 0 is true and I know some N such that P N is false. I also know that P n = false implies that P (n + 1) is false [*]. I want to find the maximum n such that…
Rupert Swarbrick
  • 2,681
  • 13
  • 25
8
votes
3 answers

Find where f(x) changes in a list, with bisection (in Python)

Reasoning: I'm trying to implement, in Python, something similar to git bisect, but with basically a list of directories. I have a (long) list of version numbers like this: ['1.0', '1.14', '2.3', '3.1', '4'] I have a function works() which takes a…
Daniel
  • 1,841
  • 5
  • 19
  • 24
8
votes
6 answers

Multivariate Bisection Method

I need an algorithm to perform a 2D bisection method for solving a 2x2 non-linear problem. Example: two equations f(x,y)=0 and g(x,y)=0 which I want to solve somultaneously. I have very familiar with the 1D bisection ( as well as other numerical…
7
votes
1 answer

Input equation in bisection method, C++

I have this code: #include #include #include using namespace std; double f(double x); double biseccion(double a, double b, double tolerancia, int maxiter); int main() { double a, b, raiz; double…
Ashir
  • 511
  • 2
  • 8
  • 23
6
votes
3 answers

How to pair (x,y) pairs using numpy

I have 2, 2D NumPy arrays consisting of ~300,000 (x,y) pairs each. Given the ith (x, y) pair in array A, I need to find the corresponding jth (x,y) pair in array B such that ([xi - xj]2 + [yi - yj]2)½, the distance between the two (x,y) pairs, is…
5
votes
1 answer

Why does python's bisect_left return a valid index even if the value does not exist?

I want to find if a number exists in a sorted array. To be straight an array contains fibonaccci number from 1 to 63. Below is the fibonacci number generator and some of it's output. stacksize = 10000 # default 128 stack from functools import…
user6573621
5
votes
1 answer

calculate midpoint

Why in the bisection method it is better to compute the midpoint c between a and b with c = a + (b - a) / 2. instead of the simpler: c = (a + b) / 2. all variables are floating points.
Ruggero Turra
  • 14,523
  • 14
  • 72
  • 123
5
votes
3 answers

Get closest element from list of dictionaries

My program generates the following list (excerpt): my_list = [{'x': 1764, 'y': 18320, 'class': 'note', 'id': 'd1e2443'}, {'x': 1764, 'y': 20030, 'class': 'note', 'id': 'd1e2591'}, {'x': 1807, 'y': 12650, 'class': 'note', 'id':…
sonovice
  • 648
  • 1
  • 10
  • 21
5
votes
3 answers

efficient algorithms with array of increasing integers

I've been self teaching myself data structures in python and don't know if I'm overthinking (or underthinking!) the following question: My goal is come up with an efficient algorithm With the algorithm, my goal is to determine whether an integer i…
WycG
  • 141
  • 1
  • 5
1
2 3
15 16