
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Justify each answer.
- Write pseudocode for an
algorithm that interchanges the values of the variables m and n, using only assignments (assigning values to variables). - Arrange the functions (1.5)n, n100, (log2n)3, 10n, n!, and n99 so that each function is big-O of the next function.
- Give a big-O estimate for the following algorithm:
count = array of k + 1 zeros
for x in input do
count[key(x)] + = 1
end for
total = 0
for i in 0,1,...k do
count[i], total = total, count[i] + total
end for
output = array of the same length as input
for x in input do
output[count[key(x)]] = x
count[key(x)] + = 1
end for return output
![Algorithms
Justify each answer.
a) Write pseudocode for an algorithm that interchanges the values of the variables m and n, using only
assignments (assigning values to variables).
b)
Arrange the functions (1.5)", n100, (log2n)³, 10", n!, and n9 so that each function is big-O of the
next function.
c) Give a big-O estimate for the following algorithm.
count = array of k + 1 zeros
for x in input do
count[key(x)] + = 1
end for
total = 0
for i in 0,1,...k do
count[i), total = total, count[i] + total
end for
output = array of the same length as input
for x in input do
output[count[key(x)]] = x
count[key(x)] + = 1
end for return
output](https://content.bartleby.com/qna-images/question/73f1cfd2-bcd7-4331-9bac-d6561a274292/5e013df7-f2fa-4fc1-844d-a1f8f10243ff/e4awkbh_thumbnail.png)
Transcribed Image Text:Algorithms
Justify each answer.
a) Write pseudocode for an algorithm that interchanges the values of the variables m and n, using only
assignments (assigning values to variables).
b)
Arrange the functions (1.5)", n100, (log2n)³, 10", n!, and n9 so that each function is big-O of the
next function.
c) Give a big-O estimate for the following algorithm.
count = array of k + 1 zeros
for x in input do
count[key(x)] + = 1
end for
total = 0
for i in 0,1,...k do
count[i), total = total, count[i] + total
end for
output = array of the same length as input
for x in input do
output[count[key(x)]] = x
count[key(x)] + = 1
end for return
output
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- You are given an array A[1, ., n] in which the elements A[2] to A[n] are already sorted, i.e., A[2, .., n] is a sorted array. Write down an efficient algorithm with proper pseudocode for moving A[1] in the correct place, so that the full array A[1, ..., n] is sorted.arrow_forwardalgorithms are solely theoretical for a and b. please number the steps of the algorithm, thank youarrow_forwardAn array is called a winner if it has two entries which together add up to a third entry, i.e. if A[i] + A[j] = A[k]for some i,j,k, where i≠j≠k. a)Write an algorithm (pseudocode preferred) to determine if a given array A is a winner. Your algorithm should not use any additional data structures. b)Analyze the running time of your algorithm using Big-O notation.arrow_forward
- To compute the average of the squares of the elements of a vector V, aka the mean square, we (Note: use randn to create a random vector) Select one: a. We use polyfit which does least squares and skip the minimization part b.we use sum(V.^2)./length(V*V) c.we use sum(V.*V)/length(V) d.we use mean(V) e.we use sum(V^2)/length(V)arrow_forwardWe can sort n integers between 0 and 2n in O(n) time. True False Given a sorted array of n integers, we can find the median of them in O(1) time. True False If ƒ = 0(g), then g = 0(f). False Truearrow_forwardDuring each iteration of Quick Sort algorithm, the first element of array is selected as a pivot. The algorithm for Quick Sort is given below. Modify it in such a way that last element of array should be selected as a pivot at each iteration. Also explain the advantages.arrow_forward
- write a computer program that produces the desired output from the given input. Input: Elements in a finite set SOutput: Elements in ℘(S)Algorithm: Use recursion.arrow_forwardThe algorithm below searches for the maximum in an input array A. Assume A is a random sequence containing n distinguishable real numbers, what is the probability for line #4 to be executed exactly once? (The phrase "random sequence" here means the n numbers can appear in any order with equal chance.) mymax(A, n) { 1: max = A[1]; 2: for i = 2:n 3: if A[i] > max 4: max = A[i); 5: end; 6: end; 7: return max; }arrow_forwardAn array of size n and two integers D and S are given, the special sum of a subarray is defined as follows:(Sum of all elements of the subarray) (D - p S)Where p = number of distinct prime factors of “product of all elements of the subarray”.Find the maximum special sum by considering all non-empty subarrays of the given array.Input:-First 3 integers will be n, D and S and the following will be the elements of the arrayOutput:- Output maximum special sum considering all non-empty subarrays of the array(single output integer)arrow_forward
- A majority element is an element that makes up more than half of the items inan array. Given a positive integers array, find the majority element. If there is no majority element,return -1. Do this in O(N) time and 0(1) space.Input: 1 2 5 9 5 9 5 5 5Output: 5arrow_forwardan array of integers nums sorted in ascending order, find the startingand ending position of a given target value. If the target is not found in thearray, return [-1, -1]. For example:Input: nums = [5,7,7,8,8,8,10], target = 8Output: [3,5]Input: nums = [5,7,7,8,8,8,10], target = 11Output: [-1,-1].arrow_forwardLet M(n) be the minimum number of comparisons needed to sort an array A with exactly n ele- ments. For example, M(1) = 0, M(2) = 1, and M(4) = 4. If n is an even number, clearly explain why M(n) = 2M(n/2) + n/2.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education