Docsity

CSE 240 MIDTERM HIGH-YIELD RECURSION, SORTING, AND COMPLEXITY ANALYSIS SUMMARY 2026, Exams of Programming Paradigms

Toggle sidebar
bg1
CSE 240 MIDTERM HIGH-YIELD RECURSION,
SORTING, AND COMPLEXITY ANALYSIS
SUMMARY 2026
◉ 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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download CSE 240 MIDTERM HIGH-YIELD RECURSION, SORTING, AND COMPLEXITY ANALYSIS SUMMARY 2026 and more Exams Programming Paradigms in PDF only on Docsity!

CSE 240 MIDTERM HIGH-YIELD RECURSION,

SORTING, AND COMPLEXITY ANALYSIS

SUMMARY 2026

◉ 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

  1. The output of the 2nd printf statement is 70 3.The output of the 3rd printf statement is 20 ◉ Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statement prints character a? Answer: printf("%c", *(++p)); ◉ Given the following code: char *p = "hello", *s = "this is a string"; p = s; printf("%s\n", p);

◉ 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);

  1. What value will be printed for variable x? 6.
  2. What value will be printed for variable y? 7 (Hint: enums are really just integers...) Answer: 1. 6
  3. 7 ◉ Consider the following snippet of code in a 32-bit computer #define MAX 10 struct contact { char name[30]; char email[30];

◉ 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);