Intro Algorithms Exam 1

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

What is the output of the following? True = False while True: print(True) break

Not true or false: NONE

What is sorting?

Sorting refers to arranging data in a particular format. Sorting algorithm specifies the way to arrange data in a particular order. Most common orders are in numerical or lexicographical order.

What is the difference between in-place sorting and not-in-place sorting?

- Sorting algorithms may require some extra space for comparison and temporary storage of few data elements. These algorithms do not require any extra space and sorting is said to happen in-place, or for example, within the array itself. This is called in-place sorting. Bubble sort for example. - However in some sorting algorithms, the program requires space which is more than or equal to the elements being sorted.

How does selection sort work?

1. Finds the smallest element in the list and swaps it with the element in the first position. 2. Then it finds the second smallest element and swaps it with the element in the second position. 3. It does this until we reach the last position.

How does bubble sort work?

1. Going left to right, you compare consecutive elements. 2. Whenever two are out of place, you swap them. At the end of a single iteration, the max element is in the last spot. 3. This repeats n times. 4. On each pass, the maximal element is moved to its correct spot at the end, as if the maximum is "bubbling up".

How does insertion sort work?

1. Starting with the second element, you go one-by-one and insert it (by swapping) into the already sorted list to its left in the correct order. 2. So by the time you reach the end of the list, it will put the last element where it should be and then the list is sorted.

Consider the usual algorithm for determining whether a sequence of parentheses is balanced.The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(())) are:

3

The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How many iterations will be done to sort the array with improvised version?

4

What is a process?

A process is a sequence of activities actually being executed, to solve a problem.

What is a brute force algorithm?

A straightforward approach usually based on problem statement and definitions

What are algorithms and programs?

Algorithm and programs are just descriptions of a process in some notation.

What is the definition of an algorithm?

An algorithm is a description or statement of a sequence of activities that constitute a process of getting the desired outputs from the given inputs.

How does output work in algorithms?

An algorithm must have at least one desirable outcome.

How do inputs play a role in algorithms?

An algorithm must have zero or more but must be finite number of inputs.

How does effectiveness work in algorithms?

An algorithm should be effective. Effective means that each step should be referred as principle and should be executing in finite time.

How does finiteness work in algorithms?

An algorithm should terminate infinite number of steps and each step must finish in finite amount of time.

What best describes an array?

Container of objects of similar types

What is the best case efficiency of bubble sort in the improvised version?

O(n)

What is the worst case complexity of bubble sort?

O(n^2)

What is the time complexity of Insertion Sort?

O(n^2) Big-Omega of n

What is the time complexity of Selection Sort?

O(n^2) Big-Omega of n^2

What is the time complexity of Quicksort?

O(n^2) big-Omega of nlogn

What is the time complexity of Bubble sort?

O(n^2) because 2 for loops Big-Omega of n

What is the time complexity of merge sort?

O(nlogn) Big-Omega of nlogn

Which sorting algorithm is usually not a stable sorting algorithm?

Quicksort

What are the advantages of arrays?

a) Easier to store elements of same data type b) Used to implement other data structures like stack and queue c) Convenient way to represent matrices as a 2D array

What are the disadvantages of arrays?

a) We must know before hand how many elements will be there in the array b) There are chances of wastage of memory space if elements inserted in an array are lesser than than the allocated size c) Insertion and deletion becomes tedious

print(0xA + 0xB + 0xC)

33

What is the advantage of bubble sort over other sorting techniques?

Detects whether the input is already sorted

How does definiteness work in algorithms?

Each step of algorithm should be clearly and precisely define and there should mot be any ambiguity.

What recurrence relation can be used to find the nth fibonacci number?

F(n) = F(n - 1) + F(n - 2)

What are the characteristics of algorithms?

Input specified. Output specified. Definiteness. Effectiveness. Finiteness.

What are the weaknesses of brute force algorithms?

rarely yields efficient algorithms•some brute force algorithms unacceptably slow•not as constructive/creative as some other design techniques

What arithmetic operators cannot be used with strings?

-

What is the difference between stable and not-stable sorting?

- If a sorting algorithm, after sorting the contents, does not change the sequence of similar content in which they appear, it is called stable sorting. If a sorting algorithm, after sorting the contents, changes the sequence of similar content in which they appear, it is called unstable sorting

Suppose the first fibonnaci number is 0 and the second is 1. What is the sixth fibonnaci number?

5


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

Chapter 2: The Chemical Context of Life (Multiple-Choice Questions)

View Set

Chapter 4: Purposes of Texts and Graphic Sources

View Set

ISYS 316 Advanced Java Programming Chapter 32 Java Database Programming

View Set