Question

6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the va

0 0
Add a comment Improve this question Transcribed image text
Answer #0

The function swap v,v) Oİ Adot aw tle飆.tos, -to -el.e agorthm. Fn one dort Sentence expafn んlat tle Rwpaseal the The agerithres what is ost case aumti ne Scevaiofoa this a while bopOin) (fox loop--> O(n) foy loop both for (ooPs T s (2n) .l-e (n)

Add a comment
Know the answer?
Add Answer to:
6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is...

    (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is an earray A. You must assume that indexing begins at 1. 1: for j = 2: A.length do key = A i=j-1 while i > 0 and A[i] > key do Ali + 1] = Ai i=i-1 7: A[i+1] = key (a) Follow this algorithm for A[1..4) =< 7,9,6,8 >. Specifically, please indicate the contents of the array after each iteration of the outer...

  • 3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int...

    3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...

  • It is common practice for banks to record account transactions in the chronological order that they...

    It is common practice for banks to record account transactions in the chronological order that they were made. However, it is also common for people to prefer to order their transactions by check number, versus chronological order. This is essentially a problem of sorting a list initially ordered chronologically into one sorted by check number, where it is highly likely that the chronologically ordered list is almost already sorted by check number. Consider the following sorting algorithm where A is...

  • Create the following function in java: ALGORITHM PERMUTATION GENERATOR PermGenerator(integer n 22) li generates in lexicographical...

    Create the following function in java: ALGORITHM PERMUTATION GENERATOR PermGenerator(integer n 22) li generates in lexicographical order all permutations llof the integers in the set {I.....!! Local variables: integers i //indices of permutation elements integer //for loop counter integers d., d..., Mleft to right elements of a permutation Section 4.4 Permutations and Combinations 283 1/create and write out smallest permutation for k=1 to n do end for write d.d..... //create and write out remaining permutations for k = 2 to...

  • Question 2 Consider the following algorithm Fun that takes array A and key Kas Fun(AO,...,n -...

    Question 2 Consider the following algorithm Fun that takes array A and key Kas Fun(AO,...,n - 1], K) count = 0 for i = 0 ton - 1 do for j = i +1 to n - 1 do if A[i] + A[j] == K then count = count +1 end if end for end for return count What is the best case time complexity of the above algorithm?! (log(n)) O(1) (n) (na) Previous o H H 9

  • 4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up t...

    4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...

  • Perform the following to the algorithm below: - - Express T(n) as a function of n...

    Perform the following to the algorithm below: - - Express T(n) as a function of n Find a best approximation for the Big O function for T(n) Perform a time complexity analysis Define the basic operation of the algorithm Correctness Efficiency - - Procedure maxMin (n, A, I, h) integer h, I, A (1:n), n integer j j-2 IA (1) hS (1) while (i <=n) do if (Ali) < 1) then TEA (0) if(Ali) >h) then h A() j+į+1 repeat...

  • (V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a...

    (V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a list of n integers) for i = 2 to n do c= j=i-1 while (j > 0) do if ra; then break end if 4j+1 = a; j= j-1 end while j+1 = 1 end for 14: return 0.02. 1, 15: end procedure Answer the following questions: (1) Run the algorithm with input (41, 02, 03, 04) = (3, 0, 1,6). Record the values...

  • 2. Suggest a structured plan (algorithm) for the bubble sort and selection sort, and perform running...

    2. Suggest a structured plan (algorithm) for the bubble sort and selection sort, and perform running time analysis for both best and worst case. 3. Consider the age data of 12 children who are supposed to undergo for vaccination in ascending order of their age. Suggest and apply a sorting technique which can efficiently handle this data. Show all the intermediate steps clearly. Child ID 01 02 03 04 05 06 07 08 09 10 11 12 2. Age 1...

  • 6. [8 marks Consider the sequence 10, 11, ... defined by To = 0, 11 =...

    6. [8 marks Consider the sequence 10, 11, ... defined by To = 0, 11 = 1, and ri = i-1 + 24-2 for all i > 2. Consider the following algorithm that attempts to compute the value In, given an n > 0. Algorithm 6 1: //pre: (n e Z) ^ (n > 0) 2: if n == 0 then 3: bro 1: else 5: a 0 6: 5+ 1 it1 //LoopInv: while i<n do ct a+b atb bc...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT