


"""simple docstring"""






# Author: OMKAR PATHAK, Nwachukwu Chidiebere

# Use a Python dictionary to construct the graph.
from __future__ import annotations

from pprint import pformat
from typing import Generic, TypeVar

UpperCAmelCase    :     Tuple   						=		TypeVar('T')





class      lowerCamelCase__   (     Generic[T]				):







					"""simple docstring"""


					def __init__(       self    : int ,       UpperCamelCase    : bool = True  ):
												'''simple docstring'''






												__UpperCAmelCase   :						dict[T, list[T]]      							=					{}  # dictionary of lists
												__UpperCAmelCase   :						Optional[int]      							=					directed






					def lowerCamelCase__							(       self    : Any ,       UpperCamelCase    : T ,       UpperCamelCase    : T  ):
												'''simple docstring'''






												if not self.directed:  # For undirected graphs
																			# if both source vertex and destination vertex are both present in the
																			# adjacency list, add destination vertex to source vertex list of adjacent
																			# vertices and add source vertex to destination vertex list of adjacent
																			# vertices.
																			if source_vertex in self.adj_list and destination_vertex in self.adj_list:
																										self.adj_list[source_vertex].append(UpperCamelCase  )
																										self.adj_list[destination_vertex].append(UpperCamelCase  )
																			# if only source vertex is present in adjacency list, add destination vertex
																			# to source vertex list of adjacent vertices, then create a new vertex with
																			# destination vertex as key and assign a list containing the source vertex
																			# as it's first adjacent vertex.
																			elif source_vertex in self.adj_list:
																										self.adj_list[source_vertex].append(UpperCamelCase  )
																										__UpperCAmelCase   :						int      							=					[source_vertex]
																			# if only destination vertex is present in adjacency list, add source vertex
																			# to destination vertex list of adjacent vertices, then create a new vertex
																			# with source vertex as key and assign a list containing the source vertex
																			# as it's first adjacent vertex.
																			elif destination_vertex in self.adj_list:
																										self.adj_list[destination_vertex].append(UpperCamelCase  )
																										__UpperCAmelCase   :						int      							=					[destination_vertex]
																			# if both source vertex and destination vertex are not present in adjacency
																			# list, create a new vertex with source vertex as key and assign a list
																			# containing the destination vertex as it's first adjacent vertex also
																			# create a new vertex with destination vertex as key and assign a list
																			# containing the source vertex as it's first adjacent vertex.
																			else:
																										__UpperCAmelCase   :						List[str]      							=					[destination_vertex]
																										__UpperCAmelCase   :						List[Any]      							=					[source_vertex]
												else:  # For directed graphs
																			# if both source vertex and destination vertex are present in adjacency
																			# list, add destination vertex to source vertex list of adjacent vertices.
																			if source_vertex in self.adj_list and destination_vertex in self.adj_list:
																										self.adj_list[source_vertex].append(UpperCamelCase  )
																			# if only source vertex is present in adjacency list, add destination
																			# vertex to source vertex list of adjacent vertices and create a new vertex
																			# with destination vertex as key, which has no adjacent vertex
																			elif source_vertex in self.adj_list:
																										self.adj_list[source_vertex].append(UpperCamelCase  )
																										__UpperCAmelCase   :						List[Any]      							=					[]
																			# if only destination vertex is present in adjacency list, create a new
																			# vertex with source vertex as key and assign a list containing destination
																			# vertex as first adjacent vertex
																			elif destination_vertex in self.adj_list:
																										__UpperCAmelCase   :						int      							=					[destination_vertex]
																			# if both source vertex and destination vertex are not present in adjacency
																			# list, create a new vertex with source vertex as key and a list containing
																			# destination vertex as it's first adjacent vertex. Then create a new vertex
																			# with destination vertex as key, which has no adjacent vertex
																			else:
																										__UpperCAmelCase   :						str      							=					[destination_vertex]
																										__UpperCAmelCase   :						List[str]      							=					[]

												return self






					def __repr__(       self    : Dict  ):
												'''simple docstring'''






												return pformat(self.adj_list  )




"""simple docstring"""






from collections.abc import Callable
def      lowerCamelCase       (     _UpperCamelCase		:      Callable[[float], float]       ,			_UpperCamelCase		:      float       ,			_UpperCamelCase		:      float							)		->       float:

							'''simple docstring'''



							__UpperCAmelCase   :						float      							=					a
							__UpperCAmelCase   :						float      							=					b
							if function(_UpperCamelCase							) == 0:  # one of the a or b is a root for the function
														return a
							elif function(_UpperCamelCase							) == 0:
														return b
							elif (
							    function(_UpperCamelCase							) * function(_UpperCamelCase							) > 0
							):  # if none of these are root and they are both positive or negative,
														# then this algorithm can't find the root
														raise ValueError("""could not find root in given interval."""							)
							else:
														__UpperCAmelCase   :						float      							=					start + (end - start) / 2.0
														while abs(start - mid							) > 1_0**-7:  # until precisely equals to 10^-7
																					if function(_UpperCamelCase							) == 0:
																												return mid
																					elif function(_UpperCamelCase							) * function(_UpperCamelCase							) < 0:
																												__UpperCAmelCase   :						Union[str, Any]      							=					mid
																					else:
																												__UpperCAmelCase   :						List[Any]      							=					mid
																					__UpperCAmelCase   :						Optional[Any]      							=					start + (end - start) / 2.0
														return mid
def      lowerCamelCase       (     _UpperCamelCase		:      float							)		->       float:

							'''simple docstring'''



							return x**3 - 2 * x - 5


if __name__ == "__main__":
							print(bisection(f, 1, 1000))

							import doctest

							doctest.testmod()
