CSE240

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

2 pointer operations

&- r-value *- l-value

what are the four-steps abstract approach for solving recursive problems?

1. Formulate the size-n problem. 2.Find the stopping condition and the corresponding return value. 3.Formulate the size-m problem and find m. in many cases, m = n-1; 4. Construct the solution of size-n problem from size-m problem.

Recursion - Traverse Binary Search Tree 1. Formulate the size-n problem. 2.Find the stopping condition and the corresponding return value. 3.Formulate the size-m problem and find m. in many cases, m = n-1; 4. Construct the solution of size-n problem from size-m problem.

1. void traverse (struct treeNote *top) 2. if ( p == NULL) and return NULL; 3. Traverse (p->left); then traverse(p->right); 4. traverse (p->left); printf("date = %d\n", p-> data); traverse(p->right);

Recursion- Search Binary Search Tree 1. Formulate the size-n problem. 2.Find the stopping condition and the corresponding return value. 3.Formulate the size-m problem and find m. in many cases, m = n-1; 4. Construct the solution of size-n problem from size-m problem.

1.struct treeNote *search(struct treeNote *top, int key) 2. stopping Condition: (if (key == p->data) Return (printf("%d, p->data); 3. search( p->left, key); or search(p->right, key); 4. struct treeNote * search(struct treeNote *top, int key) { struct treeNote *p = top; if (key == p->data) printf("data = %d\n", p->data); if (key <= p->data) { if (p->left == NULL) return p; else search(p->left, key); } else { if (p->right == NULL) return p; else search(p->right, key);

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;

10

Given the following snippet of code, answer the following two questions based on the code: typedef enum {red, amber, green} traffic_light; traffic_light x = red, y = green; while (x != y) { x++; } y++; printf("x = %d, y = %d", x, y); 1. What value will be printed for variable x? Please choose: 0 . 2. What value will be printed for variable y? Please choose: 2

2 3

Consider the following snippet of code in a 32-bit computer. #define max 10 struct contact { char name[30]; char email[30]; int phone; } struct contact A[max]; What is the size of the entire array A in bytes?

640

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; } x;

68 bytes

A pointer variable can take the address of a memory location as its value. Read the given program. main(){ int i = 10, j = 20, *p, *q, **r; p = &i; *p = 40; q = &j; *q = 60; r = &p; **r = 80; printf("%d", i); printf("%d", j); i = 10; j = 70; printf("%d", **r);

80 60 10

Given the following code char *p = "hello", *s = "this is a string"; p = s; printf("%s\n", p); What will happen?

A compilation error will occur at this line: p = s;

What is "func" in this C program example? #include <stdio.h> #define func(x, y) (x > y) ? y : x int main(){ int x = 10; int y = 9; int z = func(x, y);}

A macro

C/C++ has 2 pointer operators, which operator will return the address of a variable?

Ampersand (&)

Type checking types (two)

Coercion, Casting

What programming language characteristics impact the readability of the programs written in this language?

Control structures, Syntax design, Data structures

What are the key features of object orientation in programming languages? Select all that apply.

Encapsulation of state and dynamic memory allocation

semantic error

Follows the rules but makes no sense. ex. the milk drinks the cat.

If you want to change the insertion sort function with a size-(n-1) problem, as discussed in the lecture, to a merge sort function, where do you need to make changes?

In the definition of size-m problem. In the code that constructs the solution of size-n problem from the size-m problem.

Given the following C code char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} }; int i, j; for (i = 0; i<2 ; i++) { for (j = 0; j<3; j++) printf("%c", a[i][j]);}

It prints: catdog

Given the following code char a[] = {'c', 'a', 't', '\0'}; char *p = a; while (*p != 0) { *p = *p + 1; printf("%c", *(p++)); } What will happen?

It prints: dbu

DOES VALUES WHILE COMPILING, FASTER The programmer decides if to optimize the program; The programmer is responsible for the correctness; Macro is a forced in-lining and the programmer can predict the performance.

Macros

what type of equivalence is two types are equivalent if they have the same name .

Name equivalence

What is the major improvement of structured programming languages over the earlier programming languages?

Removing Goto statement from the language.

If your program was designed to print "Hello World" ten (10) times, but during execution, it printed eleven (11) times. What type of error is it?

Semantics Error

(True or False) Sort orthogonality 1 and sort orthogonality 2 implies compositional orthogonality.

TRUE

Scope rule

The scope of a declaration starts from the declaration and extends to the end of the current block.

When will the buffer be created?

When the file operation fread or fwrite is performed.

Given this snippet of codes, what is the expected output? #include <stdio.h> char *getString(char *str) { return str;} void main() { char *p, q[] = "Hello", *s = "World"; p = getString(s); printf("%s %s\n", p, q);}

World Hello

A merge-sort is typically implemented using

a function with two recursive calls.

Assume a function requires 20 lines of machine code and will be called 10 times in the main program. You can choose to implement it using a function definition or a macro definition. Compared with the function definition, macro definition will lead the compiler to generate, for the entire program, ______

a longer machine code but with shorter execution time.

The function searching a binary search tree can be easily implemented using a

a recursive function with two recursive calls.

The size (number of bytes) of a structure-type variable can be changed by the following factors. Select all that apply.

adding a member into the structure. changing the computer from a 32-bit to a 64-bit processor.

A final method in Java defines

an in-line function

When inserting a data into a binary search tree, the data should be inserted

at the position that keeps the entire tree a binary search tree.

If we want to store an array of structures into a disk file, what file type should we choose?

binary file

Consider an array, a linked list, and a binary search tree. Which data structure requires fewest comparisons in average to search an element stored in the data structure?

binary tree

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;}

call-by-address

Given this snippet of codes, identify the passing mechanism used for y (in func). void func(int *x, int y){ *x = *x + y; y = 2;

call-by-value

Which parameter passing mechanism does not have side-effects?

call-by-value

Explicit type conversion is commonly refer to as __________

casting

Implicit type conversion is commonly refer to as __________ .

coercion

What C/C++ constant variable can potentially be modified during the execution?

const x = 5;

C++ allows a programmer to create an object through ___________ (Select all that apply)

declaration in compilation phase and the "new" operation during execution.

Event-driven computing paradigm is to

define a set of events and write an event handler for each event.

The data structure that stores the Frequently Brought Together (FBT) list in Amazon's recommendation system is linked toeach item in the catalog.

each item in the catalog.

In an array-implemented queue class, what members should be declared as "public" members?

enqueue and dequeue functions

in c, how to avoid reading in the \n after scanf in buffer

fflush(stdin)

What computing paradigm enforces stateless (no variable allowed) programming?

functional

Which recursive functions require us to define more than one size-m problem?

hanoi tower mergesort function

Assume that you want to delete the entire linked list pointed to by head. Which of the following deletion operation will cause the most garbage of memory?

head = null;

The tail variable in an array of structures is used for indicating (Select all that apply) Correct!

how far the search() function should go in searching the items of the array. where to insert a new item, if the items in the array do not need to be sorted.

What programming paradigm does Fortran belong to?

imperative

The reason that we need to call fflush() or cin.ignore() is because the previous

input leaves a character in the file buffer.

If you like to see accurate debugging information, which of the following program processing would you recommend?

interpretation

Which language will report a compilation error for the following snippet of code?

java

What is the maximum number of padding bytes that a compiler can add to a structure?

more than 4

Converting an integer value 5 to a float number 5.0 takes

more than two machine instuctions

Given the information below, how do you insert a new node, p, to the beginning of a linked-list. Assume head is pointing to the first node in the linked-list. struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *head, *p;

p->next = head; head = p;

What data types in C have the same data range, assuming that the computer used is a 32-bit computer?

pointer type and unsigned int

Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statement prints character a?

printf("%c", *(++p));

During compilation, linker is used for ____

resolving external references (bring in code from other libraries).

what error is this: int x = 5/0;

semantic error;

Which of the following cannot be checked by an imperative or object-oriented compiler. Select all that applies.

semantics

A critical step in writing a recursive function is to assume that the

size-m problem has been solved by the underlying recursive mechanism, where m < n.

what type of equivalence is two types are equivalent if they have the same set of values and operations. (e.g. non- structured C types)

structural equivalence

Which construct will have a loop when expressed in a syntax graph?

switch

What error is this: int x = 'a';

syntax error

Type Checking

the activity of ensuring that the operands of an operator are of compatible types

Data type:

the set of primary values allowed and operations on these values. It is used to declare variables.

What does the tail-recursive program resemble?

while-loop

syntactic error

wrong construction of the code, not following the rules of the language. Does not care about meaning of the code. EX. Cat the drink milk the.

Given the information below, how will you access the name for a terminal node pointed to by x? struct Terminal { char name[30]; char location[32]; struct Terminal* next;} *x;

x->name;

Given this snippet of codes, what is the expected output? void func(int *x, int y){ *x = *x + y; y = 2;}

x: 20, y: 10

char name[] = "hello"; char *p; p = name; // Is this possible?

yes ( equivalent to p = &name[0];)


संबंधित स्टडी सेट्स

Ch 10 SB Pure Competition in the Short Run

View Set

Chapter 1: Campbell Biology 9th ed.

View Set

money and financial systems test 2 (ch 9-12)

View Set

Quiz 1 Study Guide for Medical Surgical ll

View Set

Network Troubleshooting and Tools (5.0) study set

View Set