






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
A set of multiple-choice questions and answers related to data structures, focusing on recursion, algorithm analysis, and stacks. It covers topics such as adt specifications, primitive data types in c++, recursive solutions, class constructs, factorial computation, recursive functions, algorithm complexity, stack operations (push, pop, top), and stack applications. The questions are designed to test understanding of fundamental concepts and their practical implications in software development. This material is useful for exam preparation and reinforcing key concepts in data structures. (410 characters)
Typology: Exams
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Data structures can be said to be an ADT's ______. 1 specifications 2 implementation 3 abstraction 4 definition - correct answers 2 implementation The specifications of an ADT's operations indicate ______. 1 what the operations do 2 how to store the data in the ADT 3 how to carry out the operations 4 how to implement the operations - correct answers 2 what the operations do Which of the following is not an primitive data type in C++? 1 string 2 char 3 bool 4 double - correct answers 1 string In a recursive solution to a problem, we solve a problem P(n) by solving another problem P(k) where
1 P(k) is smaller than P(n) 2 P(k) is same as P(n) 3 P(k) is the hardest part of P(n) 4 P(k) is a larger problem than P(n) - correct answers 1 P(k) is smaller than P(n) A(n) ______ is a C++ construct that enables a programmer to define a new data type. 1 data field 2 object 3 method 4 class - correct answers 4 class The function int fact (int k) { return k * fact(k-1); if (k == 0) return 1; } 1 computes the factorial on an integer k passed to it as parameter 2 works for all non-negative values of k, but not for negative numbers. 3 returns the value 1 if it is passed a value of 0 for the parameter k 4 does not correctly handle its base case - correct answers 4 does not correctly handle its base case When a function contains a function call to itself, such function is _____.
2 This is an infinite recursion 3 8 4 2 - correct answers 2 This is an infinite recursion When an algorithm has an upper limit to the number of instructions, regardless of the size of n, it is referred to as a(n) ______________ algorithm. 1 limited 2 time complex 3 constant time 4 instruction-truncated - correct answers 3 constant time A stack is initially empty, then the following commands are performed: push 7, push 5, pop, push 10, pop, push 6 which of the following is the correct stack after those commands (assume the top of the stack is on the left)? 1 6 7 2 6 10 5 7 3 6 10 4 10 7 - correct answers 1 6 7 If the array 6, 2, 7, 13, 8, 5
is added to a stack, in the order given, which number will be the first number to be removed from the stack? 1 8 2 2 3 6 4 5 - correct answers 4 5 Which of the following is a good analogy of the ADT Stack? 1 a group of people playing musical chairs 2 a paper bag with colored poker chips 3 a pile of textbooks on your desk 4 people standing in a cafeteria line - correct answers 3 a pile of textbooks on your desk We can measure the complexity of an algorithm that solves a computational problem by determining the number of ___ for an input of size n. 1 basic steps it requires 2 output statements it has 3 input statements it has 4 variables it uses - correct answers 1 basic steps it requires All of the following operations of the ADT stack take no parameters except? 1 pop 2 push 3 isEmpty 4 top or peek - correct answers 2 push
3 push 4 pop - correct answers 1 top or peek Software must make efficient use of resources such as _______ and _______ . 1 Memory, Hard Drive 2 CPU time, Memory 3 Hard Drive, Video Card 4 CPU time, Video Card - correct answers 2 CPU time, Memory If keyboard entry is treated as an stack ADT and the backspace key is pressed when the stack ADT is empty, which of the following is the most reasonable action for the stack ADT to take? 1 display an error message 2 ignore the backspace and continue 3 display a symbol for the backspace 4 terminate the program and write an error message - correct answers 2 ignore the backspace and continue A ______ can be used to reverse the order of a set of data. 1 Stack 2 Software 3 Heaps 4 Queue - correct answers 1 Stack What behavior does the ADT stack exhibit?
1 first in, first out 2 last-in, first-out 3 first in, never out 4 last in, last out - correct answers 2 last-in, first-out A recursive function should be designed to stop making recursive calls when it reaches its 1 base case 2 last parameter 3 closing curly brace 4 return statement - correct answers 1 base case Which of the following construct does not allow programmer to define a new type in C++? 1 struct 2 array 3 class 4 typedef - correct answers 2 array The ______ operation of the ADT stack retrieves and then removes the top of the stack. 1 pop 2 getTop 3 createStack 4 push - correct answers 1 pop
The ______ operation of the ADT stack adds an item to the top of the stack. 1 push 2 pop 3 getTop 4 createStack - correct answers 1 push If you implement a stack using an array, where would be the more appropriate place for the bottom element of the stack? 1 mid array for a binary search 2 at the end of the array 3 at the first element of the array 4 it doesn't matter - correct answers 3 at the first element of the array