COSC 2436

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

When implementing a heap using a Python list , what are the indices for the root and its left and right node

0 1 2

What is the output of the following code segment ? tuple_obj obj=(35,[1,(10,20),3] , ' python , (4,5,6)) print (tuple_obj \ obj[1][1][0])

10

How many loops are found in a typical insertion sort ?

2

What is the output after the following code segment is executed? table = [[1, 2, 3], [4, 5, 6, 7]] print (len(table), en * (table * [1]) , sep=" )

2,4

Which of the following lists does not represent a heap ?

2,5,7,10,8,11,9

How many iterations does the following code segment have if n = 20 ? What is the time complexity? for k in range (0, n) for i in range(, n: for j in range (0, n) : print * (k, i, j)

20^3, O(n^3)

What is the output after the following code segment is executed ? table=[[1,2,3,4] , [4, 5, 6, 7]; [8, 9, 10, 11] , [12,13,14,15]] for row in range * (0, 4) print ( table * [1] row , end = ' ')

4 5 6 7

What is the output after the following code snippet executed ? original_set = { 5, 10 , 15, 20, 25} new_set = x * 5 for x in original_set if x > 10 print (new_set )

75, 100, 125

Which of the following is an example of a stack in everyday life?

A spindle of blank DVDs

A binary search tree can contain duplicate items .

False

When adding /removing data from queues , what data operation method does Stack structure use

First in first out (FIFO )

The time complexity of the binary search algorithm is

O(log n )

The time complexity of merge sort algorithm is

O(n * log n)

The time complexity for the worst case to search an item in the binary search tree is

O(n)

The time complexity of the linear search algorithm is

O(n)

The time complexity of the worst case to insert or delete a node in a binary search tree is

O(n)

What is the time complexity of traversing a tree in any order ?

O(n)

What is the order of growth for the following function ? 2 ^ 3 + 1000n ^ 2 + 10n

O(n^2)

What is the time complexity for the following loop? for i in ange * (n) : for j in range * (n) : total = i + j

O(n^2)

The __next__() method that raises a exception after all elements are iterated

Stoplteration

What is the output after the following code segment is executed ? class Super : def __init __ (self ) print ("Superclass's ) class Sub (Super ) : def __init __ (self ) super ( ). __init __ () print ("Subclass's __init__ ") sub=sub()

Superclass's __init__ Subclass's init

One of the advantages using doubly linked list is:

You can access the previous node from the current node .

What is the output of the following code segment ? 'Full Stack Developer'split ()

['full', 'stack','developer']

If the current state of the stack is [10, 20, 15] where 15 is the bottom of the stack and 10 is the top of the stack, what is the state of the stack and the value returned after a pop operation?

[20,15], 10 is returned

What is output of the followirg segment ? list1=[5,7]; list2=list1; list1[1]=12 print t(list2)

[5,12]

What is the output after the following code segment is executed ? multi list=[[num,num+1 num + 2] for num in range(0,2)] print(multi_list )

[[0,1,2],[1,2,3]]

What is the output after the code segment executed ? import math numbers=\ 49:7,9:3,25:5\ } sqrt value=\ math.sqrt(x):x for x in numbers.keys ( )} print (sqrt_value )

\ 7.0:49,3.0:9,5.0:25\ }

Which of the following scenarios best represents a queue ?

a line from grocery checkout lines

an input that results in the shortest execution time is ___An input that results in the longest execution time is called the called the ___input .

best, worst

LinkedStack is a stack class which is implemented using linked list structure . Define the LinkedStack class with the following methods : _init_0 ) push (), pop (), peek( ), clear ), is_empty ( ) and __str_0 . LinkedList class is provided for reference . *** The linked_list.py file is attached in this quiz. of characters that

class LinkedStack : def __init__(self ): self.top=None self.element= [] def_str __ ( self ) current = self.top result " [" while temp : result.append (str(current.element )) current=current.nex if current != None : result += "- > else : result +=^ prime prime ]^ prime prime def is_empty (self ) return len (self.element ) == def peek (self ) return self.top.element def push (self , element ): if self.top == None: self.top=; =Node(elemen ) else: new_node Node (element )

Create a Node class to handles doubly linked list. A doubly linked list can be traversed both ways (forward and backward). class Node: def init - (self,e) : # your code here

class Node : def __init __ (self , e ) : self.prev=None self.element=e self.next=None

The following code segment searches an item in a linked list. Fill in the code on line 3 to complete the code segment. 1current = head 2 while current !None and search_item !current data: 3 # your code here 4if current != None: 5 print(' Search item found!") 6else: 7print ('Search item not found!')

current = current.next

Write a function is_palindrome) which checks for the string passed in is palindrome or not. A palindrome is a sequence of characters that reads the same backward as forward, such as civic, madam, noon, etc. You will create an object of LinkedStack class from previous question to test whether a string passed in is palindrome. This function returns True if it is palindrome, False otherwise. Call the function to display the result .

def is palindrome ( string) : left = 0; right = len * (string) - 1 while right >= left: if not string[left]==string[rig| ] return False left +=1 right -= 1 retun True S=LinkedStack() S.push(' m') S.push('a') S.push('d') S.push('a') S.push('m ') print ( is_palindrome ())

student = {1: 'name: 'Mary'age: 27'major':'Accounting',: 'name': 'John', 'age: 19, major:'}} Based on the code snippet above, which statement is the correct way to remove student Mary?

del student [1]

When adding data to queues , what method is used ?

enqueue

Quadratic time means that the time complexity is O(2^ ^ n) .

false

The following code segment correctly defines a Number class and creates a Number object . class Number def __init (self, num ) self.num = num num_object Number()

false

Which sort algorithm involves building a data structure from a list and then utilizing it to sort the list

heap sort, heap

The ___of a nonempty tree is the length of the path from the root node to its furthest leaf. It is -1 for an empty

height

Which of the following is NOT true of a priority queue ?

items of equal priority are dequeued in LIFO order

What is the output after the following codes executed ? first_names = ('Jerry ', 'Amy ') full_name = tuple (name + ' Johnson ' for name in first_names if not name== ^ prime prime ) print (full_name )

jerry johnson, amy johnson

A node without children is called a

leaf

In what way doesn't the Python list data structure accurately emulate a stack ?

list methods allow manipulation of items at any position

The algorithm divides the list into two halves and applies the same sort algorithm on each half recursively. After the two halves are sorted, they are combined into one list

merge sort

To apply a bubble sort to a sorted list with n elements, how many comparisons will it perform?

n-1

In merge sort the recursive call continues dividing the list into sublists until each sublist contains only__elements

one

In quick sort algorithm, an called is selected from the list to help the partition of the list. The list is divided into two part one part contains the elements with less or equal values and the other part contains the elements with larger values

pivot

Which traversal is to visit the left subtree of the current node recursively , then the right subtree of the current node recursively , and finally the current node ?

postorder

You are implementing a Heap class using Python list, which statement is correct to initialize a Heap object? def __init__ (self): # your code here

self.__lst =[]

What is the output of the following code snippet ? print(fHowdy^ prime ) delta [Greeting ')

set()

The measures the amount of memory space used by an algorithm

spqce complexity

What term best describes the following code ? a - list[i] , a - list[j]=a - list[j] , a - list[i]

swap function

test_tuple = (' Tuple') print(type test_tuple # output : < class 'str'> The above code segment displays the type of test_tuple as string instead of tuple. Which of the following answer can fix the problem , so that test_tuple is type of tuple. ( Choose two answers)

test_tuple = ('Tuple ) test_tuple =tuple( 'Tuple ')

dict1=\ states^ prime :\ tx^ prime :\ ^ prime cc county ':{' name': ' harris ', ' school_district :22 }}}} From the above code snippet , which statement is correct to retrieve the value of school_district ?

total_sd = dict1['states ']['tx']['county ''school_district ')

O(1) represents constant time which means the running time is not affected by input size.

true

What is the output of the following code snippet ? num=\ 1,2,3\ print (num.issuperset ( num),num.issubset(num ))

true true

What is the output after the following code executed ? print(\ 11,12,13,14,15\ ^\ 15,16,17\ -\ 11,31\ )

{11,12,13,14,16,17}


Kaugnay na mga set ng pag-aaral

Chapter 3: Early Empires in the Ancient Near East

View Set

Term exam 1 (Ch 1, 2, 3, 4, 11, 12)

View Set

Vsim Carla Hernandez Pre/Post-test

View Set

Psychology Topic 2: Intelligence

View Set

Substance Use Disorders Diagnosis

View Set

Atome/molecule/intrant extrant/mélange/shema de principe/shema de construction/ tableau périodique/ changement

View Set