















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
CSE 240 MIDTERM HIGH-YIELD RECURSION, SORTING, AND COMPLEXITY ANALYSIS SUMMARY 2026
Typology: Exams
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















โ Converting an integer value 5 to a float number 5.0 takes Answer: At least one important machine instruction to perform conversion between data binary formats. โ Explicit type conversion is commonly refer to as __________. Answer: Casting โ Which of the following statements are correct if a language is strongly typed. Select all that apply. Answer: Each name in a program has a single type associated with it and type errors are always reported. โ Type checking happens during compilation phase. It reinforces which of the following structural layers? Answer: Contextual
โ The imperative programming paradigm is popular and is a part of object-oriented computing paradigm, because it ____ (Select all answers that apply). Answer: Matches the common culture of doing things by following the step-wise instructions and is based on computer organization and thus is efficient to execute on hardware. โ In C, what function can be used for inputting a string containing spaces? Answer: fgets(); โ The forward declaration of a function requires: (Select all answers that apply) Answer: parameter types, return type, and function name โ Where is the main() function located in a C++ program? Answer: Outside any class โ A variable declaration can involve the following attributes: (Select all answers that apply) Answer: type and scope โ A data type defines the Answer: values and operations allowed
โ C/C++ has 2 pointer operators, which operator will return the address of a variable? Answer: Ampersand (&) โ Given this snippet of code, what is the value of x after executing the last statement? int x = 10, *y; y = &x; y = y + 1; *y = 100; Answer: 10 โ A pointer variable can take the address of a memory location as its value. Read the given program: #include main(){ int a = 20, b = 30, *p, *q, **r; p = &a; *p = 50; q = &b;
*q = 70; r = &p; **r = 90; printf("%d\n", a); //1st printf statement printf("%d\n, b); //2nd printf statement a = 20; b = 30; printf("%d\n, **r); //3rd printf statement } Answer: 1. The output of the 1st printf statement is 90
โ Given the following code: char a[2][4] = { { 'c', 'a', 'r', 'b' }, { 'i', 'k', 'e', '\0' } }; char p = &a[0][0]; while (p != '\0') { printf("%c", *p); p++; } What will happen? Answer: It prints: carbike โ Given the following definition and declarations: #define size1 10 const int size2 = 20; char a1[size1]; char a2[size2]; which line is most likely to cause a compilation error? Answer: char a2[size2];
โ Given the following snippet of code, answer the following two questions based on the code: typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; days x = Mon, y = Sat; while (x != y) { x++; } y++; printf("x = %d, y = %d", x, y);
โ Consider the following snippet of code on a 32-bit computer: struct contact { char name[30]; int phone; char email[30]; } x; What is the size of variable x in bytes? (x is just a variable containing a struct contact) Answer: 68 โ When will the buffer be created? Answer: When the file operation fopen is performed. โ The reason that we use a buffer between the disk and the memory is _______ Answer: Disk access speed is low, but large blocks of data can be read from and written to the disk. โ What parameters are required when performing file operations fread and fwrite? Select all that apply.
Answer: Destination, source, number of items, and item size โ The reason that we need to call fflush() or cin.ignore() is because the previous Answer: input leaves a character in the buffer. โ Assume that the search function of a linked list is specified by struct Terminal* search(); What values can the search function return? Select all correct answers. Answer: The address of a terminal node and 0. โ Assume this is a 32-bit environment, what is the size of x? (HINT: Don't forget about padding.) struct Terminal { char name[30]; char location[32]; struct Terminal* next; }
first node in the linked list and that it already contains at least one node. struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *head, *p, *q; Answer: p = (struct contact *) malloc(sizeof(struct contact)); p->next = head->next; head->next = p; โ Given this snippet of codes, what is the expected output? #include char *getString(char *str) { return str; } void main() { char *p, q[] = "Hello", *s = "World"; p = getString(s);
printf("%s %s\n", p, q); } Answer: World Hello โ Given this snippet of codes, identify the passing mechanism used for x (in func). void func(int *x, int y){ *x = *x + y; y = 2; } Answer: pass-by-address โ Which of the following statements is true? A constant cannot be used as the actual parameter for pass-by-alias. A constant cannot be used as the actual parameter for pass-by- address. A structure type of variable cannot be as the actual parameter for pass-by-value.
} else return; } Answer: deleteList(node->next); โ Given this snippet of code, identify the size-n problem (based on the four step approach discussed in class). void deleteList(struct contact* node) { if (node != NULL) { deleteList(node->next); free(node); } else return; } Answer: void deleteList(struct contact* node) โ A tail-recursive function is structurally equivalent to Answer: a while loop โ A merge-sort is typically implemented using Answer: a function with two recursive calls.
โ A critical step in writing a recursive function is to assume that the Answer: size-m problem has been solved by the underlying recursive mechanism, where m < n. โ If you want to change the insertion sort function with a size-(n-1) problem, as discussed in class, to a merge sort function, then where do you need to make changes? Answer: In the code that constructs the solution of size-n problem from the size-m problem and in the definition of size-m problem. โ What is the time complexity of the insertion sort algorithm? Answer: O(n*n) โ Which of the following problems require us to define more than one size-m problem in it's recursive formulation? Answer: Mergesort and Towers of Hanoi โ In the hanoi towers function, what part of the code represents step 4: Construction of size-n problem from size-(n-1) problems? Answer: hanoitowers(n-1, S, D, M); hanoitowers(1, S, M, D); hanoitowers(n-1, M, S, D);
โ Consider an array, a linked list, and a binary search tree. Which data structure requires fewest comparisons on average to search an element stored in the data structure? Answer: binary search tree โ C++ allows a programmer to create an object through ___________ (Select all that apply) Answer: declaration in compilation phase and the "new" operation during execution. โ The purpose of the scope resolution operator is to allow a function to be Answer: placed outside the class. โ Using the principle of information hiding in OOP, in an array- implemented queue class, what members should be declared as "public" members? Answer: enqueue and dequeue functions โ What are the key features of object orientation in programming languages? Select all that apply. Answer: Encapsulation of state and dynamic memory allocation
โ If a function calls another function, the local variables in these two functions use the memory from Answer: different stack frames. โ Which C/C++ operations will acquire memory from heap? Select all that apply. Answer: malloc and new โ What is the key difference between a static variable and a global variable? Answer: They have different visibility. โ You do not need to garbage-collect the memory, if it comes from (Select all that apply) Answer: stack memory, global memory, and static memory โ Given the snippet of code: int x = 5; int bar(int j) { int *k = 0, m = 5; k = &m; return (j+m);