CSC-231: Introduction to Data Structures

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

The efficiency of an algorithm is determined by...

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

Big-O notation

The rate of growth. In other words, how quickly an algorithm's execution time increases as the size of the input increases.

For a given class...

There can be multiple levels of subclasses

Two methods that are implemented to display the value of a given object:

__str__ and __repr__

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

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

What are the three laws of recursion?

1. A recursive function must call itself. 2. Every recursive function must have a base case. 3. Every recursive function must work towards its base case

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: 24 12/\26 11/\16 13/ If we remove the root node, which of the node from the left subtree will be the new root?

16

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

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?

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

What is the output of the following code? a = 20 b = 30 assert b - a , 'a is smaller than b' print(b)

30

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

3: self.data, self.prev, and self.next

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

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:

4

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 times

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

Abstract Data Type

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

Algorithm

A step-by-step list of instructions for solving any instance of a problem that might arise.

What is Algorithm Analysis?

Algorithm analysis is an implementation-independent way of measuring an algorithm. Big-O notation allows algorithms to be classified by their dominant process with respect to the size of the problem.

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

All O(n)

Another name for a subclass is a:

Child Class

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

Encapsulation, Inheritance, and Polymorphism

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 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 Big-O running time for the following?: T(n) = 12n^3+8n+3

O(n^3)

All values in Python are represented as...

Objects

Another name for a superclass is a...

Parent class/ Base class

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

abstract class

"Front" of the deque is the end of the list: add_front(item): O(?) add_rear(item): O(?) remove_front(): O(?) remove_rear(): O(?)

add_front(item): O(1) add_rear(item): O(n) remove_front(): O(1) remove_rear(): O(n)

"Front" of the deque is index 0 of the list add_front(item): O(?) add_rear(item): O(?) remove_front(): O(?) remove_rear(): O(?)

add_front(item): O(n) add_rear(item): O(1) remove_front(): O(n) remove_rear(): O(1)

"Front" of the queue is index 0 of the list: enqueue(item): O(?) dequeue(): O(?)

enqueue(item): O(1) dequeue(): O(n)

"Front" of the queue is the end of the list: enqueue(item): O(?) dequeue(): O(?)

enqueue(item): O(n) dequeue(): O(1)

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

executes quickly.

members of a class being made inaccessible to ("hidden from") its clients, referred to as:

information hiding

peek()

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

A problem solved with recursion can also be solved using..

iteration and vice versa

Getters and setters

methods providing controlled access to private instance variables

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

n

Consider a situation where the swap operation is very costly. Which sorting algorithm 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

A data item entered into a linear data structure...

stays in that position relative to the other elements that came before and after it.

Algorithm analysis is not concerned with...

the number of lines of code written in a program.

What is the output of the following code? try: print('try') except ValueError: print('ValueError') finally: print('finally')

try finally

Which of the following is not a stable sorting algorithm in its typical implementation? a. merge sort b. bubble sort c. quick sort d. insertion sort

c. quick sort

Suppose you have the following series of queue operations: q = Queue() q.enqueue('hello') q.enqueue('dog') q.enqueue(3) q.dequeue() What items are left in the queue?

'dog',3

What is the result of evaluating the following: 17 10 + 3 * 9 / ==

(17 + 10) * 3 /9 == 9

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)

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 Which number could be chosen for the pivot?

(The pivot could be either the 7 or the 9

An object contains a set of attributes, stored in a set of___________, and a set of functions called_____________ that provide its behavior.

Instance Variables, Methods

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') What items are left on the deque? (Read as Rear is the left and Front is the right

Fran,Charles,Alice,Bob

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

In-order

Which data structure uses the First-In-First-Out(FIFO) method?

Queue

Which data structure uses the First-In-Last-Out(FILO) method?

Stack

test = 0 for i in range(n): for j in range(n): test = test + i * j What is the T(n) for the above code?

T(n) = 1 + n + (n*j) + (n*j*1) T(n) = 2n^2 + n + 1

Convert the following infix expression to postfix : 10 + 3 * 5 / (16 - 4)

The easiest way for me to think about this is to add additional parentheses based on the order of operations. 10 +( (3*5) / (16 - 4) ) - so you know the 3 * 5 becomes 3 5 * - also the 16 - 4 becomes 16 4 - - those two pieces are what is divided -> 3 5 * 16 4 - / - then that entire piece is added to the 10 10 3 5 * 16 4 - / +

Private members of a class in Python

begin with 2 underscores.

Special methods in Python correspond to

both arithmetic and relational operators.

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 ? a. Insertion at the front of the linked list b. Insertion at the end of the linked list c. deletion of the front node of the linked list d. deletion of the last node of the linked list

d. deletion of the last node of the linked list


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

ATI Endocrine N180 Pharmacology Made Easy 4.0

View Set

chapter 3 - Health , Illness and disparities

View Set

Chapter 6: Variable Costing & Segment Reporting Accounting Terms

View Set

Field Tech III - IV Conventional

View Set