CSC 231 Quizzes

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Suppose we are sorting an array of eight integers using quicksort, and we have just finished the partitioning with the array looking like this: 2 5 1 7 9 12 11 10 What is true?

The pivot could be either the 7 or the 9

True or False: A class can be used to make as many object instances of that type as needed.

True

True or False: A data item entered into a linear data structure stays in that position relative to the other elements that came before and after it.

True

True or False: A problem solved with recursion can also be solved using iteration.

True

True or False: An algorithm is a step-by-step list of instructions for solving any instance of a problem that might arise.

True

True or False: Big-O notation refers to the rate of growth. In other words, how quickly an algorithm's time increases as the size of the input increases.

True

True or False: Getters and setters are methods providing controlled access to private instance variables

True

True or False: There are special methods in Python corresponding to both arithmetic and relational operators.

True

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?

0 1 2 3 4 5 6 7 8 9

Assume that we use Bubble Sort to sort n distinct elements in ascending order. When does the best case of Bubble Sort occur?

When elements are sorted in ascending order

What is the name of the special method used to initialize instance variables?

__init__

Consider the following operation performed on a stack of size 5. Push(1); Pop(); Push(2); Push(3); Pop(); Push(4); Pop(); Pop(); Push(5); After the completion of all operation, the number of elements present on stack are

1

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

15, 10, 23, 25, 20, 35, 42, 39, 30

Consider the following binary search tree: If we remove the root node, which of the node from the left subtree will be the new root?

16

In a doubly linked list, the number of pointers affected for an insertion operation at the beginning or end of a doubly linked list will be

2

What does the following line of code display? print(7//3)

2

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16 What is the height of the binary search tree ?

3

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?

3

The minimum number of fields or instance variables with each node of a doubly linked list is

3

What is the output of the following code? def some_func(n): if n <= 1: return n else: return(some_func(n-1) + some_func(n-2)) print(some_func(4))

3

Postorder traversal of a given binary search tree T produces following sequence of keys: 3, 5, 7, 9, 4, 17, 16, 20, 18, 15, 14 Which one of the following sequences of keys can be the result of an in-order traversal of the tree T?

3, 4, 5, 7, 9, 14, 15, 16, 17, 18, 20

In a doubly linked list, the number of pointers affected for an insertion operation in the middle of the doubly linked list will be

4

Examine the following Python code, numList = [1, 3, 6, 7, 10, 3, 12]for k in range(0, (len(numList)-2)): print(numList[k]) How many times does the above loop iterate?

5

While inserting the elements 71, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in the sequence shown, the element in the lowest level is

67

What are the three laws of recursion?

A recursive algorithm must call itself recursively, must have a base case, and must change its state and move toward the base case.

An ____________________ is a logical description of how we view the data and the operations that are allowed without regard to how they will be implemented.

Abstract Data Type

The process of combining multiple sequences (strings) together using the + operator is called ____________________.

Concatenation

What is the Best Case Running time complexity we could get for bubble sort?

N

What is the Big-O running time for the following code fragment? i = n while i > 0: k = 2 + 2 i = i // 2

O(log n)

What is the Big-O running time for the following T(n) = 12n^3+8n+3

O(n log n)

What is the Big-O running time for the following code fragment? test = 0 for i in range(n): test = test + 1 for j in range(n): test = test - 1

O(n)

What is the worst case running time for search, insert and delete operations in a general binary search tree?

O(n) for all

Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort?

O(n^2)

You have an array of n elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is

O(n^2)

The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:

O(n^2), O(n log n) and O(n^2)

What is the Big-O running time for the following code fragment? for i in range(n): for j in range(n): for k in range(n): k = 2 + 2

O(n^3)

All values in Python are represented as ___________.

Objects

A class with one or more unimplemented methods is called an _____________ class.

abstract

In algorithm analysis, we say that an efficient algorithm is one that ________.

executes quickly

Which of the following is CORRECT Python syntax for defining a set?

fruit = {'apple' , 'banana' , 'pear' , 'peach'}

Which of the following sorting algorithms has the lowest worst-case complexity?

merge sort

Which of the following is true about merge sort?

merge sort works better than quick sort if data is accessed from slow sequential memory merge sort outperforms bubble sort is most practical situations. merge sort is a stable sort by nature

In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is

n

What method is used to view the next element to be removed from a stack?

nextItem()

Another name for a superclass is a __________ class.

parent or base

The three fundamental features of an object-oriented programming language that support object-oriented development are

polymorphism, encapsulation, inheritance

Which of the following is not a stable sorting algorithm in its typical implementation?

quick sort

Which of the following is CORRECT Python syntax for defining a dictionary?

rainfall = {'mon' : 3.2 , 'tue' : 0.9, 'wed' : 1.3, 'thur' : 0.4, 'fri' : 0.0}

Consider a situation where the swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general?

selection sort

Functions in Python meant to serve as methods of a particular class must have an added first parameter, by convention named ________________.

self

The efficiency of an algorithm is determined by which of the following? Select all that apply

the size of the input to the program and the number of steps in an algorithm

Another name for a subclass is a __________ class.

child or derived

Suppose you have the following series of queue operations. q = Queue() q.enqueue('hello') q.enqueue('dog') q.enqueue(3) q.dequeue()

'hello",dog'

A binary search tree is generated by inserting in order the following integers: 50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24 The number of nodes in the left subtree and right subtree of the root respectively is

(7,4)

True or False: A tuple is mutable.

False

True or False: Algorithm analysis is concerned with the number of lines of code written in a program.

False

True or False: Private members of a class in Python begin and end with two underscore characters.

False

Put the following O(f(n)) values in order from best (fastest) to worst (slowest):

Fastest to Slowest: O(1) O(log n) O(n) O(n log n) O(n^2) O(n!)

Suppose you have the following series of deque operations. d = Deque() d.add_front('Alice') d.add_front('Bob') d.add_rear('Charles') d.add_rear('Daniella') d.add_front('Erin') d.remove_rear() d.remove_front() d.add_rear('Fran')

Fran, Charles, Alice, Bob

Which of the following traversal outputs the data in sorted order in a BST?

Inorder

Which of the following uses the FIFO method?

Queue

Consider an implementation of an unsorted singly linked list. Suppose it has its representation with a head and a tail pointer (i.e. pointers to the first and last nodes of the linked list). (Reminder: single linked list does not have a built in previous pointer). Given the representation, which of the following operation can not be implemented in O(1) time ?

deletion of the last node of the linked list


Set pelajaran terkait

E2, Next Move 2, Unit 5 Personality Adjectives

View Set

Chapter 53: Drug Therapy for Seizure Disorders and Spasticity, Pharmacology Drug Therapy for Seizure Disorders and Skeletal Muscle Disorders, Chapter 53: Drug Therapy for Seizure Disorders and Spasticity, Drug therapy for seizure disorders and spasti…

View Set

Lecture 12: epigenetic mechanism of gene regulation

View Set

PrepU Ch 37: Management of Patients with Musculoskeletal Trauma

View Set

Merrill's Ch. 17 - Liver & Biliary System

View Set

MARKETING COMMUNICATIONS: CHAPTER 9

View Set

Business Law 2 Ch. 20 True & False

View Set

Federal Tax Considerations for Life Insurance and Annuities

View Set