Comp 285 Test 1 study guide

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

ctr = 0 while ( ctr < N ) { myAge = ctr val = ctr + 1 while ( val < N ) { if ( age OfPeople [ val ] < ageOfPeople [ myAge ] ) myAge = val ++ val } tempList ageOfPeople [ ctr ] ageOfPeople [ ctr ] = ageOfPeople [ myAge ] ageOfPeople [ myAge ] = tempList ++ ctr }

0 ( N2 )

The Big O notation of the composite function 5 N 3 + 0 ( N2 ) is_

0 ( N3 )

Identify the correct sequence of performing a binary search .

1. Binary search first checks the middle element of the list . 2. If the search key is not found , the algorithm : i checks the left sublist if the search key is less ii . checks the right sublist if the search key is greater than the middle element or than the middle element .

The upper bound of an algorithm with best case runtime T ( N ) = 3 N + 16 and worst case runtime T ( N ) = 4 N2 + 10 N + 5 is

19 N 2

Which abstract data type ( ADT ) is suited to check whether a given string is a palindrome ?

A deque

Which is an abstract data type ( ADT ) ?

A list

Which abstract data type ( ADT ) is best suited to store the names of all currently available smartphone models ?

A set

Which of the following statements is true with reference to an algorithm's runtime ?

A single algorithm can execute more quickly on a faster processor .

Which of the following is best represented by a graph ?

A telephone network .

Which of the following is an example of constant time O ( 1 ) ?

Accessing an element of an array

Which of the following is correct for a list ADT ?

An element can be found and removed from the end of the list .

A list of employees that has been sorted in descending order needs to be reversed . Which XXX completes the algorithm to sort the list in ascending order ? AscendingList ( empList , begin , end ) { if ( begin > = end ) return . else ( Swap empList [ begin ] and empList [ end ] XXX } }

AscendingList ( empList , begin + 1 , end - 1 )

A manufacturing plant has many ways to assemble a product . Which algorithm will be useful to find the quickest way ?

Dijkstra's shortest path

ADTS allow programmers to

Focus on higher level operations as per a program's needs

Which XXX base case completes the algorithm to count the number of occurrences of a value in a list of numbers ? CountOccurrences ( numbers , numbersLength , value , startindex ) { XXX if ( numbers [ startindex ] == value ) return 1+ CountOccurrences ( numbers , numbersLength , value , startindex + 1 ) else return CountOccurrences ( numbers , numbersLength , value , startindex + 1 ) }

If(startIndex>= numbersLength) return 0

Which of the following algorithms is correct for applying linear search to find the element findEle in a list StudentlDs ?

LinearSearch ( StudentIDs , int listSize , int findEle ) { for ( ctr = 0 ; i < listSize ; ++ ctr ) { if ( StudentIDs [ findEle ] == ctr ) return findEle } }

Which algorithm is best suited for a plagiarism check ?

Longest common substring

Which of the following is an example of a recursive function ?

MySalaryCalculator ( tempSal ) { if ( tempSal < = 500 ) return -1 else tempSal = tempSal + 1000 }

An algorithm that uses a constant number k of integer variables to find a number list's minimum value has space complexity S ( N ) = ________ and auxiliary space complexity S ( N ) =

N,k

The Big O notation of the algorithm 7+ 12 N +3 N 2 is

N. 2

An algorithm is written to return the first name beginning with " L " in a list of employee names . Which of the following is the algorithm's worst case scenario ?

No names in the list begin with " L "

What is the space complexity the algorithm ? ArithmeticSeries (list listSize ) { i = 0 arithmeticSum = 0 while ( i < listSize ) { arithmeticSum arithmeticSum + list [ i ] i = i + 1 } return arithmeticSum }

S ( N ) = N + k

Identify the notation for algorithm complexity that has a positive constant c for all T ( N ) 2 c f ( N ) .

T ( N ) = Q ( f ( N ) )

Which of the following statements is correct ?

The list ADT supports the printing of the list contents but the queue ADT does not

Which of the following is the main requirement for a binary search algorithm ?

The list must be sorted in ascending order .

Which XXX completes the binary search algorithm ? BinarySearch ( numbers , numbersSize , key ) { mid = 0 low = 0 high numbersSize - 1 XXX { mid = ( high + low ) / 2 f ( numbers [ mid ] < key ) { low = mid + 1 else if ( numbers [ mid ] > key ) { high = mid - 1 else { return mid return -1

While(high>=low)

What values are stored in the list numList ? numberList ( ) { for ( i = 0 ; i < 10 ; i ++ ) { if ( i % 2 == 0 ) { numList [ i ] = i } } }

[0 , 2 , 4 , 6 , 8 ]

A ( n ) . is a function f ( N ) that is defined in terms of the same function and operates on a value less than N.

a . recurrence relation

The process of providing only the essentials and hiding the details is known as

abstraction

The following algorithm is an example of def MyMath ( num ) if num < = 1 return num return MyMath ( num - 2 ) + MyMath ( num - 1 )

an exponential runtime complexity

An algorithm's is the scenario where the algorithm does the minimum possible number of operations .

best case

Given the following code for generating the Fibonacci series for N numbers which XXX would replace the missing statement ? FibonacciNumber ( N ) { XXX return 0 else if ( N == 1 ) return 1 else return FibonacciNumber ( N - 1 ) + FibonacciNumber ( N - 2 ) }

if ( N == 0 )

Which XXX will complete the algorithm to separate numberList into two lists ( even and odd ) using an array ? MathematicalFunction ( numberList ) { Create evenNumberList array Create oddNumberList array for ( i = 0 ; i < numberList - >length ; ++i){ XXX { ArrayAppend ( evenNumberList , numberList [ i ] ) } else { ArrayAppend ( oddNumberList , numberList [ i ] ) } SortAscending ( evenNumberList ) SortAscending ( oddNumberList ) } for ( i = 0 ; i < evenNumberList - length ; ++ i ) { Display evenNumberList [ i ] } for ( i = 0 ; i < oddNumberList - length ; ++ i ) { Display oddNumberList [ i ] } }

if ( numberList [ i ] % 2 == 0 )

A stack abstract data type ( ADT ) is implemented using a ( n ) _____data structure .

linked list

second recursive call ? Given a list ( 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 17 ) the binary search algorithm calls Binary Search ( list , 0 , 8 , 5 ) . What will the low and high argument values be for the

low =5 , high = 8

In a linked list , each node stores a _____the next node .

pointer to

Which data type is best suited to store the names and grades of students ?

record

Appending an element in an array involves increasing the array's

size

In a recursive function , the base case the function .

terminates

The worst - case runtime of an algorithm is number of steps taken to execute a program .

the maximum


Set pelajaran terkait

Thermodynamics ASEN 2002- Exam 1

View Set

Financial Markets and instituitions

View Set

Lesson 2 - Introduction to Forms of Energy

View Set

Basic Livestock Nutrition - Assessment V

View Set