COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 2.1, Problem 2.11PP
A.
Explanation of Solution
Determining the value of variables “first” and “last” in function “reverse_array”:
From the given question, an array of odd length “cnt = 2k + 1”. Assume k = 0, 1, 2
Case 1:
- When “k = 0”, then “cnt = 2 (0) + 1 = 0 + 1 = 1”.
- Then call the function “reverse_array” with “cnt = 1”.
first | last = cnt - 1 | first < = last | inplace_swap(&a[first], &a[last]) |
first = 0 | last = 1 - 1 = 0 | 0 < = 0 |
inplace_swap(&a[0], &a[0]) Here the both values are equal so value of middle element “a[0]” is “0”. Therefore, “first = 0” and “last = 0”. That is same as the value of “k”. |
Case 2:
- When “k = 1”, then cnt = 2 (1) + 1 = 2 + 1 = 3.
- Then call the function “reverse_array” with “cnt = 3”...
B.
Explanation of Solution
Setting the array element is “0” in the function “inplace_swap”:
- In the “inplace_swap” function, the arguments “x” and “y” point to the same location.
- Once user compute “*x ^ *y”, then the user get the result of “0”. Because of, value of “a ^ a” is “0” for any “a” in the “inplace_swap” function.
- It is based on the property of “^”.
- Calling “inplace_swap” function to the reverse array, the value of middle element becomes “0” for odd array length.
- Once user compute “*x ^ *y”, then the user get the result of “0”. Because of, value of “a ^ a” is “0” for any “a” in the “inplace_swap” function.
Example:
When the array elements are “1, 2, 3, 4 and 5”, then the reverse array is “5, 4, 0, 2, 1”.
- Call the function “reverse_array” with array “a” 1, 2, 3, 4 and 5 and “cnt = 3”.
- Initially array “a” is
a[0] | a[1] | a[2] | a[3] | a[4] |
1 | 2 | 3 | 4 | 5 |
- Steps to find the reverse array...
C.
Explanation of Solution
Modification to the code for “reverse_array” function:
- Replace the test condition of “first <=...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
30.// programming
Write a function void reverse(int a[ ], int size)
to reverse the elements in array a, the second
parameter size is the number of elements in
array a. For example, if the initial values in
array a is {5, 3, 2, 0}.
After the invocation of
function reverse(), the final array values
should be {0, 2, 3, 5}
In main() function, declares and initializes an
integer array a with{5, 3, 2, 0}, call reverse()
function, display all elements in final array a.
Write the program on paper, take a picture, and upload
it as an attachment.
Or just type in the program in the answer area.
m861144
m861144
""'Question"".
(CP6) Write a function that is passed an array of structs and performs calculations. The function should locate the highest gpa from a group of students. The function is passed the array of structs, the first element to be searched, and the last element to be searched. The return value of the function is the highest gpa in the search range.
struct data{ string name; double gpa;};
double highestGpa( data [ ], int, int );
data [ ] - array of structs to search
int - first element to be searched
int - last element to be searched
return - highest gpa from group
Chapter 2 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
Ch. 2.1 - Practice Problem 2.1 (solution page 143) Perform...Ch. 2.1 - Prob. 2.2PPCh. 2.1 - Prob. 2.3PPCh. 2.1 - Practice Problem 2.4 (solution page 144) Without...Ch. 2.1 - Prob. 2.5PPCh. 2.1 - Prob. 2.6PPCh. 2.1 - Prob. 2.7PPCh. 2.1 - Prob. 2.8PPCh. 2.1 - Practice Problem 2.9 solution page 146 Computers...Ch. 2.1 - Prob. 2.10PP
Ch. 2.1 - Prob. 2.11PPCh. 2.1 - Prob. 2.12PPCh. 2.1 - Prob. 2.13PPCh. 2.1 - Prob. 2.14PPCh. 2.1 - Prob. 2.15PPCh. 2.1 - Prob. 2.16PPCh. 2.2 - Prob. 2.17PPCh. 2.2 - Practice Problem 2.18 (solution page 149) In...Ch. 2.2 - Prob. 2.19PPCh. 2.2 - Prob. 2.20PPCh. 2.2 - Prob. 2.21PPCh. 2.2 - Prob. 2.22PPCh. 2.2 - Prob. 2.23PPCh. 2.2 - Prob. 2.24PPCh. 2.2 - Prob. 2.25PPCh. 2.2 - Practice Problem 2.26 (solution page 151) You are...Ch. 2.3 - Prob. 2.27PPCh. 2.3 - Prob. 2.28PPCh. 2.3 - Prob. 2.29PPCh. 2.3 - Practice Problem 2.30 (solution page 153) Write a...Ch. 2.3 - Prob. 2.31PPCh. 2.3 - Practice Problem 2.32 (solution page 153) You are...Ch. 2.3 - Prob. 2.33PPCh. 2.3 - Prob. 2.34PPCh. 2.3 - Practice Problem 2.35 (solution page 154) You are...Ch. 2.3 - Prob. 2.36PPCh. 2.3 - Practice Problem 2.37 solution page 155 You are...Ch. 2.3 - Prob. 2.38PPCh. 2.3 - Prob. 2.39PPCh. 2.3 - Practice Problem 2.40 (solution page 156) For each...Ch. 2.3 - Prob. 2.41PPCh. 2.3 - Practice Problem 2.42 (solution page 156) Write a...Ch. 2.3 - Practice Problem 2.43 (solution page 157) In the...Ch. 2.3 - Prob. 2.44PPCh. 2.4 - Prob. 2.45PPCh. 2.4 - Prob. 2.46PPCh. 2.4 - Prob. 2.47PPCh. 2.4 - Prob. 2.48PPCh. 2.4 - Prob. 2.49PPCh. 2.4 - Prob. 2.50PPCh. 2.4 - Prob. 2.51PPCh. 2.4 - Prob. 2.52PPCh. 2.4 - Practice Problem 2.53 (solution page 160) Fill in...Ch. 2.4 - Practice Problem 2.54 (solution page 160) Assume...Ch. 2 - Compile and run the sample code that uses...Ch. 2 - Try running the code for show_bytes for different...Ch. 2 - Prob. 2.57HWCh. 2 - Write a procedure is_little_endian that will...Ch. 2 - Prob. 2.59HWCh. 2 - Prob. 2.60HWCh. 2 - Prob. 2.61HWCh. 2 - Write a function int_shifts_are_arithmetic() that...Ch. 2 - Fill in code for the following C functions....Ch. 2 - Write code to implement the following function: /...Ch. 2 - Write code to implement the following function: /...Ch. 2 - Write code to implement the following function: / ...Ch. 2 - You are given the task of writing a procedure...Ch. 2 - Prob. 2.68HWCh. 2 - Write code for a function with the following...Ch. 2 - Write code for the function with the following...Ch. 2 - You just started working for a company that is...Ch. 2 - You are given the task of writing a function that...Ch. 2 - Write code for a function with the following...Ch. 2 - Write a function with the following prototype: /...Ch. 2 - Prob. 2.75HWCh. 2 - The library function calloc has the following...Ch. 2 - Prob. 2.77HWCh. 2 - Write code for a function with the following...Ch. 2 - Prob. 2.79HWCh. 2 - Write code for a function threefourths that, for...Ch. 2 - Prob. 2.81HWCh. 2 - Prob. 2.82HWCh. 2 - Prob. 2.83HWCh. 2 - Prob. 2.84HWCh. 2 - Prob. 2.85HWCh. 2 - Intel-compatible processors also support an...Ch. 2 - Prob. 2.87HWCh. 2 - Prob. 2.88HWCh. 2 - We are running programs on a machine where values...Ch. 2 - You have been assigned the task of writing a C...Ch. 2 - Prob. 2.91HWCh. 2 - Prob. 2.92HWCh. 2 - following the bit-level floating-point coding...Ch. 2 - Following the bit-level floating-point coding...Ch. 2 - Following the bit-level floating-point coding...Ch. 2 - Following the bit-level floating-point coding...Ch. 2 - Prob. 2.97HW
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
- Don't try to give me wrong, plagiarised and Al generated answer. I'll report your account this is sure.arrow_forwardWrite a function that gets an array as a parameter (address and size) and a number and checks to see if that number exists in the array. The function should report every single occurrence of the number in the array. It should also report how many occurrences were detected in total (use c code)Suggested prototype: void findnReport(int* ar, int size, int num) Example of function output: If array = {2,5,3,5,12,13,14,15,0,5,-1,11,5} and num = 5, Number 5 found in array index 1 Number 5 found in array index 3 Number 5 found in array index 9 Number 5 found in array index 12 Total of 4 occurrences of number 5arrow_forward(C++) I need a quicksort algorithm implementation which returns the indices of the sorted array in an array without modifying the array itself:ie,Before sortingindex : 0 1 2 3 4 5values: 70 60 40 20 30 50After sortingindex : 3 4 2 5 1 0values: 70 60 40 20 30 50 function returns an array with indexes: [3 4 2 5 1 0]arrow_forward
- computer science questionarrow_forwardProgram 2: (LAB 7) Write a program for printing the largest elements in each row of an array using function. The function should take an array. and number of rows and columns as parameterarrow_forward) Write a program to overload the function call operator ( ) so as to allow the more common form of double-array subscripting. Therefore, instead of saying: chessBoard[row][column] for an array of objects, overload the function call operator to allow the alternate form: chessBoard(row, column) A sample output of your program should look like follows: chessBoard(1, 7) is 7 chessBoard(3, 5) is 15 chessBoard(8, 2) is 16 The value of each array element is the product of the row and column values. Using the class definition given in the myClassOperator.h header file below, implement the class member functions and driver code in separate files.arrow_forward
- | The code in Part 1 counts the crossings and nestings for a given matching. We now want to use this to analyze the distribution of crossings and nestings for arc diagrams with 100 arcs. Using your function random_matching from Exercise [1.4], generate 104 such arc diagrams and create histograms for the numbers of crossings and nestings, respectively. Display them in a single plot. Also generate a two-dimensional histogram for the joint distribution of crossings and nestings. What do you observe?arrow_forward"""3. Write a function validSolution/ValidateSolution/valid_solution()that accepts a 2D array representing a Sudoku board, and returns trueif it is a valid solution, or false otherwise. The cells of the sudokuboard may also contain 0's, which will represent empty cells.Boards containing one or more zeroes are considered to be invalid solutions.The board is always 9 cells by 9 cells, and every cell only contains integersfrom 0 to 9. (More info at: http://en.wikipedia.org/wiki/Sudoku)""" # Using dict/hash-tablefrom collections import defaultdict def valid_solution_hashtable(board): for i in range(len(board)): dict_row = defaultdict(int) dict_col = defaultdict(int) for j in range(len(board[0])): value_row = board[i][j] value_col = board[j][i] if not value_row or value_col == 0: return False if value_row in dict_row: return False else: dict_row[value_row] += 1.arrow_forwardThe goal is to use the following C++ Functions: Conditional Statement Arrays Looping (Any) To create a system that would do the following functions: Accept an input of five integer numbers in a single array object. Use a loop to get the five integer numbers. Arrange the five numbers from lowest to highest. Output the new array object which displays the arranged integers from highest to lowest.arrow_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