Question

In: Computer Science

Task 1. to be completed. 1.1 - Write a small Python snippet code that can revert...

Task 1. to be completed.

1.1 - Write a small Python snippet code that can revert an array of N element (Please do not use the default function “reverse()).

1.2 - There is a famous programming (algorithm) concept that can vastly reduce the complexity of Recursive Fibonacci Algorithm. 2 .a) What is the name of this concept 2.b) Write the execution time and memory complexity of Fibonacci sequences, once this concept is applied 2.c) Explain the main idea behind this concept, and how it reduces the execution time complexity.

1.3 - There is a bound over the runtime complexity of sorting algorithms if no assumption is made on the type of input. Write two algorithms that serve as an exception to this bound and explain what their additional assumption on the input is.

1.4 - Write the average running time complexity of Selection, Insertion, Mergesort, Quicksort, and Radix sort algorithms with Big-O notation.

1.5 - Explain why the array must be sorted in order for binary search to work. Your answer must relate the sorting requirement with the complexity of binary search (e.g., provide a counter example that violates complexity etc)

1.6 - What is the Big-O complexity of Binary Search for input size N. Write just one Big-O term.

Solutions

Expert Solution

#The string reverse program in Python is:

a = input("Enter the String which you wnat to reverse: ") #Enter the input which you waat to reverse
b = "" #Create an empty string
for i in a: #using for loop to reverse the string
b = i+b
print ("The reverse of %s is: %s"%(a,b)) #print the string which is reversed

1.2.

2a. The name of the method is "Golden Ration"

2b. The execcution time of the fibonnci series once this method applied is "O(1.6180)^n" . and the memory required is 7772 kilobytes.

2c. The main idea behind this concept is quadratic equations

1.4. The average runtime of  

selection = O(n)

Insertion = O(n)

Merge sort = O(nlog(n))

quick sort = O(nlog(n))

Radix Sort = O(n+b)*log(bk)  whare b is the base of the log and k is the maximum value

1.5 Generally binary search works on the princple of finding the middle of the array which has the value if median in array. if the binary search is not sorted, the assumptions which we are assuming will not work. because the median will be diffrent places and slicing the array into half may mean that you slice the number that we are searching for

1.6 The time complexity of binary search is O(log2(N))

where 2 is base of the log and and N is number of times the operation has to perform.

----------------------------------------------------------------

Kindly comment your queries if any, upvote if you like it. Thank you!!


Related Solutions

CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
Write a code snippet to pre-sell a limited number of movie tickets. Each   buyer can buy...
Write a code snippet to pre-sell a limited number of movie tickets. Each   buyer can buy as many as 6 tickets. No more than 20 tickets can be sold.   Prompt the user for the desired number of tickets and then display the   number of remaining tickets. Repeat until all tickets have been sold,   and then display the total number of buyers. **********IN JAVA**********
*****IN JAVA***** A run is a sequence of adjacent repeated values. Write a code snippet that...
*****IN JAVA***** A run is a sequence of adjacent repeated values. Write a code snippet that generates a sequence of 20 random die tosses in an array and that prints the die values, marking the runs by including them in parentheses, like this: 1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 (3 3) Use the following pseudocode: inRun = false for each valid index i in the array If inRun...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then prints the following output: a. every element (on a single line) b. every element at an even index (on a single line) c. every even element (on a single line) d. all elements in reverse order (on a single line) e. only the first and last elements (on a single line)
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
Write a code snippet for the following:   You need to control the maximum number of people...
Write a code snippet for the following:   You need to control the maximum number of people who can be in a   restaurant at any given time. A group cannot enter the restaurant if they   would make the number of people exceed 100 occupants. Use random numbers   between 1 and 20 to simulate groups arriving to the restaurant. After each   random number, display the size of the group trying to enter and the number   of current occupants. As soon as the...
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Write a java code snippet that allows a teacher to track her students’ grades. Use a...
Write a java code snippet that allows a teacher to track her students’ grades. Use a loop to prompt the user for each student’s name and the grade they received. Add these values to two separate parallel ArrayLists. Use a sentinel to stop. Output a table listing each of the student’s names in one column and their associated grades in the second column.
Task 1 1.1 - Mergesort has two major advantages over Quicksort. What are these advantages? Write...
Task 1 1.1 - Mergesort has two major advantages over Quicksort. What are these advantages? Write at most 5-6 sentences. 1.2 - Mergesort complexity analysis, explain it via recurrence relation and its main strategy. Write at most 7-8 sentences. 1.3 - Why a recursive algorithm always needs a base case? 2-3 sentences at most. 1.4 - Write Fibonacci Sequence formula F(N) with its base cases. Just write the formula with base-cases. 1.5 - Show how F(N=4) is computed for Fibonacci...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT