Data Structures and Algorithms Exam Answer Key - 899 Verified Questions

Page 1


Data Structures and Algorithms

Exam Answer Key

Course Introduction

Data Structures and Algorithms is a foundational course that introduces students to the fundamental concepts of data organization, storage, and manipulation for efficient computational problem-solving. The course covers essential data structures such as arrays, linked lists, stacks, queues, trees, graphs, and hash tables, as well as algorithmic techniques including sorting, searching, recursion, and dynamic programming. Emphasis is placed on analyzing the efficiency of algorithms using Big O notation and applying data structures to solve real-world problems. Through theoretical learning and hands-on practice, students develop critical skills to design, implement, and optimize algorithms and data structures, preparing them for advanced topics in computer science and software development.

Recommended Textbook

C++ Programming From Problem Analysis to Program Design 6th Edition by D.S. Malik

Available Study Resources on Quizplus 18 Chapters

899 Verified Questions

899 Flashcards

Source URL: https://quizplus.com/study-set/1103 Page 2

Chapter 1: An Overview of Computers and Programming Languages

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/128446

Sample Questions

Q1) ____________________ signals represent information with a sequence of 0s and 1s.

Answer: Digital digital

Q2) ____ represent information with a sequence of 0s and 1s.

A) Analog signals

B) Application programs

C) Digital signals

D) System programs

Answer: C

Q3) The programming language C++ was designed by Bjarne Stroustrup at Bell Laboratories in the early ____.

A) 1960s

B) 1970s

C) 1980s

D) 1990s

Answer: C

Q4) In C++, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____________________.

Answer: class

To view all questions and flashcards with answers, click on the resource link above. Page 3

Chapter 2: Basic Elements of C

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21709

Sample Questions

Q1) In C++, reserved words are the same as predefined identifiers.

A)True

B)False

Answer: False

Q2) A(n) ____________________ is a collection of statements, and when it is activated, or executed, it accomplishes something.

Answer: subprogram sub program sub-program function modlue

Q3) The length of the string "computer science" is ____.

A) 14

B) 15

C) 16

D) 18

Answer: C

Q4) The ____________________ type is C++ 's method for allowing programmers to create their own simple data types.

Answer: enumeration

Page 4

To view all questions and flashcards with answers, click on the resource link above.

Chapter 3: Inputoutput

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21710

Sample Questions

Q1) When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.

A) clear

B) skip

C) delete

D) ignore

Answer: D

Q2) In the statement cin >> x;, x can be a variable or an expression.

A)True

B)False

Answer: False

Q3) The stream function ____________________ lets you put the last character extracted from the input stream by the get function back into the input stream. Answer: putback

Q4) On some compilers, the statements cin >> fixed; and cin >> scientific; might not work. In this case, you can use the statement ____________________ in place of cin >> fixed;.

Answer: cin.setf(ios::fixed);

To view all questions and flashcards with answers, click on the resource link above. Page 5

Chapter 4: Control Structures I Selection

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21711

Sample Questions

Q1) The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.

A)True

B)False

Q2) If the expression in an assert statement evaluates to true, the program terminates.

A)True

B)False

Q3) Which of the following is the "not equal to" relational operator?

A) !

B) |

C) !=

D) &

Q4) A(n) ____________________ structure does not require the evaluation of a logical expression.

Q5) The conditional operator ?: takes ____ arguments.

A) two

B) three

C) four

D) five

To view all questions and flashcards with answers, click on the resource link above. Page 6

Chapter 5: Control Structures II Repetition

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21712

Sample Questions

Q1) What is the output of the following C++ code? num = 10; while (num > 10)

\(\quad\)num = num - 2;

cout << num << endl;

A) 0

B) 6

C) 8

D) 10

Q2) Which executes first in a do...while loop?

A) the statement

B) loop condition

C) the expression

D) update statement

Q3) Which of the following loops does not have an entry condition?

A) EOF-controlled while loop

B) sentinel-controlled while loop

C) do...while loop

D) for loop

Q4) A software ____________________ is a piece of code written on top of an existing piece of code intended to fix a bug in the original code.

To view all questions and flashcards with answers, click on the resource link above. Page 7

Chapter 6: User-Defined Functions

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21713

Sample Questions

Q1) A variable for which memory is allocated at block entry and deallocated at block exit is called a(n) ____________________ variable.

Q2) Given the following function prototype: int test(float, char);, which of the following statements is valid?

A) cout << test(12, &);

B) cout << test("12.0", '&');

C) int u = test(5.0, '*');

D) cout << test('12', '&');

Q3) A(n) ____________________ parameter is a formal parameter that receives the location (memory address) of the corresponding actual parameter.

Q4) What value is returned by the following return statement? int x = 5;

Return x + 1;

A) 0

B) 5

C) 6

D) 7

Q5) A(n) ____________________ parameter s a formal parameter that receives a copy of the content of the corresponding actual parameter.

To view all questions and flashcards with answers, click on the resource link above. Page 8

Chapter 7: User-Defined

Simple Data Types, Namespaces, and the String Type

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21714

Sample Questions

Q1) In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the problem of overlapping global identifiers.

Q2) Which of the following statements is used to simplify the accessing of all globalType namespace members?

A) using globalType;

B) using namespace globalType:all;

C) using namespace globalType::all;

D) using namespace globalType;

Q3) Suppose str = "abcd"; After the statement str[1] = 'A'; The value of str is "____________________".

Q4) The values in the domain of an enumeration type are called ____________________.

Q5) The data type string has a named constant, ____________________, associated with it.

Q6) The string expression strVar.____________________ inserts all the characters of str at index pos into strVar.

Q7) Suppose str = "abcd". After the statement str = str + "ABCD"; the value of str is "____________________".

Q8) The length of the string "Hello There." is ____________________. Page 9

To view all questions and flashcards with answers, click on the resource link above.

Page 10

Chapter 8: Arrays and Strings

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21715

Sample Questions

Q1) The array index can be any integer less than the array size.

A)True

B)False

Q2) Which of the following correctly declares name to be a character array and stores "William" in it?

A) char name[6] = "William";

B) char name[7] = "William";

C) char name[8] = "William";

D) char name[8] = 'William';

Q3) The following statements store the value ____________________ into len. int len; len = strlen("Sunny California");

Q4) The word ____________________ is used before the array declaration in a function heading to prevent the function from modifying the array.

Q5) If an array index goes out of bounds, the program always terminates in an error. A)True

B)False

Q6) The statement strlen("Marylin Stewart"); returns ____________________.

To view all questions and flashcards with answers, click on the resource link above. Page 11

Chapter 9: Records Structs

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21716

Sample Questions

Q1) Data in a struct variable must be read one member at a time.

A)True

B)False

Q2) The following statement defines a struct houseType with a total of ____________________ member(s).

struct houseType { string style; \(\quad\)int numOfBedrooms; \(\quad\)int numOfBathrooms; \(\quad\)int numOfCarsGarage; \(\quad\)int yearBuilt; };

Q3) Aggregate input/output operations are allowed on a struct variable.

A)True

B)False

Q4) In structs, you access a component by using the struct name together with the relative position of the component.

A)True

B)False

Page 12

To view all questions and flashcards with answers, click on the resource link above.

Chapter 10: Classes and Data Abstraction

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/21717

Sample Questions

Q1) A(n) ____________________ contains the definitions of the functions to implement the operations of an object.

Q2) If an object is created in a user program, then the object can access both the public and private members of the class.

A)True

B)False

Q3) A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function.

A) accessor

B) mutator

C) constructor

D) destructor

Q4) Classes were specifically designed in C++ to handle ____________________.

Q5) A class is an example of a structured data type.

A)True

B)False

Q6) A constructor with no parameters is called the ____________________ constructor.

Q7) Non-static member variables of a class are called the ____________________ variables of the class.

To view all questions and flashcards with answers, click on the resource link above. Page 13

Chapter 11: Inheritance and Composition

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21718

Sample Questions

Q1) Inheritance is an example of a(n) ____ relationship.

A) is-a

B) has-a

C) handshaking

D) had-a

Q2) If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list.

A)True

B)False

Q3) A derived class can directly access the protected members of the base class.

A)True

B)False

Q4) The new classes that we create from existing classes are called ____ classes.

A) sibling

B) base

C) derived

D) parent

Q5) C++ provides ____________________ functions as a means to implement polymorphism in an inheritance hierarchy.

To view all questions and flashcards with answers, click on the resource link above. Page 14

Chapter 12: Pointers, Classes, Virtual Functions, and

Abstract Classes

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21719

Sample Questions

Q1) The dereferencing operator is also known as the indirection operator and refers to the object to which its operand points.

A)True

B)False

Q2) An object of the base class type cannot be passed to a(n) ____________________ parameter of the derived class type.

Q3) The statement int *p; is equivalent to int * p;, which is also equivalent to the statement ____________________.

Q4) In C++, you declare a pointer variable by using the ____ symbol.

A) *

B) &

C) #

D) @

Q5) Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s).

A) one

B) two

C) four

D) eight

Page 15

To view all questions and flashcards with answers, click on the resource link above.

Chapter 13: Overloading and Templates

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21720

Sample Questions

Q1) The operator function that overloads the insertion operator, <<, or the extraction operator, >>, for a class must be a(n) ____________________ function of that class.

Q2) Which of the following is the general syntax of the function prototype to overload the pre-increment operator as a nonmember function?

A) className operator++();

B) friend className operator++();

C) className operator++(int);

D) friend className operator++(className&);

Q3) Suppose cType is a class template, which can take int as a parameter. The statement: ____ declares x to be an object of type cType, and the type passed to the class cType is int.

A) cType&lt;int&gt; x;

B) cType int x;

C) cType int = x;

D) cType int :: x;

Q4) In C++, a function ____________________ can be overloaded.

Q5) To overload a(n) ____________________ operator for a class, if the operator function is a nonmember, it has one parameter.

To view all questions and flashcards with answers, click on the resource link above. Page 16

Chapter 14: Exception Handling

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21721

Sample Questions

Q1) When an exception is thrown in a function, the function-call stack is ____ so that the exception can be caught in the next try/catch block.

A) destroyed

B) allocated

C) unbound

D) unwound

Q2) A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution.

A) crash

B) exception

C) misfire

D) bug

Q3) If no exception is thrown in a try block, all catch blocks associated with that try block are ignored.

A)True

B)False

Q4) In C++, any class can be considered an exception class.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above. Page 17

Chapter 15: Recursion

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21722

Sample Questions

Q1) Consider the following definition of the recursive function print. void print(int num) { \(\quad\)if (num > 0) \(\quad\){

\(\quad\)\(\quad\)cout << num << " "; \(\quad\)\(\quad\)print(num - 1); \(\quad\)}

} What is the output of the following statement? Print(4);

Q2) In the Tower of Hanoi problem, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is ____________________.

Q3) The ____________________ Fibonacci number in a sequence is the sum of the second and third Fibonacci numbers.

To view all questions and flashcards with answers, click on the resource link above.

Page 18

Chapter 16: Searching, Sorting and the Vector Type

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21723

Sample Questions

Q1) The type vector provides the expression ____________________, which returns the last element of the object.

Q2) After the second iteration of bubble sort for a list of length n, the last ____ are sorted.

A) element

B) two elements

C) three elements

D) n-2

Q3) The insertion sort algorithm sorts the list by moving each element to its proper place.

A)True

B)False

Q4) In a bubble sort for list of length n, the first step is to compare elements ____.

A) list[0] and list[n]

B) list[0] and list[n-1]

C) list[0] and list[1]

D) list[n-1] and list[n+1]

Q5) In order to apply a(n) ____________________ search, the list must be sorted.

Q6) The first element in a vector object is at location ____________________.

To view all questions and flashcards with answers, click on the resource link above. Page 19

Chapter 17: Linked Lists

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21724

Sample Questions

Q1) What is the purpose of the following code? current = head; While (current != NULL)

{ //Process current Current = current->link;

}

A) Insertion of a node

B) Selection of a node

C) Traversal of a linked list

D) Creation of a new list

Q2) In a circular linked list with more than one node, it is convenient to make the pointer first point to the ____________________ node of the list.

Q3) A(n) ____________________ is an object that produces each element of a container, such as a linked list, one element at a time.

Q4) A linked list in which the last node points to the first node is called a(n) ____________________ linked list.

Q5) The length of a linked list is the number of nodes in the list. A)True B)False

To view all questions and flashcards with answers, click on the resource link above. Page 20

Chapter 18: Stacks and Queues

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/21725

Sample Questions

Q1) Postfix notation requires the use of parentheses to enforce operator precedence. A)True

B)False

Q2) The infix expression (a + b) * (c - d / e) + f is equivalent to the postfix expression ab + cde /-* f + A)True

B)False

Q3) The default constructor for the linked implementation of a stack initializes the stack to an empty state when a stack object is declared. A)True

B)False

Q4) The elements at the ____________________ of the stack have been in the stack the longest.

Q5) The postfix expression 2 4 6 * + 15 - 21 7 / + = evaluates to ____.

A) 4

B) 14

C) 24

D) 26

Page 21

To view all questions and flashcards with answers, click on the resource link above.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.