QUESTIONS AND CORRECT ANSWERS
(VERIFIED ANSWERS); A GRADE
__init__ - correct answer- instantiation of a class
automatically calls this method defined in the class def
this is also known as the constructor
(high + low)/2 - correct answer- mid-values
calculation for binary search. toCeil()
// - correct answer- symbol for floored division
Add(int index, Object x) - correct answer- command
that inserts object x at position index in a list
ADT (Abstract data Type) - correct answer- data type
described by predefined user operations, such as "insert data at
rear", without indication how each operation is implemented
,array - correct answer- a data structure that stores
an ordered list of items, with each item is directly accessible by a
positional index
homogeneous data elements
assignment - correct answer- type of operation for
setting a var
Bag - correct answer- ADT for stroing items in which
the order does not matter and duplicate items are allowed
binary tree - correct answer- A data structure that
consists of nodes, with one root node at the base of the tree,
and two nodes (left child and right child) extending from the
root, and from each child node
can have no children, single left or right, or both right and left
bubble sort - correct answer- for i from 0 to N -1
if a[i] > a[i+1]
swap(a[i], a[i +1]
, end for
Bubble Sort Algorithm - correct answer- def
shortSort(alist):
exchanges = True
passnum = len(alist)-1
while passnum > 0 and exchanges:
exchanges = False
for i in range(passnum):
if alist[i]>alist[i+1]:
exchanges = True
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
passnum = passnum-1
bucket sort - correct answer- Best: O(n+k)
Avg: O(n+k)
Worst: O(n^2)
Space: O(nk)