Q1: given N numbers in pl,p2,p3...pn, we would like to sort these number. The only process we can do is moving the first number in the list k spaces down the line. For example, suppose that N=4 and the numbers start off in the following order: 4, 3, 2, 1 The only number can be moved at this point is 4, If we instructs number 4 to move 2 spaces down the line, the order will subsequently look like this: 3, 2, 4, 1 Now the only number can be moved is 3, so in the second time step we may give number 3 an instruction, and so forth until the list of numbers are sorted. Find the minimum number of time steps required to sort these numbers. INPUT FORMAT: The first line of input contains N, The second line contains N space-separated integers, pl,p2,p3.pn, indicating the starting order of these numbers. OUTPUT FORMAT A single integer: the number of time steps before the N numbers are in sorted order, if we acts optimally. SAMPLE INPUT 1: 4 1 2 4 3 SAMPLE OUTPUT 1: 3 SAMPLE INPUT 2: 60 35 50 4 39 54 32 20 53 29 1ô 55 28 40 44 48 25 21 5 9 14 33 3 16 38 31 23 15 60 27 49 11 51 46 52 30 45 1 6 36 43 24 7 58 56 42 2 8 10 12 13 17 19 22 26 34 37 41 47 57 59 SAMPLE OUTPUT 2: 45 SAMPLE INPUT 3: 70 23 16 69 53 51 65 70 29 5 41 62 25 13 21 3 22 68 28 1 2 4 6 7 8 9 10 11 12 14 15 17 18 19 20 24 26 27 30 31 32 33 34 35 36 37 38 39 40 42 43 44 45 46 47 48 49 50 52 54 55 56 57 58 59 60 61 63 64 66 67 SAMPLE OUTPUT 3: 18
Q1: given N numbers in pl,p2,p3...pn, we would like to sort these number. The only process we can do is moving the first number in the list k spaces down the line. For example, suppose that N=4 and the numbers start off in the following order: 4, 3, 2, 1 The only number can be moved at this point is 4, If we instructs number 4 to move 2 spaces down the line, the order will subsequently look like this: 3, 2, 4, 1 Now the only number can be moved is 3, so in the second time step we may give number 3 an instruction, and so forth until the list of numbers are sorted. Find the minimum number of time steps required to sort these numbers. INPUT FORMAT: The first line of input contains N, The second line contains N space-separated integers, pl,p2,p3.pn, indicating the starting order of these numbers. OUTPUT FORMAT A single integer: the number of time steps before the N numbers are in sorted order, if we acts optimally. SAMPLE INPUT 1: 4 1 2 4 3 SAMPLE OUTPUT 1: 3 SAMPLE INPUT 2: 60 35 50 4 39 54 32 20 53 29 1ô 55 28 40 44 48 25 21 5 9 14 33 3 16 38 31 23 15 60 27 49 11 51 46 52 30 45 1 6 36 43 24 7 58 56 42 2 8 10 12 13 17 19 22 26 34 37 41 47 57 59 SAMPLE OUTPUT 2: 45 SAMPLE INPUT 3: 70 23 16 69 53 51 65 70 29 5 41 62 25 13 21 3 22 68 28 1 2 4 6 7 8 9 10 11 12 14 15 17 18 19 20 24 26 27 30 31 32 33 34 35 36 37 38 39 40 42 43 44 45 46 47 48 49 50 52 54 55 56 57 58 59 60 61 63 64 66 67 SAMPLE OUTPUT 3: 18
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
object oriented c++

Transcribed Image Text:Q1: given N numbers in pl,p2,p3..pn, we would like to sort these
number. The only process we can do is moving the first number in
the list k spaces down the line.
For example, suppose that N=4 and the numbers start off in the
following order:
4, 3, 2, 1
The only number can be moved at this point is 4, If we instructs
number 4 to move 2 spaces down the line, the order will
subsequently look like this:
3, 2, 4, 1
Now the only number can be moved is 3, so in the second time
step we may give number 3 an instruction, and so forth until the
list of numbers are sorted.
Find the minimum number of time steps required to sort these
numbers.
INPUT FORMAT:
The first line of input contains N, The second line
contains N space-separated integers, pl,p2,p3..pn, indicating the
starting order of these numbers.
OUTPUT FORMAT
A single integer: the number of time steps before the N numbers
are in sorted order, if we acts optimally.
SAMPLE INPUT 1:
4
1 2 4 3
SAMPLE OUTPUT 1:
3
SAMPLE INPUT 2:
60
35 50 4 39 54 32 20 53 29 18 55 28 40 44 48 25 21 5 9 14 33 3 16
38 31 23 15 60 27 49 11 51 46 52 30 45 1 6 36 43 24 7 58 56 42 2
8 10 12 13 17 19 22 26 34 37 41 47 57 59
SAMPLE OUTPUT 2:
45
SAMPLE INPUT 3:
70
23 16 69 53 51 65 70 29 5 41 62 25 13 21 3 22 68 28 1 2 4 6 7 8
9 10 11 12 14 15 17 18 19 20 24 26 27 30 31 32 33 34 35 36 37 38
39 40 42 43 44 45 46 47 48 49 50 52 54 55 56 57 58 59 60 61 63
64 66 67
SAMPLE OUTPUT 3:
18
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY