Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Use OUBUILD Or Scratch and Simple algorithm as following is required : Design an algorithm to solve this problem by using loop and if

Please Use OUBUILD Or Scratch and Simple algorithm as following is required :

Design an algorithm to solve this problem by using loop and if statement with providing full comments on the code. According to the complexity which is covered in the TM111 chapter 6 you should make your algorithm efficient. 2- Explain the mechanism of your algorithm by your own words. 3- Does your algorithm efficient or not (explain based on your answer)?

The Question is :

There are some people standing in a circle. You are given their heights in an a list of A[].It is required for each one to print the index of the first person taller than him on his right (print -1 if no one is taller than him). Example 1 : List =[175,166,184,170,187,167] Output : 2 2 4 4 -1 0 Example 2: List =[174,180,184,160,177] Output : 1 2 -1 4 1

image text in transcribed

Explanation of example 1: The given list A[] of heights is as follows: A[index] A[O] A[1] A[2] A[3] A[4] A[5] Content 175 166 184 170 187 167 The person at the starting point of the circle has a height 175. The first person taller than her on her right is 184 (i.e., A[2]). As It is required for each one to print the index of the first person taller than him on his right, 2 is printed. The second one with height 166 has also the same person on her right. Therefore 2 is printed again ... and so on 167 187 Input list=[175,166,184,170,187,167] 177 170 166 to right 184 output 2244-10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

What is Indian Polity and Governance ?

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago