A bipartite graph is a graph G=( ,E) such that the set can be partitioned into t
ID: 3925457 • Letter: A
Question
A bipartite graph is a graph G=( ,E) such that the set can be partitioned into two (disjoint) sets and ( = ) where every edge in the graph is between a node a and a node in . A complete bipartite graph is a bipartite graph where every node in is connected to every node in . Based on a graph traversal technique, write an algorithm that takes as input an undirected graph G, and returns whether or not G is a complete bipartite; if G is complete bipartite, the algorithm should also return and . Analyze the time complexity of your algorithm.
Explanation / Answer
iven an array ''A'' of ''n'' elements with values or [[Record (computer science)|records]] ''A''<sub>0</sub> ... ''A''<sub>''n''1</sub>, sorted such that ''A''<sub>0</sub> ≤ ... ≤ ''A''<sub>''n''1</sub>, and target value ''T'', the following [[subroutine]] uses binary search to find the index of ''T'' in ''A''.{{Sfn|Knuth|1998|loc=§6.2.1 ("Searching an ordered table"), subsection "Algorithm B"}}
# Set ''L'' to 0 and ''R'' to ''n'' − 1.
# If ''L'' > ''R'', the search terminates as unsuccessful.
# Set ''m'' (the position of the middle element) to the [[Floor and ceiling functions|floor]] of (''L'' + ''R'') / 2.
# If A<sub>''m''</sub> < ''T'', set L to ''m'' + 1 and go to step 2.
# If A<sub>''m''</sub> > T, set R to ''m'' – 1 and go to step 2.
# Now A<sub>''m''</sub> = ''T'', the search is done; return ''m''.
This iterative procedure keeps track of the search boundaries via two variables. Some implementations may place the comparison for equality at the end of the algorithm, resulting in a faster comparison loop but costing one more iteration on average.<ref name="bottenbruch">{{cite journal | title=Structure and Use of ALGOL 60 | author=Bottenbruch, Hermann | journal=[[Journal of the ACM]] | year=1962 | volume=9 | issue=2 | pages=161–211}} Procedure is described at p. 214 (§43), titled "Program for Binary Search".</ref>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.