Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 4, Problem 42C

Explanation of Solution

Algorithm:

findMax(Array A, size n>0):

    max=A[0]

    for i in 1 to n (inclusive)

    if(A[i] > max)

        max=A[i]

    return max

Explanation:

The above algorithm uses a binary tree where every node keeps track of the maximum and minimum for the sub tree starting with that node.

Let us consider the three types as the following implementation to prove the maximum and minimum of “n” numbers. Type-1 contains less than “3n/2” comparisons, type-2 contains “n/2 ” nodes that have leaves as children, and type-3 contains less than “n/2” nodes where a least one of the children aren't leaves.

  • First, start with the type 2 nodes, and compare the two leaves. This requires a maximum of “n/2” comparisons. If there are an odd number of type 1 nodes, the last node is promoted to type 2 and only it uses (n1)/2 comparisons.
  • Now there are “n/2 ” or “(n 1)/2 + 1 ”type 2 nodes.
  • Let us take “m” be the number of nodes and keep pairing the nodes until only one node is left. In each iteration, it requires two comparisons while pairing two nodes

Blurred answer
Students have asked these similar questions
Computer programs can be very complex, containing thousands (or millions) of lines of code and performing millions of operations per second. Given this, how can we possibly know that a particular computer program's results are correct? Do some research on this topic then think carefully about your response. Also, explain how YOU would approach testing a large problem. Your answer must be thoughtful and give some insight into why you believe your steps would be helpful when testing a large program.
Could you fix this? My marker has commented, What's missing? The input list is the link below.  https://gmierzwinski.github.io/bishops/cs321/resources/CS321_Assignment_1_Input.txt     result.put(true, dishwasherSum);        result.put(false, sinkSum);        return result;    }}
PLEG136: Week 5 Portofolio Project Motion to Compel

Chapter 4 Solutions

Data Structures and Algorithms in Java

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT