
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
![1. task: Introduction and basics. And again, Peter Puzzle has found a piece of
paper with the following code:
int FooBar (A, i) {
n= len (A);
if (i == n-1) return A;
for (j= (i + 1); j<n; j++) {
if (A[i] <A[j]) { temp= A[i]; A[i] = A[j]; A[j] = temp; }
}
return FooBar (A, i+1)
}
QUESTIONS:
A) (i.) What is the loop invariant for the for loop based on which you can
show what the function actually returns? (ii.) Show that it remains invariant
throughout the execution of the function.
B) (i.) What does the array A returned by the function FooBar (A, i) contain?
Justify your answer. (ii.) What does the array A returned by the function
FooBar (A, 0) contain? Justify your answer.
HINT: Use induction.
C) (i.) What is the time complexity of the function FooBar if we count the
number of comparisons over the elements of the array A? Justify your answer.](https://content.bartleby.com/qna-images/question/45a2c93f-7502-4c22-a7b1-88698e38cece/bba35f42-cb47-4933-bc56-b5b38b41eec3/dakh0om_thumbnail.jpeg)
Transcribed Image Text:1. task: Introduction and basics. And again, Peter Puzzle has found a piece of
paper with the following code:
int FooBar (A, i) {
n= len (A);
if (i == n-1) return A;
for (j= (i + 1); j<n; j++) {
if (A[i] <A[j]) { temp= A[i]; A[i] = A[j]; A[j] = temp; }
}
return FooBar (A, i+1)
}
QUESTIONS:
A) (i.) What is the loop invariant for the for loop based on which you can
show what the function actually returns? (ii.) Show that it remains invariant
throughout the execution of the function.
B) (i.) What does the array A returned by the function FooBar (A, i) contain?
Justify your answer. (ii.) What does the array A returned by the function
FooBar (A, 0) contain? Justify your answer.
HINT: Use induction.
C) (i.) What is the time complexity of the function FooBar if we count the
number of comparisons over the elements of the array A? Justify your answer.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 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
- What is the value of sum?int w = 5;int sum = 0;for (int r = 1; r <= w; r++)for (int s = r; s <= w; s++)sum = sum + s;arrow_forwardDo you reach many, do you reach one? def knight_jump(knight, start, end): An ordinary chess knight on a two-dimensional board of squares can make an “L-move” into up toneight possible neighbours. However, we can generalize the entire chessboard into k dimensions from just the puny two. A natural extension of the knight's move to keep moves symmetric with respect to these dimensions is to define the possible moves as some k-tuple of strictly decreasing nonnegative integer offsets. Each one of these k offsets must be used for exactly one dimension of your choice during the move, either as a positive or a negative version. For example, the three-dimensional (4,3,1)-knight makes its way by first moving four steps along any one of the three dimensions, then three steps along any other dimension, and then one step along the remaining dimension, whichever dimensions that was. These steps are considered to be performed together as a single jump that does not visit or is blocked by any of the…arrow_forwardUse Javaarrow_forward
- Q5. What is the time complexity of following code? int a for (i = 0; ii; j--) { a = a + i + j; } 0; } Q6. What is the time complexity of following code? int i, j, k = 0; for (i = n/2; i <= n; i++) { for (j = 2; j <= n; j = j * 2) { k=k+n/2; } }arrow_forward1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 } write the signature of the method sum: sum(int,int) *Method name/parameter list list local variables of sum: x, y, and y are local variables of the function. list the parameters of sum: int x, int y write the line number where a call to sum occurs 7 list the arguments for the above call list the return type of sum here ______________arrow_forwardQuestion 3 Consider the following code: public static boolean[] [] whichOdd (int[] [] arr) { boolean[] [] result = new boolean [arr.length] [arr [0].length]; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { result[i][j] = arr[i][j] % 2 != 0; } [ ] Suppose you have written this solution to a problem that asks you to write a method that accepts a 2D array of integers (guaranteed to be rectangular) and returns a 2D array of boolean s where each element is true if its corresponding element in the parameter 2D array is odd, and false otherwise. You've already tried it with the problem's example which uses 2D array: } [ J return result; and after it's passed to your method, it correctly contains: [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] O [true, false, true, false], [true, false, true, false], [true, false, true, false], [true, false, true, false] Select an option below that makes a good test candidate to test a different case that shows…arrow_forward
- 1. When you run the following code, what would happen?public class Question1 {public static void main(String arg[]){int i;int [] A = new int[10];int count = 0;int temp = 10;for (i=0; i < A.length; i++)if (A[i] < temp) count++;System.out.println(count);}}(a) It finds the smallest value and stores it in temp.(b) It finds the largest value and stores it in temp.(c) It counts the number of elements equal to the smallest value in list.(d) It counts the number of elements in list that are less than temp.arrow_forwardI need the code from start to end with no errors and the explanation for the code ObjectivesJava refresher (including file I/O)Use recursionDescriptionFor this project, you get to write a maze solver. A maze is a two dimensional array of chars. Walls are represented as '#'s and ' ' are empty squares. The maze entrance is always in the first row, second column (and will always be an empty square). There will be zero or more exits along the outside perimeter. To be considered an exit, it must be reachable from the entrance. The entrance is not an exit.Here are some example mazes:mazeA7 9# # ###### # # ## # # #### # ## ##### ## ########## RequirementsWrite a MazeSolver class in Java. This program needs to prompt the user for a maze filename and then explore the maze. Display how many exits were found and the positions (not indices) of the valid exits. Your program can display the valid exits found in any order. See the examples below for exact output requirements. Also, record…arrow_forwardBum 0; for (int i = 1; iarrow_forwardJAVA Language: Transpose Rotate. Question: Modify Transpose.encode() so that it uses a rotation instead of a reversal. That is, a word like “hello” should be encoded as “ohell” with a rotation of one character. (Hint: use a loop to append the letters into a new string) import java.util.*; public class TestTranspose { public static void main(String[] args) { String plain = "this is the secret message"; // Here's the message Transpose transpose = new Transpose(); String secret = transpose.encrypt(plain); System.out.println("\n ********* Transpose Cipher Encryption *********"); System.out.println("PlainText: " + plain); // Display the results System.out.println("Encrypted: " + secret); System.out.println("Decrypted: " + transpose.decrypt(secret));// Decrypt } } abstract class Cipher { public String encrypt(String s) { StringBuffer result = new…arrow_forwardint arr[] = {-2, -4, 8, 4, 3, 3, -9};In Java with this given this array, how would this version of Divide and Conqueror be implemented in this case, specifically?arrow_forwardarrow_back_iosarrow_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