CP264 MOCK FINAL

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Given the struct DATA {char name[20]; float marks;}: The value of sizeof (struct DATA) is

  • 28
  • 5
  • 24 (correct)
  • 20

Both array and linked list can be used to implement queue and stack data structures.

True (A)

Which data structure is more efficient for random access?

  • BST
  • array (correct)
  • AVL tree
  • Linked list

Which represents the height of a height balanced binary tree of n nodes?

<p>O(log n) (C)</p> Signup and view all the answers

The space complexity of search, insert, and delete operations on BST of n nodes is

<p>O(h) (C)</p> Signup and view all the answers

The time complexity of search, insert, delete operations on AVL tree of n nodes is

<p>O(log n) (A)</p> Signup and view all the answers

For splay tree the time complexity of accessing the last inserted node is

<p>O(log n) (C)</p> Signup and view all the answers

Which operation is time complexity O(1) on binary min-heap?

<p>find min (C)</p> Signup and view all the answers

If no collision happens in hash table insertions. Searching by key can be done in time.

<p>O(1) (A)</p> Signup and view all the answers

Which graph representation is more efficient for large space graph?

<p>adjacency list (D)</p> Signup and view all the answers

Given the binary tree diagram (Root A, left child B with children D, E; right child C with child F), the pre-order traversal of the tree nodes is _____. (Separate nodes with commas)

<p>A, B, D, E, C, F</p> Signup and view all the answers

Given the binary tree diagram (Root A, left child B with children D, E; right child C with child F), the in-order traversal of the tree nodes is _____. (Separate nodes with commas)

<p>D, B, E, A, F, C</p> Signup and view all the answers

Given the binary tree diagram (Root A, left child B with children D, E; right child C with child F), the post-order traversal of the tree nodes is _____. (Separate nodes with commas)

<p>D, E, B, F, C, A</p> Signup and view all the answers

Given the binary tree diagram (Root A, left child B with children D, E; right child C with child F), the breadth-first-order traversal of the tree nodes is _____. (Separate nodes with commas)

<p>A, B, C, D, E, F</p> Signup and view all the answers

Flashcards

What does sizeof do?

Returns the memory size (in bytes) of a data type or variable.

What data structure allows efficient random access?

A data structure where elements are accessed in a non-sequential order such as an array

What's the height of a balanced binary tree?

O(log n), where n is the number of nodes.

What is the space complexity operations on a BST?

O(h), where h is the height of the tree. In the worst case, this can be O(n).

Signup and view all the flashcards

What's the time complexity of AVL tree operations?

O(log n), because AVL trees are balanced.

Signup and view all the flashcards

What is the time complexity of accessing the last inserted node in a splay tree?

O(log n)

Signup and view all the flashcards

O(1) heap operation?

The operation to time complexity O(1) on binary min-heap is find-min

Signup and view all the flashcards

Hash table search time (no collisions)?

O(1)

Signup and view all the flashcards

What graph representation saves space?

Adjacency list

Signup and view all the flashcards

Study Notes

Struct DATA Size

  • Given the struct DATA with a char array name[20] and a float marks, the sizeof(struct DATA) is 24.

Queue and Stack Implementation

  • Both arrays and linked lists are suitable for implementing queue and stack data structures.

Efficient Random Access

  • An array is a more efficient data structure for random access compared to linked lists, BST, and AVL trees.

Height Balanced Binary Tree Height

  • The height of a height-balanced binary tree with n nodes is represented as O(log n).

BST Space Complexity

  • The space complexity for search, insert, and delete operations on a Binary Search Tree (BST) with n nodes is O(h), where h is the height of the tree. This can be O(log n) in balanced trees or O(n) in skewed trees.

AVL Tree Time Complexity

  • The time complexity for search, insert, and delete operations on an AVL tree with n nodes is O(log n).

Splay Tree Access Time

  • For a splay tree, the time complexity of accessing the last inserted node is O(log n).

Binary Min-Heap Operation at O(1)

  • The find min operation has a time complexity of O(1) on a binary min-heap.

Hash Table Search Time

  • Assuming no collisions occur during hash table insertions, searching by key can be done in O(1) time.

Efficient Graph Representation

  • An adjacency list is a more space-efficient graph representation for large, sparse graphs.

AVL Tree Construction

  • An AVL tree can be built by inserting key values in a specific order, such as 5, 3, 4, 2, 1, and rebalancing the tree through rotations as needed. Refer to the original document for a visual depiction of this process.

Binary Tree Traversal

  • To solve #1 pre-order, #2 in-order, and #3 post-order of the tree nodes requires performing said traversals of the binary tree. These algorithms visit nodes in a specific order. Review the original document for the a visual depiction of a binary tree.

Binary Min-Heap Insertion

  • Inserting key values (e.g., 4, 3, 2, 1) into a binary min-heap involves adding the key to the heap and then heapifying to maintain the min-heap property. Review the original document for the a visual depiction of steps to build the heap.

Linked List Insertion Function

  • A C function insert_end(NODE **startp, int num) can be written to insert a new node with value num at the end of a linked list. The list is accessed via a pointer startp to the first element.

Binary Tree Info Structure

  • A structure type TREEINFO along with a function treeinfo(TNODE *roto) can be designed to compute and return the height and number of leaves of a binary tree. Root is passed as an argument. The implementation should use a single recursive function.

Binary Tree Breadth-First Search Function

  • A C function TNODE *breadth_first_search(TNODE *root, int key) can be implemented to search a binary tree in breadth-first order for a node with a specific key. The function returns the node's address if found, otherwise NULL.

Heap Sort Function

  • A C function void heap_sort(int a[], n) can sort an integer array a[] of n elements in decreasing order using heap sort. The function's implementation should include heapify-up/heapify-down operations within the function.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Use Quizgecko on...
Browser
Browser