CSE 1320 Final Review

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

linear Last in First Out

A Stack is a ______ data structure which follows a particular order in which the operations are performed. The order will be LIFO (______ ___ ______ ____)

linked list

A _____ _____ is a linear data structure which consists of groups of nodes in a sequence. Each node and address of the next node; hence, forming a chain like structure

hash table

A ______ ______ is a data structure which implements an associative array abstract data type which is a structure that can map keys to values.

linear two left right Parent

A binary tree is a non-______ tree-like data structure consisting of nodes where each node has up to ______ child nodes, creating the branches of the tree. The two children are usually called the ______ and ______ ndoes. _______ nodes are nodes with children, while child nodes may include references to their parents

environment local global

A function's execution ______ include ______ variables and parameters and other information like a pointer to the memory containing the ______ variables.

FALSE - created every time.

A function's execution environment is only created the first time a function is called.

TRUE

A good hash function should provide a uniform distribution across the hash table and should not result in clustering

collisions same

A good hashing mechanism should minimize ______ which occur when pairs of elements are mapped to the ______ hash value.

FALSE - Easy to compute - It should be easy to compute and must not become an algorithm in itself.

A good hashing mechanism should use a hash function that is a complex algorithm.

leak

A memory _____ is caused when a program fails to release discarded memory causing impaired performance or failure.

recursion

A simple example of mathematical ______ is factorial

search binary

Binary trees are used to implement binary _____ trees and ______ heaps. They are also often used for sorting data as in a heap sort.

FALSE - hierarchically

Binary trees organize data linearly instead of hierarchically

20 4 ptr

Fill in the blanks int *ptr; ptr = malloc(______); /* malloc() 20 bytes of memory */ ptr = calloc(5,______); /* calloc() 20 bytes of memory */ ptr = realloc(______, 40); /* realloc() ptr to 40 bytes */ free(ptr);

* *

Fill in the blanks to create the head node of a linked list struct node { int node_number; struct node ___next_ptr; } ___LinkedListHead; /* the head of the linked list is a global variable */ LinkedListHead = NULL;

same linear

For separate chaining, the worst-case scenario is when all entries are inserted into the _____ linked list. The lookup procedure may have to scan all its entries, so the worst-case cost is proportional to number (n) of entries in the table so O(n) which is the same as ______ search. A good hash function can prevent this worst-case scenario and make hash table look up always faster than linear search.

key index

Given an input key, the has function uses an algorithm to map the _____ to an ______ in the array

A B

If node A is the parent of node B, then either node ___'s left or right pointer is pointing at node ___.

FALSE - old memory remains unaffected

If realloc() fails, then NULL will be returned and the old memory will be freed.

linear

In a ______ search, an array with 10 cells will have a performance value based on the worst case which is when the value we are looking for is in the last cell. In this case, the performance is shown as O(10) or O(n) where n is the size of the array.

head

In a circular linked link, the last node's pointer points to the ______ of the list.

last first

In a double linked list, the next pointer of the ______ node points to NULL and the previous pointer of the ______ node points to NULL

NULL first

In a single linked list, the next pointer of the last node of the list points to ______ and the next pointer of the ______ node of the list points to the second node of the list

large small hash function algorithm array hash table

In hashing, ______ keys are converted into ______ keys by using a _____ ______. The hash function employs an _______ to compute an index into the array. These small keys are then stored in this ______ which is called the ______ ______.

collisions resolution

Irrespective of how good a hash function is, ______ are bound to occur. Therefore, to maintain the performance of a hash table, it is important to manage collisions through various collision ______ techniques.

linear First In First Out

Queue is a ______ data structure which follows a particular order in which the operations are performed. The order will be FIFO (_____ ____ ______ ______)

functions

Recursive ______ can use a lot of memory quickly since a new execution environment is created each time the recursive function is called.

chaining linked list

Separate ______ turns each array element into its own _____ _____. Any collisions are handled by adding the new element on to the end of the linked list for that index.

RAM

Stack and heap are both stored in the computer's ______

static dynamic

The Stack is used for ______ memory allocation and the heap is used for ______ memory allocation.

first malloc() calloc() bytes

The _____ parameter to realloc() is a pointer to the first byte of memory that was previously allocated using _____ or ______ and the second parameter is the new size of the block in ______

Stack heap

The ______ does not deallocate variables while memory in the ______ must be freed

Stack heap

The ______ has LIFO access while the ______ has random access.

Stack heap

The ______ has a predetermined size while the ______ memory size is only limited by machine's memory

Stack heap

The ______ is used for static variables, strings, local variables, function parameters and the ______ is used by malloc(), calloc(), realloc(), and free()

second first

The ______ parameter to calloc() is the size of each item and _____ parameter is the number of items

Stack heap heap stack

The _______ is faster than the ______ and the ______ is slower than ______.

NULL NULL

The left pointer of a leaf node is pointing at ______ and the right pointer of a leaf node is pointing at ______.

pointer

The one parameter to free() is a ______ to the allocated space.

bytes

The one parameter to malloc() is the number of _____ to allocate.

address first

The return value from malloc() is the ______ of the ______ byte in the newly allocated buffer.

address

The return value from malloc() is the ______ of the first byte in the newly allocated buffer

pointer contiguous

The return value of realloc() is a ______ to new block of memory. realloc() will change your pointer if needed to allocate a new ______ block of memory.

FALSE - increasing

To use a recursive binary search, the array being searched must be sorted in decreasing order

stdlib.h

To use the dynamic reallocation functions, which library must be included?

NULL NULL

When a new node of a binary tree is created, the left pointer is set to _____ and the right pointer is set to ______

A D N

When deleting a node in a single linked list, if node A's next pointer is pointing to node N and node N's next pointer is pointing to node D, then to delete node N, we point node ___'s next pointer to node ___ and free node ___.

C S E

When inserting a node into a single linked list, if node C's next pointer points to node E and we want to insert node S in between node C and node E, then we change node ___'s next pointer to point at node ___ and node S's next pointer to point at node ___.

FALSE - newly allocated memory is not inintialized

When using realloc(), old data is not lost and newly allocated memory is initialized.

Hash tables O(1)

______ _____, on average, are more efficient than search trees or any other table lookup structure. You can access an element in ____. This is why hash tables are heavily used in many situations.

Recursion

______ occurs when a function or subprogram calls itself or calls a function which in turn calls the original function.

free

______() should be used when allocated memory is no longer needed in order to avoid memory leaks

Separate collision

_______ chaining is on of the most commonly used _______ resolution techniques. Is is usually implemented using linked lists. In separate chaining, each element of the hash table is a linked list. To store an element in the hash table you must insert it into a specific linked list. If there is any collision (i.e. two different elements have same hash value) then store both the elements in same linked list.

Stack heap

_______ memory is managed by the CPU and will not become fragmented while ______ memory is managed by the programmer and can become fragmented

FALSE - it is initialized

calloc() memory is uninitialized

TempPtr NULL node_count

int CountNodes(void) { struct node *TempPtr; int node_count = 0; TempPtr = LinkedListHead; /* Traverse the list until finding the node pointing at NULL */ while ( ______ != ______ ) { TempPtr = TempPtr->next_ptr; ______++; } return node_count; }

factorial n-1

int ______(int n) { if (n == 0) return 1; else return (n * factorial(______)); }

FALSE - it is uninitialized

malloc() memory is initialized.

malloc NULL NewNode != next_ptr

struct node *TempPtr, *NewNode; NewNode = ______(sizeof(struct node)); NewNode->node_number = NewNodeNumber; NewNode->next_ptr = ______; /* if the list is empty, then the new node is the head */ if (LinkedListHead == NULL) { LinkedListHead = _______; } else { TempPtr = LinkedListHead; /* Traverse the linked list to find the end node */ while (TempPtr->next_ptr ____ NULL) TempPtr = TempPtr->next_ptr; /* Change end node to point to new node */ TempPtr->_______= NewNode;

TempPtr NULL

struct node *TempPtr; TempPtr = LinkedListHead; while ( ______ != ______ ) { TempPtr = TempPtr->next_ptr; }

c a b e f g d

topmost node node directly under another node node directly above another node node with no children edge height depth a. child b. parent c. root of the tree d. length of the path to its roots e. leaf f. link between two nodes g. length of the longest path to a leaf


Kaugnay na mga set ng pag-aaral

Photosynthesis and Cellular Respiration Review

View Set

Chapter 2: Religion and Global Ethics

View Set

LS 6: Merchandising Operations and the Multistep Income Statement

View Set