Unit 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Merge sort

1. Divide the unsorted array into two halves 2. Recursively apply MergeSort to each subarray 3. Merge the two sorted subarrays

Heap

A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Generally, Heaps can be of two types: Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of it's children. The same property must be recursively true for all sub-trees in that Binary Tree. Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of it's children. The same property must be recursively true for all sub-trees in that Binary Tree.

stack

A constrained version of a linked list. New nodes can be added to a stack and removed from a stack only at the top. For this reason, a stack is referred to as a last-in, first-out (LIFO) data structure. A stack is referenced via a pointer to the top element of the stack. The link member in the last node of the stack is set to NULL to indicate the bottom of the stack.

tail recursion

A recursive call at the end of a function or subroutine. Tail recursion can always be replaced with simple iteration (a loop). Compilers should automatically replace tail-recursive calls with loops, so there usually isn't any loss in efficiency. Tail-recursion can be used in place of a simple loop, but you should only do so if it makes the logic of the code clearer. It is best to use recursion whenever it is natural to do so, and compare it with an iterative implementation if efficiency is a critical issue.

Binary Search Algorithm

An algorithm that searches for a target value in a sorted list by checking at the midpoint and then repeatedly cutting the search section in half. The date MUST be sorted for BSA to work

How to develop recursive algorithms

If you are developing a routine to perform a particular operation, then you can assume it exists and works correctly if you make recursive calls to it.

Insertion vs Selection sort

Insertion sort removes each element one-at-a-time from the set to be sorted and then finds its proper location in the destination list/array. In other words, it does the work of determining the rank of each element as it puts the element into the destination list/array. Selection Sort determines the rank of each element when it selects the next element to delete from the set to be sorted. It does very little work when it adds the selected element to the end of the destination list/array.

basic linked list operations

Insertion − Adds an element at the beginning of the list. Deletion − Deletes an element at the beginning of the list. Display − Displays the complete list. Search − Searches an element using the given key. Delete − Deletes an element using the given key.

Quicksort

Most widely used sorting algorithm

Insertion sort

Scan a sorted list until you reach its end or find a key that is larger than the one you're trying to insert, then insert the new key at that point. able to sort N items in O(N2) time

Bubble sort

Scan the array and swap any elements that are out oforder. Repeat until no more elements are out of order. O(n^2) complexity

Basic BST Operations

Search − Searches an element in a tree. Insert − Inserts an element in a tree. Pre-order Traversal − Traverses a tree in a pre-order manner. In-order Traversal − Traverses a tree in an in-order manner. Post-order Traversal − Traverses a tree in a post-order manner.

dataset membership

Store a collection of values in a data structure so that a membership function can be efficiently supported. Specifically, we want to implement a function that can determine whether a given value is or is not in the dataset without having to examine all or most of the elements of the dataset.

node

Structures that make up a linked list. They contain data being stored and a pointer to pointer of the same type as the node structure.

Tree sort

Take the elements input in an array. Create a Binary search tree by inserting data items from the array into the binary search tree. Perform in-order traversal on the tree to get the elements in sorted order.

base case

The condition under which a recursive function returns without calling itself, thereby ending the recursive calls.

enqueue and dequeue

The primary functions used to manipulate a stack. Function enqueue adds a new item to the rear of the queue Function dequeue removes the front item from the queue.

push and pop

The primary functions used to manipulate a stack. Function push creates a new node and places it on top of the stack. Function pop removes a node from the top of the stack, frees the memory that was allocated to the popped node and returns the popped value.

return

The return statement returns the flow of the execution to the function from where it is called. This statement does not mandatorily need any conditional statements. As soon as the statement is executed, the flow of the program stops immediately and return the control from where it was called. The return statement may or may not return anything for a void function, but for a non-void function, a return value is must be returned.

Tree

a collection of nodes connected by directed (or undirected) edges. A tree is a nonlinear data structure, compared to arrays, linked lists, stacks and queues which are linear data structures. A tree can be empty with no nodes or a tree is a structure consisting of one node called the root and zero or one or more subtrees.

Heapsort

a comparison based sorting technique based on Binary Heap data structure. It is similar to selection sort where we first find the minimum element and place the minimum element at the beginning. We repeat the same process for the remaining elements.

linked list

a data structure that is commonly used to implement the List ADT. it is a set of dynamically allocated nodes, arranged in such a way that each node contains one value and one pointer. The pointer always points to the next member of the list. If the pointer is NULL, then it is the last node in the list.

circularly linked list

a linked list in which the last element points back to the first element.

dummy node

a node that does not hold any value, but is in the list to provide an extra node at the front (and/or rear) of the list. They eliminate special cases for operations performed at the beginning or end of the list.

Priority Queue

a queue in which the highest-priority elements are removed first; within a priority value, the earliest arrival is removed first.

query

a request for information; the variable needing to be found in binary search

Binary Search Tree (BST)

a tree in which all the nodes follow the below-mentioned properties − The value of the key of the left sub-tree is less than the value of its parent (root) node's key. The value of the key of the right sub-tree is greater than or equal to the value of its parent (root) node's key.

double linked list

a type of linked list in which each node apart from storing its data has two links. The first link points to the previous node in the list and the second link points to the next node in the list.

Hash function

an algorithm that produces a fixed-length number called a hash or message digest

Big O analysis

describes the performance or complexity of an algorithm. Big O specifically describes the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.

divide and conquer algorithm

divides the given problem into smaller sub-problems, which it solves recursively, and then combines the solutions to form a solution to the overall problem. If the complexity of dividing a problem into sub-problems, and of combining solutions to those problems, is better than the complexity of your best algorithm for solving the overall problem, then recursive divide-and-conquer will generally yield an algorithm that is as good or better

queue

particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first

recursion

recursive function/method is one that calls itself. Recursion is just another type of program flow control like if-then-else statements and loops.

Selection sort

requires a scan of the input dataset to retrieve the smallest item to put into the output list, then the next smallest, etc., until all items from the input dataset have been placed into the output list. able to sort N items in O(N2) time


Ensembles d'études connexes

Chapter 2: Transaction Analysis - Study Plan Practice

View Set

Group Leadership Roles and Group Leadership Styles

View Set

Behavioral Observation and Screening Module 4: Methods of Observation and Screening in child care

View Set

BIOL 1408 Exam 1 MC, Practice Quizzes and Class Quizzes

View Set

APUSH MIDTERM REVIEW chapters 13-15 + 18 and 19

View Set

Chp 11: TX Rules Pertinent to life Insurance ONLY

View Set