quiz حل الأسئلة الجامعية manage_search الأرشيف

تم الحل ✓
categoryهندسة الحاسبات schoolبكالوريوس event_available2026-07-15

السؤال

Transcribed Image Text:

Question 2: (40 Marks) There are some people standing in a circle. You are given their heights in an array 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: (refer to the figure below) A={175,166,184,170,187,167) Output: 2244-10 Example 2: A={174,180,184,160,177} Output: 12-14 1 Explanation of example 1: The given array A[] of heights is as follows: A[index] A[0] A[1] A[2] A[3] A[4] A[5] Content 175 166 184 170 187 167 The lady 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. Input: A[] (175, 166, 184, 170, 187, 167} To the right Output: 2 2 4 4 -10 To the right a) Describe how a brute-force approach algorithm would solve the above problem (6 marks), and explain its complexity (4 marks). b) Design a more efficient algorithm to solve this problem. (10 marks) [The efficiency of your algorithm is the main driver of the mark], and analyze the complexity of your solution. (4 marks) [full explanation of your answer should be provided] c) Develop a python code to implement your efficient algorithm. (10 marks) [The marks depend on the correctness of the code, indentation, comments, test-case] d) Prepare a brief report (250 words) comparing the two algorithms (6 marks)

check_circle الجواب — حل مفصل خطوة بخطوة

hourglass_top