본문 바로가기

CHOOSE1 CHOOSE1BookmarkSuggest EditWhich of the following is not bounded by O(n^2)? (15^10) * n + 12099 n^1.98 n^3 / (sqrt(n)) (2^20) * nGood solution:The big O gives an upper bound. It doesn’t have to be tight - just means the function won’t exceed it for n > some constant. In this case O(n^2) serves as an upper bound for a, b and d. Functions a and d are linear - more to the order of O(n). Function b .. 더보기
LOOP_CMPL2 What is the time complexity of the following code : int i, j, k = 0; for (i = n/2; i 더보기
NESTED_CMPL3 What is time complexity of following code : int count = 0; for (int i = N; i > 0; i /= 2) { for (int j = 0; j 더보기
Print the Elements of a Linked List If you're new to linked lists, this is a great exercise for learning about them. Given a pointer to the head node of a linked list, print its elements in order, one element per line. If the head pointer is null (indicating the list is empty), don’t print anything.Input FormatThe void Print(Node* head) method takes the head node of a linked list as a parameter. Each struct Node has a data field (.. 더보기
Left Rotation A left rotation operation on an array of size shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become .Given an array of integers and a number, , perform left rotations on the array. Then print the updated array as a single line of space-separated integers.Input FormatThe first line contains two space-separated int.. 더보기
Dynamic Array Create a list, , of empty sequences, where each sequence is indexed from to . The elements within each of the sequences also use -indexing.Create an integer, , and initialize it to .The types of queries that can be performed on your list of sequences () are described below:Query: 1 x yFind the sequence, , at index in .Append integer to sequence .Query: 2 x yFind the sequence, , at index in .Find.. 더보기
2D Array - DS Context Given a 2D Array, :1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 We define an hourglass in to be a subset of values with indices falling in this pattern in 's graphical representation:a b c d e f g There are hourglasses in , and an hourglass sum is the sum of an hourglass' values.Task Calculate the hourglass sum for every hourglass in , then print the maximum ho.. 더보기
Arrays - DS An array is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, , of size , each memory location has some unique index, (where ), that can be referenced as (you may also see it written as ).Given an array, , of integers, print each element in reverse order as a single line of space-separated integers.Note: If you've already solved our C++ .. 더보기
Is This a Binary Search Tree? (Java) Write a function that takes a binary tree and returns true if it is a binary search tree, and false if not.In our test code, we're going to use the following examples:head1 = 0 / \ 1 2 /\ /\ 3 4 5 6head1 is NOT a binary search tree.head2 = 3 / \ 1 4 /\ / \ 0 2 5 6head2 is NOT a binary search tree.head3 = 3 / \ 1 5 /\ / \ 0 2 4 6head3 is a binary search tree.head4 = 3 / \ 1 5 /\ 0 4head4 is NOT a.. 더보기
N-th Element of a Linked List (Java) Implement a function that finds the nth node in a linked list, counting from the end.Your function should take a linked list (its head element) and n, a positive integer as its arguments.Examples:head = 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1 -> (null / None)The third element of head counting from the end is 3.head2 = 1 -> 2 -> 3 -> 4 -> (null / None)The fourth element of head2 counting from the end is .. 더보기