
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
Consider the
ALGORITHM MinDistance(A[0..n − 1])
//Input: Array A[0..n − 1] of numbers
//Output: Minimum distance between two of its elements
dmin←∞
for i ←0 to n − 1 do
for j ←0 to n − 1 do
if i != j and |A[i]− A[j ]| < dmin
dmin ←|A[i]− A[j ]|
return dmin
if n = 20, and the list is sorted in descending order, then the loop " or i ←0 to n − 1 do " will be executed ______ times.
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 3 steps

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
- The following algorithm adds all the entries in the “upper triangular” part of a square n × n array A. Consider n = 5 and the 5 × 5 array below. What will the ending value for sum be for this algorithm and the array below? sum = 0 for k = 1 to n do for j = k to n do sum = sum + A[k, j] end for end for 1 3 1 0 2 3 1 0 3 3 0 0 1 2 0 0 2 3 1 2 2 2 3 0 1arrow_forwardOne disadvantage of using a For-loop in sorting algorithms is that the body of theFor-loop is repeatedly executed even if it is no longer necessary. One example isBubble Sort:Input: Array A[1 . . . n]Output: Array A sortedfor i ←1 to (n −1) dofor j ←1 to (n −i) doif A[j] > A[j + 1] thenA[j] ↔A[j + 1]return AIn the array [2, 1, 3, 7, 9] we know that when 2 and 1 are interchanged, early on in theexecution of the algorithm, the array is now sorted, and all subsequent iterations ofthe outer loop are unnecessary. *Write a version of Bubble Sort that avoids unnecessary comparisons*arrow_forwardConsider the pseudo-code below: ALGORITHM MaxElement(A[0..n - 1]) //Determines the value of the largest element in a given array //Input: An array A[0..n - 1] of real numbers //Output: The value of the largest element in A maxval - A[0] for i 1 to n - 1 do if A[i] > maxval maxval ← A[i] return maxval a. What is the basic operation of this algorithm? b. Give the best-case and worst-case time complexities of this algorithm in asymptotic notation. Consider the algorithm below and give its best-case and worst-case time complexities in asymptotic notation. ALGORITHM UniqueElements (A[0..n-1]) //Determines whether all the elements in a given array are distinct //Input: An array A[0..n - 1] //Output: Returns "true" if all the elements in A are distinct // and "false" otherwise for i 0 to n - 2 do for ji+ 1 to n - 1 do if A[i] = A[j] return False return Truearrow_forward
- Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums = [-7, -3,2,3,11] Output: [4.9,9,49,121]arrow_forwardSee the pseudo-code of the Binary Search using recursion below. Fill in the XXXX and YYYY in the code Algorithm BinarySearch (A,v,low,hi) Input: array A indexed from low to hi with items sorted from smallest to largest. We are searching for the item v Output: returns a location index of item v in array A; if v is not found, -1 is returned. if (low > hi) then return (-1); mid = (lo + hi)/2; if (A[mid] = v) then == return(mid); if (A[mid] < v) then return(BinarySearch(A, XXXX ,hi, v)); else return(BinarySearch(a, lo, YYYY, v)); О а. ХX: lo+1, YҮҮ: hi O b. XXXX: mid, YYYY: mid О с. ХXXX: lo, YYYY: hi O d. XXXX: lo+1, YYYY: hi-1 O e. XXXX: mid+1. YYYY: mid-1arrow_forwardYou 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_forward
- Q1. Write the code necessary to find the largest element in an unsorted array of integers. What is the time complexity of this algorithm? Q2. Determine the growth function and order of the following code fragment: for (int count=0; count < n; count++) { for (int count2=0; count2 < n; count2=count2+2) { System.out.println(count, count2); } } Q3. Determine the growth function and order of the following code fragment: for (int count=0; count < n; count++) { for (int count2=0; count2 < n; count2=count2*2) { System.out.println(count, count2); } } Q4. What is the order of the following growth functions? 10n2 + 100n + 1000 10n3 – 7 2n + 100n3 n2 log n Q5. Arrange the growth functions of Q4 in ascending order of efficiency for n=10 and again for n = 1,000,000.arrow_forwardThere is a group of n children standing in a queue, where their ages are listed in the array A[ ]. The children are standing randomly in the queue. Most probably, their ages in the array A[ ] are randomly listed too. For each child, you are required to search for the next older childin the queue and to print the difference oftheir ages. Print all the outputs in an array Out[ ]. a) Design an efficient algorithm to solve this problem. [The efficiency of your algorithm is the main driver of the mark], and analyze the complexity of your solution. [full explanation of your answer should be provided]b) Develop a python code to implement your efficient algorithm. [The marks depend on the correctness of the code, indentation, comments, test-case]c) Prepare a brief report (250 words) comparing the two algorithmsarrow_forwardCalculating the Minimum Sum Path in a Triangle (LeetCode Problem)Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move toan adjacent number of the row below. More formally, if you are on index i on the current row, you maymove to either index i or index i + 1 on the next row. public static int minSumPathMemo(int[][] triangle)This method will calculate the minimum sum path in the triangle using the top down strategy. Note thismethod MUST BE recursive and you will need to create a recursive helper method. public static int minSumPathBottomUp(int[][] triangle)This method will calculate the minimum sum path in the triangle using the bottom up strategy. Note thismethod CANNOT be recursive and you should not create any additional helper functions. Extra Challenge: Could you do this using only O(n) extra space where n is the total number of rows in thetriangle? This is method signature class below: package dynamic; public class MinSumPath {…arrow_forward
- Write an efficient algorithm (to the best of your knowledge) for the following problem, briefly describe why it is a correct algorithm, and analyze the time complexity. If you cannot find any polynomial-time algorithm, then give a backtracking algorithm. Problem: Repeated Number Input: An array A[1...3n] of positive integers. Output: If any number in the array appears at least n times, then print such a number. Otherwise, print 'none'. Example: Input: A = [1,3,3,3,1,1]. Here 3n = 6 and n =2. Output: 3. Note that here 1 would also be a valid output. You just need to print one if there are many options. Example: Input: A = [4,3,5,7,9,1]. Here 3n = 6 and n =2. Output: 'none'arrow_forwardAnswer question number 5 pleasearrow_forwardThe following algorithm adds all the entries in the “upper triangular” part of a square n × n array A. Consider n = 5 and the 5 × 5 array below. The work unit is the addition operation, sum = sum + A[k, j]. How many times is the sum = sum + A[k, j] operation done? sum = 0 for k = 1 to n do for j = k to n do sum = sum + A[k, j] end for end for 1 3 1 0 2 3 1 0 3 3 0 0 1 2 0 0 2 3 1 2 2 2 3 0 1arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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