Interview MCQ

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

binary tree definition

모든 노드들이 둘 이하의 자식을 가질때 이를 이진트리라고 합니다.

두개의 정렬된 연결리스트를 정렬순서를 지켜 병합하시오

Node* MergeList(Node* a, Node* b){ Node* result = null; if(a == NULL) return b; if(b == NULL) return a; if(a->data < b->data){ result = a; result->next = MergeList(a->next, b); }else{ result = b; result->next = MergeList(a, b->next); } }

big theta notation

This notation determines whether the upper and lower limits of a given function are equal.

RECURSION APPLICATION

Find Fibonacci numbers, factoring. Merge Sort, Quick Sort Binary search Tree navigation and many tree problems Graph Navigation (DFS, BFS) Dynamic programming Partition and Conquer Algorithm Tower of Hanoi Backtracking algorithm

virtual function이란?

When a function call occurs, c ++ associates the function definition with the function call at compile time. This is called static binding. The compiler can be defined at runtime to associate a function call with an appropriate function definition, which is called dynamic binding. Use the keyword 'virtual' when you want to use dynamic binding for a particular function.

inorder successor

in order successor of a node is the leftmost element in the right subtree of th enode

Reverse list

node* temp = null; node* nextNode = null; while(head){ nextNode = head->next; head->next = temp; temp = head; head = nextNode; }

is it possible to create a doubly linked list using only one pointer with every node.

http://www.geeksforgeeks.org/xor-linked-list-a-memory-efficient-doubly-linked-list-set-1/

Find the nth node from the end of the linked list using pointers: (most efficient)

pNthNode and pTemp 두가지 포인터 사용.. 두 포인터가 리스트의 head를 가르키도록 초기화 한다. 그다음 n만큼 ptemp가 먼저 가고나서 pnthnode가 움직인다 ptemp가 끝에 도착하면 끝 return pNthNode

A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for "stack full" is (GATE CS 2004)

top1= top2 -1

full binary tree

각 노드가 정확히 두개의 자식 노드를 가지고 모든 leaf 노드들레벨 이진 트리를 전이진 트리라고합니다

strict binary tree

각 노드들이 정확히 두개의 자식 노드를 가지거나 아예 자식 노드를 가지지 않을때, 이를 순 이진 트리라고 합니다

두개의 단일 연결리스트가 어느 지점에서 서로 만나 하나의 단일 연결ㅣ스트가 됩니다 . 두연결 리스트 head가 시작점은 이미 알고 있지만 서로 만나는 지점의 노드는 알지못합니다. 또한 각 리스트가 서로 만나는 점까지 노드수를 알지못하며 이수는 서로 다를수 있습니다. list1은 서로 만날때까지 n개의 노드를 가지고있고 list 2가 m개의 노드를 가지고있을때 두리스트가 만나는 점까지 n과 m은 같을수도 있고 다를수도있습니다ㅏ. 이떄 만나는 점을 찾는 알고리즘을 구하세요

1. brute force = 길이가 더 작은 리스트를 구해서 한번 노드랑 나머지 전체 노드랑 비교하고 작은리스트 한번 더 가고 나머지 전체 노드 비교 2. hash map = 첫번째 리스트를 다 담고 두번쨰 리스트 탐색하면서 같은 노드 있는지 확인 3. 정렬은 불가능 = 첫번째 두번째 둘다 정렬해서 두개를 비교할수있지만 반복되는 값이 많기때문에 어떤거가 시작 점인지 알수없다. 4. 스택 = 첫번째 리스트를 스택에 담고 두번째 리스트도 스택에 담ㅁ는다 위에서 부터 두개의 주소가 같으면 pop. 다를 때까지 pop한다 pop한거는 temp var에 담아둔다. 다음으로 pop했을때 둘이 값이 다르면 temp 값 리턴 5. 최적화: l1, l2의 길이를 구하고 긴거를 diff만큼 옮긴다 그다음 처음부터 다시 탐색하면서 같을때 까지 stop

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:

2^(h+1) -1 Maximum number of nodes will be there for a complete tree. Number of nodes in a complete tree of height h = 1 + 2 + 2^2 + 2*3 + .... 2^h = 2^(h+1) - 1

Postorder traversal of a given binary search tree, T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an in-order traversal of the tree T? (GATE CS 2005)

9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 B 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95 D 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

Which of the following is a true about Binary Trees Every binary tree is either complete or full. B Every complete binary tree is also a full binary tree. C Every full binary tree is also a complete binary tree. D No binary tree is both complete and full. None of the above

A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which every node other than the leaves has two children. A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. A) is incorrect. For example, the following Binary tree is neither complete nor full

why recursion?

A recursive function performs a partial operation by calling itself to perform the subtask. At any moment, the function will lead to a subtask that you can perform without calling yourself. A function that is no longer called recursively is called a base case. A recursive case is when you call yourself to perform a subtask.

stack application

Balancing Symbols Intermediate-to-posterior conversion Postfix Expression Calculation Implement function call Find Width in Stock Market Visit history in web browser Undo function of text editor

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

Both Merge sort and Insertion sort can be used for linked lists. The slow random-access performance of a linked list makes other algorithms (such as quicksort) perform poorly, and others (such as heapsort) completely impossible. Since worst case time complexity of Merge Sort is O(nLogn) and Insertion sort is O(n^2), merge sort is preferred. See following for implementation of merge sort using Linked List. http://www.geeksforgeeks.org/merge-sort-for-linked-list/

Find the nth node from the end of the linked list Brute force way:

Brute-force method: Start at the first node and count how many nodes are there after that node. If the number of nodes is <n-1, it outputs the message "There is not enough nodes compared to the input value". If the number of nodes is> n-1, go to the next node. This way it repeats until the number of nodes since the current node is n-1. o(n^2)

Find the nth node from the end of the linked list hash map way:

Create a hash table that is <node location, node address>. That is, the key in the hash table is the position of the node in the list, and the value is the address value of the node. You can find the length of the list by navigating through the list and ending the search. If the length of the list is m, the method of finding the nth end of the linked list can be represented as M-n + 1 at the starting point.

You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list?

Delete the last element of the list c) Delete the last element requires pointer to previous of last, which can only be obtained by traversing the list.

c++ 에서 object slicing 이란?

Derived classes are classes that extend by defining additional member variables in the base class. If you assign a derived class to a base class, the values corresponding to the base class are copied, but the extended values are not copied because there is no place to store them. This is called object truncation.

추상클래스와 인터페이스란 무엇이며 그들의 차이점은?

In general, an abstract class is used to define things to implement and concrete class inherits from it. When a class has only a virtual function, it is called a pure abstract class or interface. class AbstractClass{ public: virtual void AbstractMemberFunction() = 0; void NonAbstractMemberFunction(); };

Binary search Tree

In general, if you want to search the tree, you have to look at all the left and right side of the tree, and eventually the worst case time complexity is o (n). A binary search tree places constraints on the types of data a node can have. As a result, in the worst case of search operations, the time complexity can be reduced to o (log n).

BST properties

In the binary search tree, the values of the nodes constituting all the left subtrees must be smaller than the value of root, and the values of the nodes constituting all right subtrees must be larger than the value of root. This is called the attribute of the binary navigation tree. 1. The left subtree of a node can have only nodes with keys that are less than the key of the node. 2. The right subtree of a node can only have nodes with keys that are greater than the node's key. 3. The left and right subtrees must also be binary search trees.

why constant time accessing array's element?

It first calculates the size of the data type of the element, multiplies the element's index, and adds the result to the start address of the array to determine the address of that element.

c) Delete the last element requires pointer to previous of last, which can only be obtained by traversing the list.

O(1) Fast solution is to copy the data from the next node to the node to be deleted and delete the next node. Something like following.

What are the time complexities of finding 8th element from beginning and 8th element from end in a singly linked list? Let n be the number of nodes in linked list, you may assume that n > 8.

O(1) and O(n) Finding 8th element from beginning requires 8 nodes to be traversed which takes constant time. Finding 8th from end requires the complete list to be traversed.

What is the difference between a deep copy and a shallow copy?

Shallow copy: Copies the member values from one object into another. 포인터는 복사되지만 포인터가 가리키는 메모리는 복사되지 않기 때문에 원래 필드의 객체와 복사본 둘다 동적으로 할당된 동일한 메모리를 가리키게 됩니다 Deep Copy: Copies the member values from one object into another. Any pointer objects are duplicated and Deep Copied. Copies the dynamically allocated memory that all fields and fields point to. To make a deep copy, create a copy constructor, and if you do not define multiple assignment operators, the copy will point to the original.

big omega notation

Similar to the notation, this notation provides the lower bound of the given algorithm, denoted f (n) = omega (g (n)). The lower bound of f (n) at the larger value n is g (n).

binary tree application

The formula tree is used by the compiler. The Huffman coding tree is used for data compression algorithms. A binary search tree that supports searching, inserting, and deleting itemsets with an average O (logn) cost. A priority queue that supports minimal retrieval and deletion of itemsets in log time.

N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this order: Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key What is the time complexity of all these operations put together

The time complexity of decrease-key operation is Θ(1) since we have the pointer to the record where we have to perform the operation. However, we must keep the doubly linked list sorted and after the decrease-key operation we need to find the new location of the key. This step will take Θ(N) time and since there are Θ(N) decrease-key operations, the time complexity becomes O(N²). Note that the other three operations have a lower bound than this one.

Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack? A queue cannot be implemented using this stack. A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions. A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction. A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.

To DEQUEUE an item, simply POP. To ENQUEUE an item, we can do following 3 operations 1) REVERSE 2) PUSH 3) REVERSE

recusion vs iteration

When the end condition is reached, it is terminated. Each recursive call requires additional space on the stack frame. If infinite recursion is encountered, the program will run out of memory, causing a stack overflow. Repeat method Terminated when the condition is false. Each iteration construct does not require additional space. An infinite loop that does not end can be because no additional memory is created. Solving a problem in a repetitive way is not always clearer than a recursive solution.

big o notation

f(n) = O(g(n)) When n is a large number, the upper bound of the function f (n) is g (n). That is, when n is a large number, g (n) gives the maximum growth rate for f (n).

A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)? Both operations can be performed in O(1) time At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n) C The worst case time complexity for both operations will be Ω(n) D Worst case time complexity for both operations will be Ω(log n)

http://quiz.geeksforgeeks.org/queue-set-1introduction-and-array-implementation/

Which one of the following is an application of Stack Data Structure? Managing function calls The stock span problem Arithmetic expression evaluation all of the above

https://en.wikipedia.org/wiki/Stack_(abstract_data_type)#Applications - stack is used for usual function call stack (stack frame)

In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves in such a tree with n internal nodes is: nk (n - 1) k+ 1 n( k - 1) + 1 n(k - 1)

internal nodes are nodes that are not leaves.

complete binary tree

이진 트리의 높이가 h일때 완전 이진 트리에서는 root에서 시하여 왼쪽으로 오른쪽으로 노드들에 번호를 매겼을때 그 번호가 1부터 노드들의 수까지 완전히 연속적인 수를 얻게 됩니다. null 포인터에도 번호를 부여해야합니다.

pre order traversal

전위 운행법에서는 각 노드는 자신의 좌, 우측 하위 트리보다 먼저 처리 됩니다. 이것은 이해하기 쉬운 운행법이지만, 노드들이 자신이 가진 하위 트리보다 먼저 처리된다 하더라도 트리를 이동하는 동안 몇가지 정보는 유지해야 합니다.


Kaugnay na mga set ng pag-aaral

APUSH Unit 4 Progress Check: MCQ

View Set

AP Gov. & Pol. Presidential Communication

View Set

APUSH: Chapter 14 - Forging the National Economy (1790-1860)

View Set

accounting module 2 quiz questions

View Set

GS MGT 439 CH 12 Corporate Culture and Leadership

View Set

Constitution and its salient features

View Set