Computers and Technology

In an earlier module, you created programs that read the contents of a large file and process it, writing the results into another large file (Code at end). What if the files were 10x bigger, i.e. instead of a million rows, they were 10 million rows? Which of the following methods would have the fastest processing time:Run the process as it is, with the larger files.Break the files up into 10 files and schedule processes to run 30 seconds or 1 minute apart, then combine the resulting files into a single output file.Break the files up into 2 files and schedule processes to run 30 seconds or 1 minute apart, then combine the resulting files into a single output file.Break the files up into 5 files and schedule processes to run 30 seconds or 1 minute apart, then combine the resulting files into a single output file.Break the files up into 20 files and schedule processes to run 30 seconds or 1 minute apart, then combine the resulting files into a single output file.Can you think of other ways to increase efficiency and reduce processing time?Code from previous lesson:import randomimport osimport sys#getting the datetime importfrom datetime import datetime#read the entire file into memory and printdef readFile1(filename):f = open(filename)all_lines = f.readlines()all_lines = "".join(all_lines)print(all_lines)#read the file one line at a time in memory and print itdef readFile2(filename):with open(filename) as f:for line in f:print(line)def readFile3(filename):#get file sizef_size = os.path.getsize(filename)f = open(filename)#depending upon the file size determine the half way mark in bytesif f_size % 2 == 0:read_until = int(f_size/2)else:read_until = int((f_size+1)/2)#read the first half of the file into memoryfirst_half = f.read(read_until)#print the first half that has been read into memoryall_lines = "".join(first_half)print(all_lines)print(">>>>>>>>>>>>>>>>>
q1 sequential search 11 points q1.14 points grading comment: in what situation can we use sequential search? choice 1 of 5:when the array is sorted and the target is in the array. choice 2 of 5:when the array is sorted and the target is not in the array. choice 3 of 5:when the array is not sorted and the target is in the array. choice 4 of 5:when the array is not sorted and the target is not in the array choice 5 of 5:all of the above q1.22 points grading comment: what is the big o of sequential search? (n is the length of the array) choice 1 of 6:o(1) choice 2 of 6:o(log n) choice 3 of 6:o(n) choice 4 of 6:o(n log n) choice 5 of 6:o(n2) choice 6 of 6:o(!n) q1.35 points grading comment: using the array 11, 30, 34, 90, 99 as the input for sequential search, how many array elements are accessed in order to find the target element 34? choice 1 of 6:1 element choice 2 of 6:2 elements choice 3 of 6:3 elements choice 4 of 6:4 elements choice 5 of 6:5 elements choice 6 of 6:sequential search does not work here q2 binary search 9 points q2.13 points grading comment: in what situation can we use binary search? choice 1 of 6:when the array is sorted and the target is in the array choice 2 of 6:when the array is sorted and the target is not in the array choice 3 of 6:when the array is not sorted and the target is in the array choice 4 of 6:when the array is not sorted and the target is not in the array choice 5 of 6:1 and 2 choice 6 of 6:1 and 3 q2.22 points grading comment: what is the big o of binary search? (n is the length of the array) choice 1 of 6:o(1) choice 2 of 6:o(log n) choice 3 of 6:o(n) choice 4 of 6:o(nlog n) choice 5 of 6:o(n2) choice 6 of 6:o(!n) q2.34 points grading comment: which of the following statements about binary search is not true? choice 1 of 4:it is the fastest searching algorithm we have learned in cs111 choice 2 of 4:it does not work if the target is not in the array choice 3 of 4:it does need extra array space for it to run choice 4 of 4:the best case scenario is when the target is in the middle of the array q3 selection sort 5 points grading comment: q3.12 points grading comment: what is the big o of selection sort? (n is the length of the array) choice 1 of 6:o(log n) choice 2 of 6:o(n log n) choice 3 of 6:o(n) choice 4 of 6:o(n^2) choice 5 of 6:o(n^3) choice 6 of 6:o(!n) q3.23 points grading comment: what is the best case for selection sort? choice 1 of 4:when the array is already sorted choice 2 of 4:when the array is already sorted backward choice 3 of 4:when the array is sorted by pairs choice 4 of 4:there are no best case for selection sort q4 insertion sort 5 points q4.12 points grading comment: 4.1 (points) what is the big o of insertion sort? (n is the length of the array) choice 1 of 5:o(n log n) choice 2 of 5:o(n) choice 3 of 5:o(n^2) choice 4 of 5:o(n^3) choice 5 of 5:o(!n) q4.23 points grading comment: what is the best case for insertion sort? choice 1 of 4:when the array is already sorted choice 2 of 4:when the array is already sorted backward choice 3 of 4:when the array is sorted by pairs choice 4 of 4:there are no best case for insertion sort q5 mergesort 5 points q5.12 points grading comment: what is the big o of mergesort? (n is the length of the array) choice 1 of 6:o(log n) choice 2 of 6:o(n log n) choice 3 of 6:o(n) choice 4 of 6:o(n^2) choice 5 of 6:o(n^3) choice 6 of 6:o(!n) q5.23 points grading comment: what is the best case for merge sort? choice 1 of 4:when the array is already sorted choice 2 of 4:when the array is already sorted backward choice 3 of 4:when the array is sorted by pairs choice 4 of 4:there are no best case for merge sort q6 sort detective 30 points grading comment: identify algorithms given to you in the sortdetective program. q6.110 points grading comment: which sorting algorithm is algorithm 1? choice 1 of 3:insertion sort choice 2 of 3:selection sort choice 3 of 3:merge sort q6.210 points grading comment: which sorting algorithm is algorithm 2? choice 1 of 3:insertion sort choice 2 of 3:selection sort choice 3 of 3:merge sort q6.310 points grading comment: which sorting algorithm is algorithm 3? choice 1 of 3:insertion sort choice 2 of 3:selection sort choice 3 of 3:merge sort
Design a four-bit shift register (not a universal shift register) with parallel load using D flip-flops. (See Figs. 6.2 and 6.3.) There are two control inputs: shift and load. When shift = 1, the content of the register is shifted toward Az by one position. New data are transferred into the register when load = 1 and shift = 0. If both control inputs are equal to O, the content of the register does not change. A D 4 PC D D D A C Clock Fig. 6.2 Four-bit register with parallel load SI Serial input D D D D so Serial output CLK Fig. 6.3 Four-bit shift register 6.7 Draw the logic diagram of a four-bit register with four D flip-flops and four 4 x 1 mul- tiplexers with mode selection inputs s and . The register operates according to the following function table. (HDL-see Problem 6.35(e), ().) 51 50 Register Operation 0 0 No change Clock Fig. 6.2 Four-bit register with parallel load SI SO Serial input D D D D Serial output CLK Fig. 6.3 Four-bit shift register 6.7 Draw the logic diagram of a four-bit register with four D flip-flops and four 4 x 1 mul- tiplexers with mode selection inputs s and so. The register operates according to the following function table. (HDL-see Problem 6.35(e), (O).) 51 50 0 1 0 1 0 0 1 1 Register Operation No change Complement the four outputs Clear register to 0 (synchronous with the clock) Load parallel data 6.27 Using JK flip-flops: (a) Design a counter with the following repeated binary sequence: 0, 1, 2, 3, 4, 5, 6. (b) Draw the logic diagram of the counter. 2