Шукаєте відповіді та рішення тестів для Course 825004? Перегляньте нашу велику колекцію перевірених відповідей для Course 825004 в estudijas.rtu.lv.
Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!
Insertion sort takes elements of the array sequentially, and maintains a sorted subarray to the left of the current point. It does this by taking an element, finding its correct position in the sorted array, and shifting all following elements by 1, leaving a space for the element to be inserted.
Heapsort starts by building a max heap. A binary max heap is a nearly complete binary tree in which each parent node is larger or equal to its children. The heap is stored in the same memory in which the original array elements are. Once the heap is formed, it completely replaces the array. After that, we take and remove the first element, restore the heap property, thus reducing the heap size by 1, after which we place the max element at the end of that memory. This is repeated until we empty out the heap, resulting in the smallest element being in the first place, and the following elements being sequentially larger.
Quicksort is performed by taking the first (leftmost) element of the array as a pivot point. We then compare it to each following element. When we find one that is smaller, we move it to the left. The moving is performed quickly by swapping that element with the first element after the pivot point, and then swapping the pivot point with the element after it. After going through the whole array, we take all points on the left of the pivot and call quicksort on that subarray, and we do the same to all points on the right of the pivot. The recursion is performed until we reach subarrays of 0-1 elements in length.
Merge sort recursively halves the given array. Once the subarrays reach trivial length, merging begins. Merging takes the smallest element between two adjacent subarrays and repeats that step until all elements are taken, resulting in a sorted subarray. The process is repeated on pairs of adjacent subarrays until we arrive at the starting array, but sorted.
Final step in algorithm development is Testing and implementation
Algorithm to Swap Two Numbers without using temporary variable
Guess the output
Algorithm to find Area & Perimeter of Triangle
Guess the output
Algorithm to generate first n Fibonacci terms 0,1,1,2,3,5…n (n>2)
You have a set of date intervals represented by StartDate and EndDate. How would you efficiently calculate the longest timespan covered by them?
What will be the time complexity?
The overall time complexity is O(NlogN) because:
Sort intervals by start date. Time complexity is O(NlogN).
Take first interval as actual range. Loop over intervals and if the current StartDate is within the actual range, extend EndDate of the actual range if needed and extend maximal timespan achieved so far if needed. Otherwise, use current interval as new actual range. Time complexity is O(N).
Algorithm to find Odd numbers between 1 to n where n is a
positive Integer
Guess the output